Skip to content
Snippets Groups Projects
Unverified Commit e5f0ef4c authored by Thomas Flori's avatar Thomas Flori
Browse files

test escaping in views

parent 44a06823
No related branches found
No related tags found
No related merge requests found
......@@ -276,10 +276,6 @@ class View
$string = $this->batch($string, $functions);
}
if (!is_string($string)) {
throw new \LogicException('Only strings can be used for escaping');
}
return htmlspecialchars($string, $flags, 'UTF-8');
}
}
<?php
namespace Syna\Test\View;
use Syna\Factory;
use Syna\Test\TestCase;
use Mockery as m;
use Syna\ViewLocator;
class EscapingTest extends TestCase
{
/** @var m\Mock|Factory */
protected $factory;
protected function setUp()
{
parent::setUp();
$this->factory = m::mock(Factory::class, [new ViewLocator($this->templatePath)])->makePartial();
}
/** @test */
public function usingEscapeMethod()
{
$this->createTemplate('escape.php', '<?= $v->escape("<p class=\\"intro\\">Lorem ipsum</p>") ?>');
$view = $this->factory->view('escape');
$result = $view->render();
self::assertSame('&lt;p class=&quot;intro&quot;&gt;Lorem ipsum&lt;/p&gt;', $result);
}
/** @test */
public function usingDollarE()
{
$this->createTemplate('escape.php', '<?= $e("<p class=\\"intro\\">Lorem ipsum</p>") ?>');
$view = $this->factory->view('escape');
$result = $view->render();
self::assertSame('&lt;p class=&quot;intro&quot;&gt;Lorem ipsum&lt;/p&gt;', $result);
}
/** @test */
public function batchProcessingBeforeEscaping()
{
$this->createTemplate('escape.php', '<?= $e($title, "strtoupper") ?>');
$view = $this->factory->view('escape');
$result = $view->render(['title' => 'Lorem & Ipsum']);
self::assertSame('LOREM &amp; IPSUM', $result);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment