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