22
33namespace Kirby \Panel ;
44
5- use Kirby \Cms \Url ;
65use Kirby \Exception \Exception ;
76use Kirby \Exception \NotFoundException ;
87use Kirby \Filesystem \F ;
98use Kirby \Http \Response ;
10- use Kirby \Toolkit \Str ;
119use PHPUnit \Framework \Attributes \CoversClass ;
1210
1311#[CoversClass(Router::class)]
1412class RouterTest extends TestCase
1513{
16- public const string TMP = KIRBY_TMP_DIR . '/Panel.Panel ' ;
17- public const string VITE_RUNNING_PATH = KIRBY_DIR . '/panel/.vite-running ' ;
18-
19- protected bool $ hadViteRunning ;
20-
21- protected function setUp (): void
22- {
23- parent ::setUp ();
24-
25- // initialize development mode to a known state
26- $ this ->hadViteRunning = is_file (static ::VITE_RUNNING_PATH );
27- F::remove (static ::VITE_RUNNING_PATH );
28- }
29-
30- protected function tearDown (): void
31- {
32- parent ::tearDown ();
33-
34- // reset development mode
35- if ($ this ->hadViteRunning === true ) {
36- touch (static ::VITE_RUNNING_PATH );
37- } else {
38- F::remove (static ::VITE_RUNNING_PATH );
39- }
40- }
41-
42- public function testCallIcons (): void
43- {
44- $ router = new Router ($ this ->app ->panel ());
45- $ response = $ router ->call ('assets/ ' . $ this ->app ->versionHash () . '/icons.svg ' );
46-
47- // the sprite is served before any area route can catch the path
48- $ this ->assertSame (200 , $ response ->code ());
49- $ this ->assertSame ('image/svg+xml ' , $ response ->type ());
50- $ this ->assertStringContainsString ('id="icon-accessibility" ' , $ response ->body ());
51- }
14+ public const string TMP = KIRBY_TMP_DIR . '/Panel.Panel ' ;
5215
5316 public function testIcons (): void
5417 {
@@ -60,32 +23,33 @@ public function testIcons(): void
6023 'public, max-age=31536000, immutable ' ,
6124 $ response ->header ('Cache-Control ' )
6225 );
63- $ this ->assertStringContainsString ('id="icon-accessibility" ' , $ response ->body ());
26+ $ this ->assertStringContainsString ('<svg ' , $ response ->body ());
6427 }
6528
6629 public function testIconsInDevMode (): void
6730 {
31+ // fake a panel dir with a running Vite dev server
32+ $ panel = static ::TMP . '/panel ' ;
33+ F::write ($ panel . '/public/img/icons.svg ' , '<svg></svg> ' );
34+ F::write ($ panel . '/.vite-running ' , '' );
35+
6836 $ this ->app = $ this ->app ->clone ([
37+ 'roots ' => [
38+ 'panel ' => $ panel
39+ ],
6940 'options ' => [
7041 'panel ' => [
7142 'dev ' => true
7243 ]
7344 ]
7445 ]);
7546
76- touch (static ::VITE_RUNNING_PATH );
77-
78- $ panel = $ this ->app ->panel ();
79- $ path = Str::after (Url::path ($ panel ->assets ()->icons ()), 'panel/ ' );
80-
81- // the modification time in the dev URL must resolve to the same route
82- $ response = $ panel ->router ()->call ($ path );
83-
84- $ this ->assertSame (200 , $ response ->code ());
85- $ this ->assertStringContainsString ('id="icon-accessibility" ' , $ response ->body ());
47+ $ router = new Router ($ this ->app ->panel ());
48+ $ response = $ router ->icons ();
8649
87- // the sprite must not be cached while it is still being edited
50+ $ this -> assertSame ( ' image/svg+xml ' , $ response -> type ());
8851 $ this ->assertSame ('no-store ' , $ response ->header ('Cache-Control ' ));
52+ $ this ->assertStringContainsString ('<svg ' , $ response ->body ());
8953 }
9054
9155 public function testResponse (): void
@@ -147,7 +111,6 @@ public function testRoutes(): void
147111 $ routes = $ router ->routes ($ areas );
148112
149113 $ this ->assertSame ('assets/(:any)/icons.svg ' , $ routes [0 ]['pattern ' ]);
150- $ this ->assertFalse ($ routes [0 ]['auth ' ]);
151114 $ this ->assertSame ('browser ' , $ routes [1 ]['pattern ' ]);
152115 $ this ->assertSame (['/ ' , 'installation ' , 'login ' ], $ routes [2 ]['pattern ' ]);
153116 $ this ->assertSame ('(:all) ' , $ routes [3 ]['pattern ' ]);
0 commit comments