summaryrefslogtreecommitdiffstats
path: root/tests/Controller/ViewTest.php
diff options
context:
space:
mode:
authorArnold Daniels <arnold@jasny.net>2017-02-09 12:54:46 +0100
committerArnold Daniels <arnold@jasny.net>2017-02-09 14:54:53 +0100
commit75ab132381ac2e9fc97daae680410e8cb3d292c3 (patch)
treebf38fd5b7b8781264df59ff79e71f740b5ca6a80 /tests/Controller/ViewTest.php
parent9f2e0789a87685d6ba8f2cf10ee345d64771d95e (diff)
downloadcontroller-75ab132381ac2e9fc97daae680410e8cb3d292c3.zip
controller-75ab132381ac2e9fc97daae680410e8cb3d292c3.tar.gz
controller-75ab132381ac2e9fc97daae680410e8cb3d292c3.tar.bz2
Reworked views using Jasny View
Added View/PHP trait Ability to set a viewer
Diffstat (limited to 'tests/Controller/ViewTest.php')
-rw-r--r--tests/Controller/ViewTest.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests/Controller/ViewTest.php b/tests/Controller/ViewTest.php
new file mode 100644
index 0000000..0473a3f
--- /dev/null
+++ b/tests/Controller/ViewTest.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Jasny\Controller\View;
+
+use Jasny\Controller\View;
+use Jasny\ViewInterface;
+use Jasny\Controller\TestHelper;
+use Jasny\Controller\Session\Flash;
+use Psr\Http\Message\ServerRequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\UriInterface;
+
+/**
+ * @covers Jasny\Controller\View
+ */
+class ViewTest extends \PHPUnit_Framework_TestCase
+{
+ use TestHelper;
+
+ /**
+ * @return string
+ */
+ protected function getControllerClass()
+ {
+ return View::class;
+ }
+
+ public function testGetViewer()
+ {
+ $viewer = $this->createMock(ViewInterface::class);
+
+ $controller = $this->getController();
+ $controller->setViewer($viewer);
+
+ $this->assertSame($viewer, $controller->getViewer());
+ }
+
+ /**
+ * @expectedException LogicException
+ * @expectedExceptionMessage Viewer has not been set
+ */
+ public function testGetViewerNotSet()
+ {
+ $this->getController()->getViewer();
+ }
+
+
+ public function testGetViewPath()
+ {
+ $this->assertSame(getcwd(), $this->getController()->getViewPath());
+ }
+
+
+ public function testView()
+ {
+ $uri = $this->createMock(UriInterface::class);
+
+ $request = $this->createMock(ServerRequestInterface::class);
+ $request->expects($this->once())->method('getUri')->willReturn($uri);
+
+ $response = $this->createMock(ResponseInterface::class);
+ $finalResponse = $this->createMock(ResponseInterface::class);
+
+ $flash = $this->createMock(Flash::class);
+
+ $name = 'foo';
+ $context = ['color' => 'blue', 'animal' => 'monkey'];
+
+ $viewer = $this->createMock(ViewInterface::class);
+ $viewer->expects($this->once())->method('render')
+ ->with($response, $name, $this->identicalTo($context + ['current_url' => $uri, 'flash' => $flash]))
+ ->willReturn($finalResponse);
+
+ $controller = $this->getController(['flash']);
+ $controller->method('getRequest')->willReturn($request);
+ $controller->method('getResponse')->willReturn($response);
+ $controller->method('flash')->willReturn($flash);
+ $controller->expects($this->once())->method('setResponse')->with($finalResponse);
+ $controller->setViewer($viewer);
+
+ $controller->view($name, $context);
+ }
+}