testing-talk/Resources/Private/CodeExamples/Tests/Unit/Controller/FrontendUserControllerTest.php

84 lines
2.7 KiB
PHP
Raw Normal View History

2018-06-23 20:18:07 +02:00
<?php
2018-07-15 11:10:08 +02:00
namespace Codappix\TestingTalk\Tests\Unit\Controller;
2018-06-23 20:18:07 +02:00
/*
* Copyright (C) 2018 Daniel Siepmann <coding@daniel-siepmann.de>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
use Codappix\TestingTalk\Controller\FrontendUserController;
2018-06-23 20:27:12 +02:00
use PHPUnit\Framework\MockObject\MockObject;
2018-06-23 20:18:07 +02:00
use PHPUnit\Framework\TestCase;
use TYPO3\CMS\Extbase\Domain\Model\FrontendUser;
2018-06-23 20:27:12 +02:00
use TYPO3\CMS\Extbase\Domain\Repository\FrontendUserRepository;
2018-06-23 20:18:07 +02:00
use TYPO3\CMS\Extbase\Mvc\View\ViewInterface;
use TYPO3\CMS\Extbase\Reflection\ObjectAccess;
class FrontendUserControllerTest extends TestCase
{
/**
* @var FrontendUserController
*/
protected $subject;
2018-06-23 20:27:12 +02:00
/**
* @var MockObject
*/
protected $viewMock;
2018-06-23 20:18:07 +02:00
public function setUp()
{
$this->subject = new FrontendUserController();
2018-06-23 20:27:12 +02:00
$this->viewMock = $this->getMockBuilder(ViewInterface::class)->getMock();
ObjectAccess::setProperty($this->subject, 'view', $this->viewMock, true);
2018-06-23 20:18:07 +02:00
}
/**
* @test
*/
2018-06-23 20:27:12 +02:00
public function providedFrontendUserIsAssignedToViewInShowAction()
2018-06-23 20:18:07 +02:00
{
$frontendUserMock = $this->getMockBuilder(FrontendUser::class)->getMock();
2018-06-23 20:27:12 +02:00
$this->viewMock->expects($this->once())
2018-06-23 20:18:07 +02:00
->method('assign')
->with('frontendUser', $frontendUserMock);
$this->subject->showAction($frontendUserMock);
}
2018-06-23 20:27:12 +02:00
/**
* @test
*/
public function fetchedFrontendUsersAreAssignedToViewInIndexAction()
{
$frontendUserRepositoryMock = $this->getMockBuilder(FrontendUserRepository::class)
->disableOriginalConstructor()
->getMock();
ObjectAccess::setProperty($this->subject, 'frontendUserRepository', $frontendUserRepositoryMock, true);
$frontendUserRepositoryMock->expects($this->any())
->method('findAll')
->willReturn(['user1' => 'test']);
$this->viewMock->expects($this->once())
->method('assign')
->with('frontendUsers', ['user1' => 'test']);
$this->subject->indexAction();
}
2018-06-23 20:18:07 +02:00
}