[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Tests / Unit / Template / Components / Button / SplitButtonTest.php
1 <?php
2 namespace TYPO3\CMS\Backend\Tests\Template\Components\Buttons;
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 use TYPO3\CMS\Backend\Template\Components\Buttons\LinkButton;
18 use TYPO3\CMS\Backend\Template\Components\Buttons\SplitButton;
19 use TYPO3\CMS\Core\Imaging\Icon;
20
21 /**
22 * Class BackendModuleRequestHandlerTest
23 */
24 class SplitButtonTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTestCase
25 {
26 /**
27 * Try to validate an empty button
28 *
29 * @test
30 * @return void
31 */
32 public function isButtonValidBlankCallExpectFalse()
33 {
34 $button = new SplitButton();
35 $isValid = $button->isValid();
36 $this->assertFalse($isValid);
37 }
38
39 /**
40 * Try adding an invalid button to a splitButton
41 *
42 * @test
43 * @return void
44 */
45 public function isButtonValidInvalidButtonGivenExpectFalse()
46 {
47 $this->expectException(\InvalidArgumentException::class);
48 $this->expectExceptionCode(1441706330);
49 $button = new SplitButton();
50
51 $primaryAction = new LinkButton();
52 $button->addItem($primaryAction);
53
54 $isValid = $button->isValid();
55 $this->assertFalse($isValid);
56 }
57
58 /**
59 * Try to add multiple primary actions
60 *
61 * @test
62 * @return void
63 */
64 public function isButtonValidBrokenSetupMultiplePrimaryActionsGivenExpectFalse()
65 {
66 $this->expectException(\InvalidArgumentException::class);
67 $this->expectExceptionCode(1441706340);
68 $button = new SplitButton();
69
70 $primaryAction = new LinkButton();
71 $icon = new Icon();
72 $primaryAction->setTitle('husel')->setHref('husel')->setIcon($icon);
73 $button->addItem($primaryAction, true);
74
75 $anotherPrimaryAction = new LinkButton();
76 $anotherPrimaryAction->setTitle('husel')->setHref('husel')->setIcon($icon);
77 $button->addItem($anotherPrimaryAction, true);
78
79 $isValid = $button->isValid();
80 $this->assertFalse($isValid);
81 }
82
83 /**
84 * Try to add an invalid button as second parameter
85 *
86 * @test
87 * @return void
88 */
89 public function isButtonValidBrokenSetupInvalidButtonAsSecondParametersGivenExpectFalse()
90 {
91 $this->expectException(\InvalidArgumentException::class);
92 $this->expectExceptionCode(1441706330);
93 $button = new SplitButton();
94
95 $primaryAction = new LinkButton();
96 $icon = new Icon();
97 $primaryAction->setTitle('husel')->setHref('husel')->setIcon($icon);
98 $button->addItem($primaryAction, true);
99
100 $anotherPrimaryAction = new LinkButton();
101 $anotherPrimaryAction->setTitle('husel')->setHref('husel');
102 $button->addItem($anotherPrimaryAction, true);
103
104 $isValid = $button->isValid();
105 $this->assertFalse($isValid);
106 }
107
108 /**
109 * Send in a valid button
110 *
111 * @test
112 * @return void
113 */
114 public function isButtonValidValidSetupExpectTrue()
115 {
116 $button = new SplitButton();
117
118 $primaryAction = new LinkButton();
119 $icon = new Icon();
120 $primaryAction->setTitle('husel')->setHref('husel')->setIcon($icon);
121 $button->addItem($primaryAction, true);
122
123 $anotherAction = new LinkButton();
124 $anotherAction->setTitle('husel')->setHref('husel')->setIcon($icon);
125 $button->addItem($anotherAction);
126
127 $isValid = $button->isValid();
128 $this->assertTrue($isValid);
129 }
130 }