Skip to content

Commit

Permalink
[TEST] ForumController->indexAction
Browse files Browse the repository at this point in the history
  • Loading branch information
smichaelsen committed Jul 11, 2015
1 parent 1207284 commit 55d6506
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
.idea
nbproject
Resources/Public/Stylesheets/.sass-cache/

# composer related ignores:
bin
composer.lock
index.php
Packages
typo3
typo3_src
typo3temp
32 changes: 32 additions & 0 deletions Tests/Unit/AbstractControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Mittwald\Typo3Forum\Tests\Unit;

use Mittwald\Typo3Forum\Service\Authentication\AuthenticationService;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use TYPO3\CMS\Fluid\View\TemplateView;

abstract class AbstractControllerTest extends UnitTestCase {

/**
* @var \PHPUnit_Framework_MockObject_MockObject|AuthenticationService
*/
protected $authenticationServiceMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|TemplateView
*/
protected $viewMock;

/**
*
*/
public function setUp() {
$this->authenticationServiceMock = $this->getMock('Mittwald\\Typo3Forum\\Service\\Authentication\\AuthenticationService');
$this->viewMock = $this->getMockBuilder('TYPO3\\CMS\\Fluid\\View\\TemplateView')
->setMethods(['__construct', 'assign'])
->disableOriginalConstructor()
->getMock();
}

}
65 changes: 59 additions & 6 deletions Tests/Unit/ForumControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,74 @@
namespace Mittwald\Typo3Forum\Tests\Unit;

use Mittwald\Typo3Forum\Controller\ForumController;
use TYPO3\CMS\Core\Tests\UnitTestCase;
use Mittwald\Typo3Forum\Domain\Model\Forum\RootForum;
use Mittwald\Typo3Forum\Domain\Repository\Forum\ForumRepository;
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;

class ForumControllerTest extends UnitTestCase {
class ForumControllerTest extends AbstractControllerTest {

/**
* @var \Mittwald\Typo3Forum\Controller\ForumController
* @var ForumController
*/
protected $forumController;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|ForumRepository
*/
protected $forumRepositoryMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|RootForum
*/
protected $rootForumMock;

/**
*
*/
public function setUp() {
parent::setUp();
$this->forumController = new ForumController();

$this->inject($this->forumController, 'authenticationService', $this->authenticationServiceMock);
$this->inject($this->forumController, 'view', $this->viewMock);

// inject root forum mock
$this->rootForumMock = $this->getMock('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\RootForum');
$this->inject($this->forumController, 'rootForum', $this->rootForumMock);

// inject forum repository mock
$this->forumRepositoryMock = $this->getMock(
'Mittwald\\Typo3Forum\\Domain\\Repository\\Forum\\ForumRepository',
[],
[$this->getMock('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')]
);
$this->inject($this->forumController, 'forumRepository', $this->forumRepositoryMock);

}

/**
* @test
*/
public function indexActionAssertsReadAuthorization() {
$this->authenticationServiceMock->expects($this->once())
->method('assertReadAuthorization')
->with($this->isInstanceOf('Mittwald\\Typo3Forum\\Domain\\Model\\Forum\\Forum'))
->will($this->returnValue(TRUE));
$this->forumController->indexAction();
}

/**
* @test
*/
public function mockIsBuildable() {
$this->forumController = $this->getAccessibleMock('Mittwald\\Typo3Forum\\Controller\\ForumController');
$this->assertTrue($this->forumController instanceof ForumController);
public function indexActionAssignsFoundForumsToView() {
$foundForums = new ObjectStorage();
$this->forumRepositoryMock->expects($this->once())
->method('findForIndex')
->will($this->returnValue($foundForums));
$this->viewMock->expects($this->once())
->method('assign')
->with($this->isType('string'), $this->equalTo($foundForums));
$this->forumController->indexAction();
}

}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"typo3/cms": "~6.2"
},
"require-dev": {
"phpunit/phpunit": "4.7.*"
"phpunit/phpunit": "4.7.*",
"mikey179/vfsstream": "1.1.*"
}
}

0 comments on commit 55d6506

Please sign in to comment.