44
55namespace PhpMyAdmin \Tests \Navigation \Nodes ;
66
7+ use PhpMyAdmin \Navigation \Nodes \Node ;
78use PhpMyAdmin \Navigation \Nodes \NodeColumn ;
89use PhpMyAdmin \Tests \AbstractTestCase ;
910use PHPUnit \Framework \Attributes \CoversClass ;
1011
1112#[CoversClass(NodeColumn::class)]
12- class NodeColumnTest extends AbstractTestCase
13+ final class NodeColumnTest extends AbstractTestCase
1314{
14- /**
15- * SetUp for test cases
16- */
17- protected function setUp (): void
15+ public function testColumnNode (): void
1816 {
19- parent ::setUp ();
20-
2117 $ GLOBALS ['dbi ' ] = $ this ->createDatabaseInterface ();
22- $ GLOBALS ['server ' ] = 0 ;
23- }
2418
25- public function testConstructor (): void
26- {
27- $ parent = new NodeColumn (['name ' => 'name ' , 'key ' => 'key ' ]);
28- $ this ->assertEquals (
19+ $ nodeColumn = new NodeColumn ([
20+ 'name ' => 'actor_id ' ,
21+ 'key ' => 'PRI ' ,
22+ 'type ' => 'smallint ' ,
23+ 'default ' => null ,
24+ 'nullable ' => '' ,
25+ ]);
26+ $ this ->assertSame ('actor_id ' , $ nodeColumn ->name );
27+ $ this ->assertSame (Node::OBJECT , $ nodeColumn ->type );
28+ $ this ->assertFalse ($ nodeColumn ->isGroup );
29+ $ this ->assertSame ('actor_id (PRI, smallint) ' , $ nodeColumn ->displayName );
30+ $ this ->assertSame (['image ' => 'b_primary ' , 'title ' => 'Column ' ], $ nodeColumn ->icon );
31+ $ this ->assertSame (
2932 [
3033 'text ' => [
3134 'route ' => '/table/structure/change ' ,
@@ -37,7 +40,53 @@ public function testConstructor(): void
3740 ],
3841 'title ' => 'Structure ' ,
3942 ],
40- $ parent ->links ,
43+ $ nodeColumn ->links ,
4144 );
45+ $ this ->assertSame ('field ' , $ nodeColumn ->urlParamName );
46+ }
47+
48+ public function testColumnNodeWithTruncatedDefaultValue (): void
49+ {
50+ $ GLOBALS ['dbi ' ] = $ this ->createDatabaseInterface ();
51+
52+ $ nodeColumn = new NodeColumn ([
53+ 'name ' => 'last_update ' ,
54+ 'key ' => '' ,
55+ 'type ' => 'timestamp ' ,
56+ 'default ' => 'current_timestamp() ' ,
57+ 'nullable ' => '' ,
58+ ]);
59+ $ this ->assertSame ('last_update (timestamp, curren...) ' , $ nodeColumn ->displayName );
60+ $ this ->assertSame (['image ' => 'pause ' , 'title ' => 'Column ' ], $ nodeColumn ->icon );
61+ }
62+
63+ public function testColumnNodeWithTruncatedDefaultValue2 (): void
64+ {
65+ $ GLOBALS ['dbi ' ] = $ this ->createDatabaseInterface ();
66+
67+ $ nodeColumn = new NodeColumn ([
68+ 'name ' => 'email ' ,
69+ 'key ' => 'UNI ' ,
70+ 'type ' => 'varchar ' ,
71+ 'default ' => 'default ' ,
72+ 'nullable ' => 'nullable ' ,
73+ ]);
74+ $ this ->assertSame ('email (UNI, varchar, defaul..., nullable) ' , $ nodeColumn ->displayName );
75+ $ this ->assertSame (['image ' => 'bd_primary ' , 'title ' => 'Column ' ], $ nodeColumn ->icon );
76+ }
77+
78+ public function testColumnNodeWithoutTruncatedDefaultValue (): void
79+ {
80+ $ GLOBALS ['dbi ' ] = $ this ->createDatabaseInterface ();
81+
82+ $ nodeColumn = new NodeColumn ([
83+ 'name ' => 'email ' ,
84+ 'key ' => '' ,
85+ 'type ' => 'varchar ' ,
86+ 'default ' => 'column ' ,
87+ 'nullable ' => '' ,
88+ ]);
89+ $ this ->assertSame ('email (varchar, column) ' , $ nodeColumn ->displayName );
90+ $ this ->assertSame (['image ' => 'pause ' , 'title ' => 'Column ' ], $ nodeColumn ->icon );
4291 }
4392}
0 commit comments