55use Packaged \Dispatch \Dispatch ;
66use Packaged \Dispatch \ResourceManager ;
77use Packaged \Dispatch \ResourceStore ;
8+ use Packaged \Dispatch \Tests \TestComponents \DemoComponent \DemoComponent ;
89use Packaged \Helpers \Path ;
910use PHPUnit \Framework \TestCase ;
1011
@@ -39,6 +40,28 @@ public function testPublic()
3940 $ this ->assertEquals ([], $ manager ->getMapOptions ());
4041 }
4142
43+ public function testComponent ()
44+ {
45+ Dispatch::bind (new Dispatch (Path::system (__DIR__ , '_root ' )));
46+ $ component = new DemoComponent ();
47+ $ manager = ResourceManager::component ($ component );
48+ $ this ->assertEquals (ResourceManager::MAP_COMPONENT , $ manager ->getMapType ());
49+ $ this ->assertEquals (
50+ [6 , 'Packaged ' , 'Dispatch ' , 'Tests ' , 'TestComponents ' , 'DemoComponent ' , 'DemoComponent ' ],
51+ $ manager ->getMapOptions ()
52+ );
53+ $ this ->assertEquals (
54+ 'c/6/Packaged/Dispatch/Tests/TestComponents/DemoComponent/DemoComponent/a4197ed8/style.css ' ,
55+ $ manager ->getResourceUri ('style.css ' )
56+ );
57+ Dispatch::instance ()->setComponentsNamespace ('\Packaged\Dispatch\Tests\TestComponents ' );
58+ $ manager = ResourceManager::component ($ component );
59+ $ this ->assertEquals (
60+ 'c/3/_/DemoComponent/DemoComponent/a4197ed8/style.css ' ,
61+ $ manager ->getResourceUri ('style.css ' )
62+ );
63+ }
64+
4265 public function testRequireJs ()
4366 {
4467 Dispatch::bind (new Dispatch (Path::system (__DIR__ , '_root ' )));
@@ -49,6 +72,17 @@ public function testRequireJs()
4972 );
5073 }
5174
75+ public function testUniqueRequire ()
76+ {
77+ Dispatch::bind (new Dispatch (Path::system (__DIR__ , '_root ' )));
78+ ResourceManager::resources ()->requireJs ('js/alert.js ' );
79+ $ this ->assertCount (1 , Dispatch::instance ()->store ()->getResources (ResourceStore::TYPE_JS ));
80+ ResourceManager::resources ()->requireJs ('js/alert.js ' );
81+ $ this ->assertCount (1 , Dispatch::instance ()->store ()->getResources (ResourceStore::TYPE_JS ));
82+ ResourceManager::resources ()->requireJs ('js/misc.js ' );
83+ $ this ->assertCount (2 , Dispatch::instance ()->store ()->getResources (ResourceStore::TYPE_JS ));
84+ }
85+
5286 public function testRequireCss ()
5387 {
5488 Dispatch::bind (new Dispatch (Path::system (__DIR__ , '_root ' )));
0 commit comments