77use PhpMyAdmin \Config ;
88use PhpMyAdmin \ConfigStorage \Relation ;
99use PhpMyAdmin \Controllers \Table \ZoomSearchController ;
10- use PhpMyAdmin \DatabaseInterface ;
1110use PhpMyAdmin \DbTableExists ;
1211use PhpMyAdmin \Http \Factory \ServerRequestFactory ;
1312use PhpMyAdmin \Table \Search ;
1413use PhpMyAdmin \Template ;
1514use PhpMyAdmin \Tests \AbstractTestCase ;
16- use PhpMyAdmin \Tests \Stubs \DbiDummy ;
1715use PhpMyAdmin \Tests \Stubs \ResponseRenderer ;
1816use PHPUnit \Framework \Attributes \CoversClass ;
1917
2018#[CoversClass(ZoomSearchController::class)]
21- class ZoomSearchControllerTest extends AbstractTestCase
19+ final class ZoomSearchControllerTest extends AbstractTestCase
2220{
23- protected DatabaseInterface $ dbi ;
24-
25- protected DbiDummy $ dummyDbi ;
26-
27- protected function setUp (): void
28- {
29- parent ::setUp ();
30-
31- $ this ->dummyDbi = $ this ->createDbiDummy ();
32- $ this ->dbi = $ this ->createDatabaseInterface ($ this ->dummyDbi );
33- DatabaseInterface::$ instance = $ this ->dbi ;
34- }
35-
3621 public function testZoomSearchController (): void
3722 {
3823 $ GLOBALS ['server ' ] = 2 ;
@@ -41,8 +26,11 @@ public function testZoomSearchController(): void
4126 $ GLOBALS ['text_dir ' ] = 'ltr ' ;
4227 Config::getInstance ()->selectedServer ['DisableIS ' ] = true ;
4328
44- $ this ->dummyDbi ->addSelectDb ('test_db ' );
45- $ this ->dummyDbi ->addResult ('SHOW TABLES LIKE \'test_table \'; ' , [['test_table ' ]]);
29+ $ dbiDummy = $ this ->createDbiDummy ();
30+ $ dbi = $ this ->createDatabaseInterface ($ dbiDummy );
31+
32+ $ dbiDummy ->addSelectDb ('test_db ' );
33+ $ dbiDummy ->addResult ('SHOW TABLES LIKE \'test_table \'; ' , [['test_table ' ]]);
4634
4735 $ request = ServerRequestFactory::create ()->createServerRequest ('GET ' , 'http://example.com/ ' )
4836 ->withQueryParams (['db ' => 'test_db ' , 'table ' => 'test_table ' ]);
@@ -52,10 +40,10 @@ public function testZoomSearchController(): void
5240 $ controller = new ZoomSearchController (
5341 $ response ,
5442 $ template ,
55- new Search ($ this -> dbi ),
56- new Relation ($ this -> dbi ),
57- $ this -> dbi ,
58- new DbTableExists ($ this -> dbi ),
43+ new Search ($ dbi ),
44+ new Relation ($ dbi ),
45+ $ dbi ,
46+ new DbTableExists ($ dbi ),
5947 );
6048 $ controller ($ request );
6149
@@ -75,4 +63,66 @@ public function testZoomSearchController(): void
7563
7664 $ this ->assertSame ($ expected , $ response ->getHTMLResult ());
7765 }
66+
67+ public function testChangeTableInfoAction (): void
68+ {
69+ $ GLOBALS ['db ' ] = 'test_db ' ;
70+ $ GLOBALS ['table ' ] = 'test_table ' ;
71+ Config::getInstance ()->selectedServer ['DisableIS ' ] = true ;
72+
73+ $ _POST ['field ' ] = 'datetimefield ' ;
74+
75+ $ dbiDummy = $ this ->createDbiDummy ();
76+ $ dbi = $ this ->createDatabaseInterface ($ dbiDummy );
77+
78+ $ dbiDummy ->addSelectDb ('test_db ' );
79+ $ dbiDummy ->addResult ('SHOW TABLES LIKE \'test_table \'; ' , [['test_table ' ]]);
80+
81+ $ request = ServerRequestFactory::create ()->createServerRequest ('POST ' , 'http://example.com/ ' )
82+ ->withQueryParams (['db ' => 'test_db ' , 'table ' => 'test_table ' ])
83+ ->withParsedBody (['change_tbl_info ' => '1 ' ]);
84+
85+ $ response = new ResponseRenderer ();
86+ $ template = new Template ();
87+ $ controller = new ZoomSearchController (
88+ $ response ,
89+ $ template ,
90+ new Search ($ dbi ),
91+ new Relation ($ dbi ),
92+ $ dbi ,
93+ new DbTableExists ($ dbi ),
94+ );
95+ $ controller ($ request );
96+
97+ // phpcs:disable Generic.Files.LineLength.TooLong
98+ $ operators = <<<'HTML'
99+ <select class="column-operator" id="ColumnOperator0" name="criteriaColumnOperators[0]">
100+ <option value="=">=</option><option value=">">></option><option value=">=">>=</option><option value="<"><</option><option value="<="><=</option><option value="!=">!=</option><option value="LIKE">LIKE</option><option value="LIKE %...%">LIKE %...%</option><option value="NOT LIKE">NOT LIKE</option><option value="NOT LIKE %...%">NOT LIKE %...%</option><option value="IN (...)">IN (...)</option><option value="NOT IN (...)">NOT IN (...)</option><option value="BETWEEN">BETWEEN</option><option value="NOT BETWEEN">NOT BETWEEN</option>
101+ </select>
102+
103+ HTML;
104+ // phpcs:enable
105+
106+ $ value = <<<'HTML'
107+ <input
108+ type="text"
109+ name="criteriaValues[0]"
110+ data-type="DATETIME"
111+ onfocus="return verifyAfterSearchFieldChange(0, '#zoom_search_form')"
112+ size="40"
113+ class="textfield datetimefield"
114+ id="fieldID_0"
115+ >
116+
117+ HTML;
118+
119+ $ expected = [
120+ 'field_type ' => 'datetime ' ,
121+ 'field_collation ' => '' ,
122+ 'field_operators ' => $ operators ,
123+ 'field_value ' => $ value ,
124+ ];
125+
126+ $ this ->assertSame ($ expected , $ response ->getJSONResult ());
127+ }
78128}
0 commit comments