ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ViewControlPaginationTest Class Reference
+ Inheritance diagram for ViewControlPaginationTest:
+ Collaboration diagram for ViewControlPaginationTest:

Public Member Functions

 testViewControlPaginationConstruct ()
 
 testViewControlPaginationWithWrongValue ()
 
 testViewControlPaginationMutators ()
 
 testViewControlPaginationWithInput (int $offset, int $page_size, array $expected)
 providePaginationInput More...
 
 testViewControlPaginationRendering ()
 
 testViewControlPaginationRenderingRanges ()
 
 testViewControlPaginationRenderingFindCurrent ()
 
 testViewControlPaginationRenderingEntries ()
 
 testViewControlPaginationRenderingOutsideContainer ()
 
- Public Member Functions inherited from ViewControlBaseTest
 getUIFactory ()
 
 getDataFactory ()
 
- Public Member Functions inherited from ILIAS_UI_TestBase
 setUp ()
 
 tearDown ()
 
 getUIFactory ()
 
 getTemplateFactory ()
 
 getResourceRegistry ()
 
 getLanguage ()
 
 getJavaScriptBinding ()
 
 getRefinery ()
 
 getImagePathResolver ()
 
 getDataFactory ()
 
 getDefaultRenderer (JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
 
 getDecoratedRenderer (Renderer $default)
 
 normalizeHTML (string $html)
 
 assertHTMLEquals (string $expected_html_as_string, string $html_as_string)
 

Static Public Member Functions

static providePaginationInput ()
 

Protected Member Functions

 getStubRenderer ()
 
- Protected Member Functions inherited from ViewControlBaseTest
 getNamesource ()
 
 buildDataFactory ()
 
 buildRefinery ()
 
 buildFieldFactory ()
 
 buildVCFactory ()
 
- Protected Member Functions inherited from ILIAS_UI_TestBase
 brutallyTrimHTML (string $html)
 A more radical version of normalizeHTML. More...
 
 brutallyTrimSignals (string $html)
 A naive replacement of all il_signal-ids with dots to ease comparisons of rendered output. More...
 

Detailed Description

Definition at line 49 of file ViewControlPaginationTest.php.

Member Function Documentation

◆ getStubRenderer()

◆ providePaginationInput()

static ViewControlPaginationTest::providePaginationInput ( )
static

Definition at line 75 of file ViewControlPaginationTest.php.

75  : array
76  {
77  return [
78  [
79  'offset' => 24,
80  'limit' => 25,
81  'expected' => [0, 25]
82  ],
83  [
84  'offset' => 25,
85  'limit' => 25,
86  'expected' => [25, 25]
87  ],
88  [
89  'offset' => 52,
90  'limit' => 25,
91  'expected' => [50, 25]
92  ],
93  [
94  'offset' => 7,
95  'limit' => 5,
96  'expected' => [5, 5]
97  ],
98  [
99  'offset' => 99,
100  'limit' => 5,
101  'expected' => [95, 5]
102  ],
103  [
104  'offset' => 4,
105  'limit' => 3,
106  'expected' => [3, 3]
107  ],
108  [
109  'offset' => 4,
110  'limit' => PHP_INT_MAX,
111  'expected' => [0, PHP_INT_MAX]
112  ],
113  [
114  'offset' => 0,
115  'limit' => 2,
116  'expected' => [0, 2]
117  ],
118  [
119  'offset' => 10,
120  'limit' => 0,
121  'expected' => [10, 5] //default smallest limit
122  ],
123 
124  ];
125  }

◆ testViewControlPaginationConstruct()

ViewControlPaginationTest::testViewControlPaginationConstruct ( )

Definition at line 51 of file ViewControlPaginationTest.php.

51  : void
52  {
53  $vc = $this->buildVCFactory()->pagination();
54 
55  $this->assertInstanceOf(Signal::class, $vc->getInternalSignal());
56  $this->assertIsArray($vc->getLimitOptions());
57  $this->assertEquals('', $vc->getLabelLimit());
58  }

◆ testViewControlPaginationMutators()

ViewControlPaginationTest::testViewControlPaginationMutators ( )

Definition at line 67 of file ViewControlPaginationTest.php.

67  : void
68  {
69  $o = [1,2,3];
70  $l = 'limitlabel';
71  $vc = $this->buildVCFactory()->pagination();
72  $this->assertEquals($o, $vc->withLimitOptions($o)->getLimitOptions($o));
73  }

◆ testViewControlPaginationRendering()

ViewControlPaginationTest::testViewControlPaginationRendering ( )

Definition at line 162 of file ViewControlPaginationTest.php.

162  : void
163  {
164  $r = $this->getDefaultRenderer();
165  $vc = $this->buildVCFactory()->pagination()
166  ->withLimitOptions([2, 5, 10])
167  ->withTotalCount(42)
168  ->withValue([Pagination::FNAME_OFFSET => 12, Pagination::FNAME_LIMIT => 2])
169  ->withOnChange((new SignalGenerator())->create());
170 
171  $expected = $this->brutallyTrimHTML('
172 <div class="il-viewcontrol il-viewcontrol-pagination l-bar__element" id="id_13">
173  <div class="dropdown il-viewcontrol-pagination__sectioncontrol">
174  <div class="btn btn-ctrl browse previous">
175  <a tabindex="0" class="glyph" aria-label="back" id="id_8">
176  <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
177  </a>
178  </div>
179 
180  <button class="btn btn-link" id="id_1">1</button>
181  <span class="il-viewcontrol-pagination__spacer">...</span>
182  <button class="btn btn-link" id="id_2">5</button>
183  <button class="btn btn-link" id="id_3">6</button>
184  <button class="btn btn-link engaged" aria-pressed="true" id="id_4">7</button>
185  <button class="btn btn-link" id="id_5">8</button>
186  <button class="btn btn-link" id="id_6">9</button>
187  <span class="il-viewcontrol-pagination__spacer">...</span>
188  <button class="btn btn-link" id="id_7">21</button>
189 
190  <div class="btn btn-ctrl browse next">
191  <a tabindex="0" class="glyph" aria-label="next" id="id_9">
192  <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
193  </a>
194  </div>
195  </div>
196 
197  <div class="dropdown il-viewcontrol-pagination__num-of-items">
198  <button class="btn btn-ctrl dropdown-toggle" type="button" data-toggle="dropdown" aria-label="label_pagination_limit" aria-haspopup="true" aria-expanded="false" aria-controls="id_13_ctrl_limit">
199  <span class="caret"></span>
200  </button>
201  <ul id="id_13_ctrl_limit" class="dropdown-menu">
202  <li class="selected"><button class="btn btn-link" id="id_10">2</button></li>
203  <li><button class="btn btn-link" id="id_11">5</button></li>
204  <li><button class="btn btn-link" id="id_12">10</button></li>
205  </ul>
206  </div>
207 
208  <div class="il-viewcontrol-value hidden" role="none">
209  <input id="id_14" type="hidden" value="12" />
210  <input id="id_15" type="hidden" value="2" />
211  </div>
212 </div>
213  ');
214 
215  $html = $this->brutallyTrimHTML($r->render($vc));
216  $this->assertEquals($expected, $html);
217  }
getDefaultRenderer(JavaScriptBinding $js_binding=null, array $with_stub_renderings=[])
Definition: Base.php:355
brutallyTrimHTML(string $html)
A more radical version of normalizeHTML.
Definition: Base.php:444

◆ testViewControlPaginationRenderingEntries()

ViewControlPaginationTest::testViewControlPaginationRenderingEntries ( )

Definition at line 254 of file ViewControlPaginationTest.php.

254  : void
255  {
256  $r = $this->getStubRenderer();
257  $ranges = $r->mock_buildRanges(203, 5);
258  $slices = $r->mock_sliceRangesToVisibleEntries($ranges, $current = 6, $visible_entries = 5);
259  $this->assertEquals(5, count($slices));
260  $this->assertEquals(0, $slices[0]->getStart());
261  $this->assertEquals(25, $slices[1]->getStart());
262  $this->assertEquals(30, $slices[2]->getStart());
263  $this->assertEquals(35, $slices[3]->getStart());
264  $this->assertEquals(200, $slices[4]->getStart());
265  }

◆ testViewControlPaginationRenderingFindCurrent()

ViewControlPaginationTest::testViewControlPaginationRenderingFindCurrent ( )

Definition at line 243 of file ViewControlPaginationTest.php.

243  : void
244  {
245  $r = $this->getStubRenderer();
246  $ranges = $r->mock_buildRanges(20, 5);
247  $this->assertEquals(0, $r->mock_findCurrentPage($ranges, 3));
248  $this->assertEquals(1, $r->mock_findCurrentPage($ranges, 5));
249  $this->assertEquals(1, $r->mock_findCurrentPage($ranges, 6));
250  $this->assertEquals(2, $r->mock_findCurrentPage($ranges, 10));
251  $this->assertEquals(3, $r->mock_findCurrentPage($ranges, 19));
252  }

◆ testViewControlPaginationRenderingOutsideContainer()

ViewControlPaginationTest::testViewControlPaginationRenderingOutsideContainer ( )

Definition at line 267 of file ViewControlPaginationTest.php.

267  : void
268  {
269  $this->expectException(\LogicException::class);
270  $this->buildVCFactory()->pagination()->getOnChangeSignal();
271  }

◆ testViewControlPaginationRenderingRanges()

ViewControlPaginationTest::testViewControlPaginationRenderingRanges ( )

Definition at line 232 of file ViewControlPaginationTest.php.

232  : void
233  {
234  $r = $this->getStubRenderer();
235  $ranges = $r->mock_buildRanges($total = 8, $pagelimit = 3); //0-2, 3-5, 6-7
236  $this->assertEquals(3, count($ranges));
237  $ranges = $r->mock_buildRanges(10, 5); //0-4, 5-9
238  $this->assertEquals(2, count($ranges));
239  $ranges = $r->mock_buildRanges(101, 5);
240  $this->assertEquals(21, count($ranges));
241  }

◆ testViewControlPaginationWithInput()

ViewControlPaginationTest::testViewControlPaginationWithInput ( int  $offset,
int  $page_size,
array  $expected 
)

providePaginationInput

Definition at line 130 of file ViewControlPaginationTest.php.

134  : void {
135  $v = [
136  Pagination::FNAME_OFFSET => $offset,
137  Pagination::FNAME_LIMIT => $page_size
138  ];
139  $input = $this->createMock(InputData::class);
140  $input->expects($this->exactly(2))
141  ->method("getOr")
142  ->will(
143  $this->onConsecutiveCalls($v[Pagination::FNAME_OFFSET], $v[Pagination::FNAME_LIMIT])
144  );
145 
146  $vc = $this->buildVCFactory()->pagination()
147  ->withNameFrom($this->getNamesource())
148  ->withInput($input);
149 
150  $df = $this->buildDataFactory();
151  $this->assertEquals(
152  $df->ok($df->range(...$expected)),
153  $vc->getContent()
154  );
155 
156  $this->assertEquals(
157  [Pagination::FNAME_OFFSET => $offset, Pagination::FNAME_LIMIT => $page_size],
158  $vc->getValue()
159  );
160  }

◆ testViewControlPaginationWithWrongValue()

ViewControlPaginationTest::testViewControlPaginationWithWrongValue ( )

Definition at line 60 of file ViewControlPaginationTest.php.

60  : void
61  {
62  $this->expectException(\Exception::class);
63  $vc = $this->buildVCFactory()->pagination()
64  ->withValue('notokvalue:-2');
65  }

The documentation for this class was generated from the following file: