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