Remove some useless comments
[phpmyadmin.git] / test / classes / BrowseForeignersTest.php
blob23600e99f14c07a2c95d6ef24c4551c12e1e8089
1 <?php
3 declare(strict_types=1);
5 namespace PhpMyAdmin\Tests;
7 use PhpMyAdmin\BrowseForeigners;
8 use PhpMyAdmin\Template;
10 class BrowseForeignersTest extends AbstractTestCase
12 /** @var BrowseForeigners */
13 private $browseForeigners;
15 /**
16 * Setup for test cases
18 protected function setUp(): void
20 parent::setUp();
21 parent::setTheme();
22 $GLOBALS['cfg']['LimitChars'] = 50;
23 $GLOBALS['cfg']['MaxRows'] = 25;
24 $GLOBALS['cfg']['RepeatCells'] = 100;
25 $GLOBALS['cfg']['ShowAll'] = false;
26 $this->browseForeigners = new BrowseForeigners(new Template());
29 /**
30 * Test for BrowseForeigners::getForeignLimit
32 public function testGetForeignLimit(): void
34 $this->assertNull(
35 $this->browseForeigners->getForeignLimit('Show all')
38 $this->assertEquals(
39 'LIMIT 0, 25 ',
40 $this->browseForeigners->getForeignLimit(null)
43 $_POST['pos'] = 10;
45 $this->assertEquals(
46 'LIMIT 10, 25 ',
47 $this->browseForeigners->getForeignLimit(null)
50 $GLOBALS['cfg']['MaxRows'] = 50;
51 $browseForeigners = new BrowseForeigners(new Template());
53 $this->assertEquals(
54 'LIMIT 10, 50 ',
55 $browseForeigners->getForeignLimit(null)
58 $this->assertEquals(
59 'LIMIT 10, 50 ',
60 $browseForeigners->getForeignLimit('xyz')
64 /**
65 * Test for BrowseForeigners::getHtmlForGotoPage
67 public function testGetHtmlForGotoPage(): void
69 $this->assertEquals(
70 '',
71 $this->callFunction(
72 $this->browseForeigners,
73 BrowseForeigners::class,
74 'getHtmlForGotoPage',
75 [null]
79 $_POST['pos'] = 15;
80 $foreignData = [];
81 $foreignData['disp_row'] = [];
82 $foreignData['the_total'] = 5;
84 $this->assertEquals(
85 '',
86 $this->callFunction(
87 $this->browseForeigners,
88 BrowseForeigners::class,
89 'getHtmlForGotoPage',
90 [$foreignData]
94 $foreignData['the_total'] = 30;
95 $result = $this->callFunction(
96 $this->browseForeigners,
97 BrowseForeigners::class,
98 'getHtmlForGotoPage',
99 [$foreignData]
102 $this->assertStringStartsWith(
103 'Page number:',
104 $result
107 $this->assertStringEndsWith(
108 '</select>',
109 $result
112 $this->assertStringContainsString(
113 '<select class="pageselector ajax" name="pos"',
114 $result
117 $this->assertStringContainsString(
118 '<option selected="selected" '
119 . 'style="font-weight: bold" value="0">',
120 $result
123 $this->assertStringContainsString(
124 '<option value="25"',
125 $result
130 * Test for BrowseForeigners::getDescriptionAndTitle
132 public function testGetDescriptionAndTitle(): void
134 $desc = 'foobar<baz';
136 $this->assertEquals(
138 'foobar&lt;baz',
141 $this->callFunction(
142 $this->browseForeigners,
143 BrowseForeigners::class,
144 'getDescriptionAndTitle',
145 [$desc]
149 $GLOBALS['cfg']['LimitChars'] = 5;
150 $browseForeigners = new BrowseForeigners(new Template());
152 $this->assertEquals(
154 'fooba...',
155 'foobar&lt;baz',
157 $this->callFunction(
158 $browseForeigners,
159 BrowseForeigners::class,
160 'getDescriptionAndTitle',
161 [$desc]
167 * Test for BrowseForeigners::getHtmlForRelationalFieldSelection
169 public function testGetHtmlForRelationalFieldSelection(): void
171 $db = '';
172 $table = '';
173 $field = 'foo';
174 $foreignData = [];
175 $foreignData['disp_row'] = '';
176 $fieldkey = 'bar';
177 $current_value = '';
178 $_POST['rownumber'] = 1;
179 $_POST['foreign_filter'] = '5';
180 $result = $this->browseForeigners->getHtmlForRelationalFieldSelection(
181 $db,
182 $table,
183 $field,
184 $foreignData,
185 $fieldkey,
186 $current_value
189 $this->assertStringContainsString(
190 '<form class="ajax" '
191 . 'id="browse_foreign_form" name="browse_foreign_from" '
192 . 'action="index.php?route=/browse-foreigners',
193 $result
195 $this->assertStringContainsString(
196 '" method="post">',
197 $result
200 $this->assertStringContainsString(
201 '<fieldset>',
202 $result
205 $this->assertStringContainsString(
206 '<input type="hidden" name="field" value="foo">',
207 $result
210 $this->assertStringContainsString(
211 '<input type="hidden" name="fieldkey" value="bar">',
212 $result
215 $this->assertStringContainsString(
216 '<input type="hidden" name="rownumber" value="1">',
217 $result
220 $this->assertStringContainsString(
221 '<span class="formelement">',
222 $result
225 $this->assertStringContainsString(
226 '<label for="input_foreign_filter">',
227 $result
230 $this->assertStringContainsString(
231 '<input type="text" name="foreign_filter" '
232 . 'id="input_foreign_filter" '
233 . 'value="5" data-old="5" '
234 . '>',
235 $result
238 $this->assertStringContainsString(
239 '<input class="btn btn-primary" type="submit" name="submit_foreign_filter" value="Go">',
240 $result
243 $this->assertStringContainsString(
244 '<span class="formelement">',
245 $result
248 $this->assertStringContainsString(
249 '<table width="100%" id="browse_foreign_table">',
250 $result
253 $foreignData['disp_row'] = [];
254 $foreignData['the_total'] = 5;
255 $result = $this->browseForeigners->getHtmlForRelationalFieldSelection(
256 $db,
257 $table,
258 $field,
259 $foreignData,
260 $fieldkey,
261 $current_value
264 $this->assertStringContainsString(
265 '<table width="100%" id="browse_foreign_table">',
266 $result
269 $this->assertStringContainsString(
270 '<th>',
271 $result