|
3 | 3 | namespace ipl\Tests\Web\Common; |
4 | 4 |
|
5 | 5 | use Icinga\Web\UrlParams; |
| 6 | +use InvalidArgumentException; |
6 | 7 | use ipl\Html\Form; |
7 | 8 | use ipl\I18n\NoopTranslator; |
8 | 9 | use ipl\I18n\StaticTranslator; |
9 | 10 | use ipl\Web\Common\Controls; |
| 11 | +use ipl\Web\Control\LimitControl; |
| 12 | +use ipl\Web\Control\PaginationControl; |
10 | 13 | use ipl\Web\Control\ViewModeSwitcher; |
11 | 14 | use ipl\Tests\Web\TestCase; |
12 | 15 | use Psr\Http\Message\ServerRequestInterface; |
@@ -111,6 +114,52 @@ public function testCreateViewModeSwitcherThrowsOnClassThatIsNoViewModeSwitcher( |
111 | 114 | ); |
112 | 115 | } |
113 | 116 |
|
| 117 | + public function testApplyViewModeLimitDoublesLimitsInMinimalMode(): void |
| 118 | + { |
| 119 | + $switcher = $this->createMock(ViewModeSwitcher::class); |
| 120 | + $switcher->method('getViewMode')->willReturn('minimal'); |
| 121 | + |
| 122 | + $limitControl = $this->createMock(LimitControl::class); |
| 123 | + $limitControl->method('getDefaultLimit')->willReturn(25); |
| 124 | + $limitControl->expects($this->once())->method('setDefaultLimit')->with(50); |
| 125 | + |
| 126 | + $paginationControl = $this->createMock(PaginationControl::class); |
| 127 | + $paginationControl->method('getDefaultPageSize')->willReturn(25); |
| 128 | + $paginationControl->expects($this->once()) |
| 129 | + ->method('setDefaultPageSize') |
| 130 | + ->with(50) |
| 131 | + ->willReturnSelf(); |
| 132 | + $paginationControl->expects($this->once())->method('apply')->willReturnSelf(); |
| 133 | + |
| 134 | + $controller = $this->controls(); |
| 135 | + $controller->track($switcher); |
| 136 | + $controller->applyLimit($limitControl, $paginationControl); |
| 137 | + } |
| 138 | + |
| 139 | + public function testApplyViewModeLimitLeavesLimitsUntouchedInNonMinimalMode(): void |
| 140 | + { |
| 141 | + $switcher = $this->createMock(ViewModeSwitcher::class); |
| 142 | + $switcher->method('getViewMode')->willReturn('common'); |
| 143 | + |
| 144 | + $limitControl = $this->createMock(LimitControl::class); |
| 145 | + $limitControl->expects($this->never())->method('setDefaultLimit'); |
| 146 | + |
| 147 | + $paginationControl = $this->createMock(PaginationControl::class); |
| 148 | + $paginationControl->expects($this->never())->method('setDefaultPageSize'); |
| 149 | + |
| 150 | + $controller = $this->controls(); |
| 151 | + $controller->track($switcher); |
| 152 | + $controller->applyLimit($limitControl, $paginationControl); |
| 153 | + } |
| 154 | + |
| 155 | + public function testApplyViewModeLimitDoesNothingWithoutTrackedSwitcher(): void |
| 156 | + { |
| 157 | + $limitControl = $this->createMock(LimitControl::class); |
| 158 | + $limitControl->expects($this->never())->method('setDefaultLimit'); |
| 159 | + |
| 160 | + $this->controls()->applyLimit($limitControl); |
| 161 | + } |
| 162 | + |
114 | 163 | public function testHandleControls(): void |
115 | 164 | { |
116 | 165 | $request = $this->createMock(ServerRequestInterface::class); |
@@ -157,6 +206,13 @@ public function handle(ServerRequestInterface $request): void |
157 | 206 | { |
158 | 207 | $this->handleControls($request); |
159 | 208 | } |
| 209 | + |
| 210 | + public function applyLimit( |
| 211 | + LimitControl $limitControl, |
| 212 | + ?PaginationControl $paginationControl = null |
| 213 | + ): void { |
| 214 | + $this->applyViewModeLimit($limitControl, $paginationControl); |
| 215 | + } |
160 | 216 | }; |
161 | 217 | } |
162 | 218 | } |
0 commit comments