[TASK] Namespace and move ModuleUtilityTest
[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 * Copyright notice
6 *
7 * (c) 2012 Susanne Moog <typo3@susannemoog.de>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the textfile GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29 /**
30 * Test class for module menu utilities
31 *
32 * @author Susanne Moog <typo3@susannemoog.de>
33 * @package TYPO3
34 * @subpackage backend
35 */
36 class ModuleControllerTest extends \Tx_PhpUnit_TestCase {
37
38 /**
39 * @var TYPO3\CMS\Backend\Module\ModuleController
40 */
41 protected $moduleController;
42
43 /**
44 * Helper function to call protected or private methods
45 *
46 * @param string $className The className
47 * @param string $name the name of the method to call
48 * @param mixed $argument The argument for the method call (only one in this test class needed)
49 * @return mixed
50 */
51 public function callInaccessibleMethod($className, $name, $argument) {
52 $class = new \ReflectionClass($className);
53 $object = new $className();
54 $method = $class->getMethod($name);
55 $method->setAccessible(TRUE);
56 return $method->invoke($object, $argument);
57 }
58
59 /**
60 * @test
61 */
62 public function createEntryFromRawDataGeneratesMenuEntry() {
63 $entry = $this->callInaccessibleMethod('TYPO3\\CMS\\Backend\\Module\\ModuleController', 'createEntryFromRawData', array());
64 $this->assertInstanceOf('TYPO3\\CMS\\Backend\\Domain\\Model\\Module\\BackendModule', $entry);
65 }
66
67 /**
68 * @test
69 */
70 public function createEntryFromRawDataSetsPropertiesInEntryObject() {
71 $rawModule = array(
72 'name' => 'nameTest',
73 'title' => 'titleTest',
74 'onclick' => 'onclickTest',
75 'icon' => array(
76 'test' => '123'
77 ),
78 'link' => 'linkTest',
79 'description' => 'descriptionTest',
80 'navigationComponentId' => 'navigationComponentIdTest'
81 );
82 $entry = $this->callInaccessibleMethod('TYPO3\\CMS\\Backend\\Module\\ModuleController', 'createEntryFromRawData', $rawModule);
83 $this->assertEquals('nameTest', $entry->getName());
84 $this->assertEquals('titleTest', $entry->getTitle());
85 $this->assertEquals('linkTest', $entry->getLink());
86 $this->assertEquals('onclickTest', $entry->getOnClick());
87 $this->assertEquals('navigationComponentIdTest', $entry->getNavigationComponentId());
88 $this->assertEquals('descriptionTest', $entry->getDescription());
89 $this->assertEquals(array('test' => '123'), $entry->getIcon());
90 }
91
92 /**
93 * @test
94 */
95 public function createEntryFromRawDataSetsLinkIfPathIsGivenInEntryObject() {
96 $rawModule = array(
97 'path' => 'pathTest'
98 );
99 $entry = $this->callInaccessibleMethod('TYPO3\\CMS\\Backend\\Module\\ModuleController', 'createEntryFromRawData', $rawModule);
100 $this->assertEquals('pathTest', $entry->getLink());
101 }
102
103 }
104
105 ?>