Merge branch '5.2' of https://github.com/LaravelCollective/html into blade-directives

This commit is contained in:
mlantz committed 2016-06-12 17:33:43 -04:00
commit e7d03053b3
6 files changed
+53 -15

No files matched your search

Executable → Regular
+8 -4
View File
@@ -13,7 +13,6 @@ use Illuminate\Contracts\Routing\UrlGenerator;
class FormBuilder class FormBuilder
{ {
use Macroable, Componentable { use Macroable, Componentable {
Macroable::__call as macroCall; Macroable::__call as macroCall;
Componentable::__call as componentCall; Componentable::__call as componentCall;
@@ -210,16 +209,21 @@ class FormBuilder
* @param string $name * @param string $name
* @param string $value * @param string $value
* @param array $options * @param array $options
* @param bool $escape_html
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
public function label($name, $value = null, $options = []) public function label($name, $value = null, $options = [], $escape_html = true)
{ {
$this->labels[] = $name; $this->labels[] = $name;
$options = $this->html->attributes($options); $options = $this->html->attributes($options);
$value = e($this->formatLabel($name, $value)); $value = $this->formatLabel($name, $value);
if ($escape_html) {
$value = $this->html->entities($value);
}
return $this->toHtmlString('<label for="' . $name . '"' . $options . '>' . $value . '</label>'); return $this->toHtmlString('<label for="' . $name . '"' . $options . '>' . $value . '</label>');
} }
@@ -1080,7 +1084,7 @@ class FormBuilder
return $value; return $value;
} }
if (! is_null($this->old($name))) { if (! is_null($this->old($name)) && $name != '_method') {
return $this->old($name); return $this->old($name);
} }
+14 -5
View File
@@ -10,7 +10,6 @@ use Illuminate\Contracts\Routing\UrlGenerator;
class HtmlBuilder class HtmlBuilder
{ {
use Macroable, Componentable { use Macroable, Componentable {
Macroable::__call as macroCall; Macroable::__call as macroCall;
Componentable::__call as componentCall; Componentable::__call as componentCall;
@@ -147,10 +146,11 @@ class HtmlBuilder
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
* @param bool $secure * @param bool $secure
* @param bool $escape
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
public function link($url, $title = null, $attributes = [], $secure = null) public function link($url, $title = null, $attributes = [], $secure = null, $escape = true)
{ {
$url = $this->url->to($url, [], $secure); $url = $this->url->to($url, [], $secure);
@@ -158,7 +158,11 @@ class HtmlBuilder
$title = $url; $title = $url;
} }
return $this->toHtmlString('<a href="' . $url . '"' . $this->attributes($attributes) . '>' . $this->entities($title) . '</a>'); if ($escape) {
$title = $this->entities($title);
}
return $this->toHtmlString('<a href="' . $url . '"' . $this->attributes($attributes) . '>' . $title . '</a>');
} }
/** /**
@@ -242,18 +246,23 @@ class HtmlBuilder
* @param string $email * @param string $email
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
* @param bool $escape
* *
* @return \Illuminate\Support\HtmlString * @return \Illuminate\Support\HtmlString
*/ */
public function mailto($email, $title = null, $attributes = []) public function mailto($email, $title = null, $attributes = [], $escape = true)
{ {
$email = $this->email($email); $email = $this->email($email);
$title = $title ?: $email; $title = $title ?: $email;
if ($escape) {
$title = $this->entities($title);
}
$email = $this->obfuscate('mailto:') . $email; $email = $this->obfuscate('mailto:') . $email;
return $this->toHtmlString('<a href="' . $email . '"' . $this->attributes($attributes) . '>' . $this->entities($title) . '</a>'); return $this->toHtmlString('<a href="' . $email . '"' . $this->attributes($attributes) . '>' . $title . '</a>');
} }
/** /**
+3 -2
View File
@@ -8,12 +8,13 @@ if (! function_exists('link_to')) {
* @param string $title * @param string $title
* @param array $attributes * @param array $attributes
* @param bool $secure * @param bool $secure
* @param bool $escape
* *
* @return string * @return string
*/ */
function link_to($url, $title = null, $attributes = [], $secure = null) function link_to($url, $title = null, $attributes = [], $secure = null, $escape = true)
{ {
return app('html')->link($url, $title, $attributes, $secure); return app('html')->link($url, $title, $attributes, $secure, $escape);
} }
} }
-3
View File
@@ -14,7 +14,6 @@ use Mockery as m;
class FormAccessibleTest extends PHPUnit_Framework_TestCase class FormAccessibleTest extends PHPUnit_Framework_TestCase
{ {
public function setUp() public function setUp()
{ {
Capsule::table('models')->truncate(); Capsule::table('models')->truncate();
@@ -65,7 +64,6 @@ class FormAccessibleTest extends PHPUnit_Framework_TestCase
class ModelThatUsesForms extends Model class ModelThatUsesForms extends Model
{ {
use FormAccessible; use FormAccessible;
protected $table = 'models'; protected $table = 'models';
@@ -93,7 +91,6 @@ class ModelThatUsesForms extends Model
class ModelThatDoesntUseForms extends Model class ModelThatDoesntUseForms extends Model
{ {
protected $table = 'models'; protected $table = 'models';
public function getStringAttribute($value) public function getStringAttribute($value)
+2 -1
View File
@@ -58,9 +58,11 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
{ {
$form1 = $this->formBuilder->label('foo', 'Foobar'); $form1 = $this->formBuilder->label('foo', 'Foobar');
$form2 = $this->formBuilder->label('foo', 'Foobar', ['class' => 'control-label']); $form2 = $this->formBuilder->label('foo', 'Foobar', ['class' => 'control-label']);
$form3 = $this->formBuilder->label('foo', 'Foobar <i>bar</i>', null, false);
$this->assertEquals('<label for="foo">Foobar</label>', $form1); $this->assertEquals('<label for="foo">Foobar</label>', $form1);
$this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2); $this->assertEquals('<label for="foo" class="control-label">Foobar</label>', $form2);
$this->assertEquals('<label for="foo">Foobar <i>bar</i></label>', $form3);
} }
public function testFormInput() public function testFormInput()
@@ -532,7 +534,6 @@ class FormBuilderTest extends PHPUnit_Framework_TestCase
class FormBuilderModelStub class FormBuilderModelStub
{ {
protected $data; protected $data;
public function __construct(array $data = []) public function __construct(array $data = [])
+26
View File
@@ -89,4 +89,30 @@ class HtmlBuilderTest extends PHPUnit_Framework_TestCase
$this->assertTrue($this->htmlBuilder->hasComponent('tweet')); $this->assertTrue($this->htmlBuilder->hasComponent('tweet'));
} }
public function testLink()
{
$result1 = $this->htmlBuilder->link("http://www.example.com", "<span>Example.com</span>", ["class" => "example-link"], null, true);
$result2 = $this->htmlBuilder->link("http://www.example.com", "<span>Example.com</span>", ["class" => "example-link"], null, false);
$this->assertEquals('<a href="http://www.example.com" class="example-link">&lt;span&gt;Example.com&lt;/span&gt;</a>', $result1);
$this->assertEquals('<a href="http://www.example.com" class="example-link"><span>Example.com</span></a>', $result2);
}
public function testMailto()
{
$htmlBuilder = m::mock('Collective\Html\HtmlBuilder[obfuscate,email]', [$this->urlGenerator, $this->viewFactory]);
$htmlBuilder->shouldReceive('obfuscate', 'email')->andReturnUsing(function () {
$args = func_get_args();
return $args[0];
});
$result1 = $htmlBuilder->mailto("person@example.com", "<span>First Name Last</span>", ["class" => "example-link"], true);
$result2 = $htmlBuilder->mailto("person@example.com", "<span>First Name Last</span>", ["class" => "example-link"], false);
$this->assertEquals('<a href="mailto:person@example.com" class="example-link">&lt;span&gt;First Name Last&lt;/span&gt;</a>', $result1);
$this->assertEquals('<a href="mailto:person@example.com" class="example-link"><span>First Name Last</span></a>', $result2);
}
} }