Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add assertTemplateName and assertNotTemplateName #4946

Merged
merged 2 commits into from

2 participants

Tim Roediger Matthew Weier O'Phinney
Tim Roediger

More handy functions for testing the dispatch process.

Matthew Weier O'Phinney weierophinney merged commit dfec585 into from
Tim Roediger superdweebie deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 12, 2013
  1. Tim Roediger
  2. Tim Roediger

    cs fix

    superdweebie authored
This page is out of date. Refresh to see the latest.
42 library/Zend/Test/PHPUnit/Controller/AbstractControllerTestCase.php
View
@@ -665,4 +665,46 @@ public function assertNotMatchedRouteName($route)
}
$this->assertNotEquals($route, $match);
}
+
+ /**
+ * Assert template name
+ * Assert that a template was used somewhere in the view model tree
+ *
+ * @param string $templateName
+ */
+ public function assertTemplateName($templateName)
+ {
+ $viewModel = $this->getApplication()->getMvcEvent()->getViewModel();
+ $this->assertTrue($this->searchTemplates($viewModel, $templateName));
+ }
+
+ /**
+ * Assert not template name
+ * Assert that a template was not used somewhere in the view model tree
+ *
+ * @param string $templateName
+ */
+ public function assertNotTemplateName($templateName)
+ {
+ $viewModel = $this->getApplication()->getMvcEvent()->getViewModel();
+ $this->assertFalse($this->searchTemplates($viewModel, $templateName));
+ }
+
+ /**
+ * Recursively search a view model and it's children for the given templateName
+ *
+ * @param ViewModel $viewModel
+ * @param string $templateName
+ * @return boolean
+ */
+ protected function searchTemplates($viewModel, $templateName)
+ {
+ if ($viewModel->getTemplate($templateName) == $templateName){
+ return true;
+ }
+ foreach ($viewModel->getChildren() as $child){
+ return $this->searchTemplates($child, $templateName);
+ }
+ return false;
+ }
}
15 tests/ZendTest/Test/PHPUnit/Controller/AbstractControllerTestCaseTest.php
View
@@ -305,4 +305,19 @@ public function testExplicityPutParamsOverrideRequestContent()
$this->dispatch('/tests', 'PUT', array('a' => 1));
$this->assertEquals('a=1', $this->getRequest()->getContent());
}
+
+ public function testAssertTemplateName()
+ {
+ $this->dispatch('/tests');
+
+ $this->assertTemplateName('layout/layout');
+ $this->assertTemplateName('baz/index/unittests');
+ }
+
+ public function testAssertNotTemplateName()
+ {
+ $this->dispatch('/tests');
+
+ $this->assertNotTemplateName('template/does/not/exist');
+ }
}
Something went wrong with that request. Please try again.