323569353fb8570625f96cafda6e94e11a11bb27
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Module / ModuleControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Unit\Module;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Test case
19 */
20 class ModuleControllerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
21 {
22 /**
23 * @var \TYPO3\CMS\Backend\Module\ModuleController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\CMS\Core\Tests\AccessibleObjectInterface
24 */
25 protected $moduleController;
26
27 protected function setUp()
28 {
29 $this->moduleController = $this->getAccessibleMock(\TYPO3\CMS\Backend\Module\ModuleController::class, array('getLanguageService'), array(), '', false);
30 }
31
32 /**
33 * @test
34 */
35 public function createEntryFromRawDataGeneratesMenuEntry()
36 {
37 $entry = $this->moduleController->_call('createEntryFromRawData', array());
38 $this->assertInstanceOf(\TYPO3\CMS\Backend\Domain\Model\Module\BackendModule::class, $entry);
39 }
40
41 /**
42 * @test
43 */
44 public function createEntryFromRawDataSetsPropertiesInEntryObject()
45 {
46 $rawModule = array(
47 'name' => 'nameTest',
48 'title' => 'titleTest',
49 'onclick' => 'onclickTest',
50 'icon' => array(
51 'test' => '123'
52 ),
53 'link' => 'linkTest',
54 'description' => 'descriptionTest',
55 'navigationComponentId' => 'navigationComponentIdTest'
56 );
57
58 $languageServiceMock = $this->getMock(\TYPO3\CMS\Lang\LanguageService::class, array(), array(), '', false);
59 $languageServiceMock->expects($this->once())->method('sL')->will($this->returnValue('titleTest'));
60 $this->moduleController->expects($this->once())->method('getLanguageService')->will($this->returnValue($languageServiceMock));
61
62 /** @var $entry \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule */
63 $entry = $this->moduleController->_call('createEntryFromRawData', $rawModule);
64 $this->assertEquals('nameTest', $entry->getName());
65 $this->assertEquals('titleTest', $entry->getTitle());
66 $this->assertEquals('linkTest', $entry->getLink());
67 $this->assertEquals('onclickTest', $entry->getOnClick());
68 $this->assertEquals('navigationComponentIdTest', $entry->getNavigationComponentId());
69 $this->assertEquals('descriptionTest', $entry->getDescription());
70 $this->assertEquals(array('test' => '123'), $entry->getIcon());
71 }
72
73 /**
74 * @test
75 */
76 public function createEntryFromRawDataSetsLinkIfPathIsGivenInEntryObject()
77 {
78 $rawModule = array(
79 'path' => 'pathTest'
80 );
81 /** @var $entry \TYPO3\CMS\Backend\Domain\Model\Module\BackendModule */
82 $entry = $this->moduleController->_call('createEntryFromRawData', $rawModule);
83 $this->assertEquals('pathTest', $entry->getLink());
84 }
85 }