From 5134803c18096ebf92be7147a6942e8d0a48ae88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Zl=C3=A1mal?= Date: Sun, 24 Jul 2016 13:26:34 +0200 Subject: [PATCH] DOMDocument: remove script tags from DOM (TPresenter) --- src/Traits/TPresenter.php | 2 ++ tests/Traits/TPresenterTest.phpt | 7 +++---- .../templates/Presenter/variabledoesntexist.latte | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Traits/TPresenter.php b/src/Traits/TPresenter.php index 1125f46..dd94f67 100644 --- a/src/Traits/TPresenter.php +++ b/src/Traits/TPresenter.php @@ -126,6 +126,8 @@ protected function checkAction($destination, $params = [], $post = []) Assert::type('Nette\Application\UI\ITemplate', $response->getSource()); $html = (string)$response->getSource(); + //DOMDocument doesn't handle HTML tags inside of script tags very well + $html = preg_replace('~)<[^<]*)*<\/script>~', '', $html); //http://stackoverflow.com/a/6660315/3135248 $dom = \Tester\DomQuery::fromHtml($html); Assert::true($dom->has('html'), "missing 'html' tag"); Assert::true($dom->has('title'), "missing 'title' tag"); diff --git a/tests/Traits/TPresenterTest.phpt b/tests/Traits/TPresenterTest.phpt index 73f7473..f96cc26 100644 --- a/tests/Traits/TPresenterTest.phpt +++ b/tests/Traits/TPresenterTest.phpt @@ -17,10 +17,9 @@ class TPresenterTest extends \Testbench\CustomPresenterTestCase { $this->checkAction('Presenter:default'); - //FIXME: how to? - //Assert::error(function () { - // $this->checkAction('Presenter:variabledoesntexist'); - //}, E_NOTICE, 'Undefined variable: doesnexist'); + Assert::error(function () { + $this->checkAction('Presenter:variabledoesntexist'); + }, E_NOTICE, 'Undefined variable: doesnexist'); } public function testClassicRenderShort() diff --git a/tests/_helpers/presenters/templates/Presenter/variabledoesntexist.latte b/tests/_helpers/presenters/templates/Presenter/variabledoesntexist.latte index 223c022..e349835 100644 --- a/tests/_helpers/presenters/templates/Presenter/variabledoesntexist.latte +++ b/tests/_helpers/presenters/templates/Presenter/variabledoesntexist.latte @@ -5,8 +5,8 @@ TEST -
+