11<?php
22
33use CodeIgniter \Config \Services ;
4+ use org \bovigo \vfs \vfsStream ;
45
56class ManifestTest extends \CodeIgniter \Test \CIUnitTestCase
67{
@@ -24,17 +25,71 @@ public function setUp(): void
2425
2526 // Create the service
2627 $ this ->manifests = new \Tatter \Assets \Libraries \Manifests ($ this ->config );
28+
29+ // Start the virtual filesystem
30+ $ this ->root = vfsStream::setup ();
31+ }
32+
33+ public function tearDown (): void
34+ {
35+ parent ::tearDown ();
36+ $ this ->root = null ;
2737 }
2838
2939 public function testLocate ()
3040 {
3141 $ expected = [
32- SUPPORTPATH . 'Manifests/Widgets.json ' ,
33- SUPPORTPATH . 'Manifests/frontend.json ' ,
34- SUPPORTPATH . 'Manifests/LawyerPack.json ' ,
42+ MODULESUPPORTPATH . 'Manifests/Widgets.json ' ,
43+ MODULESUPPORTPATH . 'Manifests/frontend.json ' ,
44+ MODULESUPPORTPATH . 'Manifests/LawyerPack.json ' ,
3545 ];
3646 $ paths = $ this ->manifests ->locate ();
3747
3848 $ this ->assertEquals ($ expected , $ paths );
3949 }
50+
51+ public function testManifestFromFile ()
52+ {
53+ $ method = $ this ->getPrivateMethodInvoker ($ this ->manifests , 'manifestFromFile ' );
54+ $ path = SUPPORTPATH . 'Manifests/Widgets.json ' ;
55+
56+ $ manifest = $ method ($ path );
57+
58+ $ expected = (object )[
59+ 'source ' => 'vendor/WidgetModule/dist ' ,
60+ 'destination ' => 'vendor/widgets ' ,
61+ 'resources ' => [
62+ 0 => (object )[
63+ 'source ' => 'widget_style.css ' ,
64+ 'destination ' => 'vendor/widgets/css ' ,
65+ ],
66+ 1 => (object )[
67+ 'source ' => 'notAsset.json ' ,
68+ ],
69+ ]
70+ ];
71+
72+ $ this ->assertEquals ($ expected , $ manifest );
73+ }
74+
75+ public function testAddIndexToDirectory ()
76+ {
77+ $ method = $ this ->getPrivateMethodInvoker ($ this ->manifests , 'addIndexToDirectory ' );
78+
79+ $ result = $ method ($ this ->root ->url () . '/ ' );
80+ $ this ->assertTrue ($ result );
81+
82+ $ this ->assertTrue ($ this ->root ->hasChild ('index.html ' ));
83+ }
84+ /*
85+ public function testSecureDirectory()
86+ {
87+ $method = $this->getPrivateMethodInvoker($this->manifests, 'addIndexToDirectory');
88+
89+ $result = $method($this->root->url() . '/assets/');
90+ $this->assertTrue($result);
91+
92+ $this->assertTrue($this->root->hasChild('index.html'));
93+ $this->assertTrue($this->root->hasChild('assets/index.html'));
94+ */
4095}
0 commit comments