12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- class TemplatePageTest extends PHPUnit_Framework_TestCase
- {
- private $testObj;
- private $twig;
- private $offerRetriever;
- public function setUp()
- {
- $this->twig = $this->getMockBuilder('TwigWrapper')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->offerRetriever = $this->getMockBuilder('OfferRetriever')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->testObj = new TemplatePage($this->twig, $this->offerRetriever);
- }
- public function tearDown()
- {
- unset($_GET['id']);
- unset($_GET['page']);
- }
- public function testDisplayOutputsDefaultPage()
- {
- $pageId = 0;
- $offerId = TestUtils::getRandomInteger();
- $_GET['id'] = $offerId;
-
- $templateFilename = TestUtils::getRandomString(10);
-
- $pageData = array('filename' => $templateFilename);
- $expected = TestUtils::getRandomString(20);
-
- $this->offerRetriever->method('getPageData')
- ->with($offerId, $pageId)
- ->willReturn($pageData);
-
- $this->twig->expects($this->once())
- ->method('render')
- ->with($templateFilename, $pageData)
- ->willReturn($expected);
-
- $actual = $this->testObj->display();
- $this->assertEquals($expected, $actual);
- }
- public function testDisplayOutputsAnErrorIfTemplateNotFound()
- {
- $templateRequested = "templateDoesNotExist.html";
- $expected = TestUtils::getRandomString(20);
-
- $_GET['id'] = null;
-
- $this->twig->expects($this->once())
- ->method('render')
- ->with($templateRequested, array())
- ->willReturn($expected);
-
- $actual = $this->testObj->display();
- $this->assertEquals($expected, $actual);
- }
- public function testDisplayOutputsCorrectTemplate()
- {
- $offerId = TestUtils::getRandomInteger();
- $pageId = TestUtils::getRandomInteger();
- $_GET['id'] = $offerId;
- $_GET['page'] = $pageId;
- $offerName = TestUtils::getRandomString(10);
- $displayTitle = TestUtils::getRandomString(10);
- $disclaimer = TestUtils::getRandomString(10);
- $templateFilename = TestUtils::getRandomString(10);
- $expected = TestUtils::getRandomString(20);
-
- $template = array('name' => $offerName, 'display_title' => $displayTitle, 'disclaimer' => $disclaimer, 'filename' => $templateFilename, 'offer_id' => $offerId);
-
- $this->offerRetriever->method('getPageData')
- ->with($offerId, $pageId)
- ->willReturn($template);
-
- $this->twig->expects($this->once())
- ->method('render')
- ->with($templateFilename, $template)
- ->willReturn($expected);
-
- $actual = $this->testObj->display();
- $this->assertEquals($expected, $actual);
- }
- }
|