Skip to content

Commit bd1828e

Browse files
committed
Fix supportpath; Add manifests tests
1 parent ee6ccc3 commit bd1828e

File tree

5 files changed

+68
-12
lines changed

5 files changed

+68
-12
lines changed

src/Libraries/Manifests.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ protected function manifestFromFile($path): ?object
111111
}
112112

113113
// Verify necessary fields
114-
foreach (['source', 'destination', 'paths'] as $field)
114+
foreach (['source', 'destination', 'resources'] as $field)
115115
{
116116
if (empty($manifest->{$field}))
117117
{
@@ -195,15 +195,15 @@ protected function addIndexToDirectory($directory): bool
195195
{
196196
$path = $directory . 'index.html';
197197
$file = new File($path);
198-
198+
199199
// Check for existing file
200200
if ($file->isFile())
201201
{
202202
return true;
203203
}
204204

205205
// Directory should be writable but just in case...
206-
if (! $file->isWritable)
206+
if (! $file->isWritable())
207207
{
208208
$error = lang('Manifests.directoryNotWritable', [$directory]);
209209
log_message('warning', $error);

tests/_support/AssetsTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function setUp(): void
1818

1919
$this->config = new \Tatter\Assets\Config\Assets;
2020
$this->config->silent = false;
21-
$this->config->fileBase = SUPPORTPATH . 'assets/';
21+
$this->config->fileBase = MODULESUPPORTPATH . 'assets/';
2222

2323
// Create the service
2424
$this->assets = new \Tatter\Assets\Libraries\Assets($this->config);

tests/_support/bootstrap.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,13 @@
1919
define('FCPATH', realpath(ROOTPATH . 'public') . DIRECTORY_SEPARATOR);
2020
define('SYSTEMPATH', realpath($paths->systemDirectory) . DIRECTORY_SEPARATOR);
2121
define('WRITEPATH', realpath($paths->writableDirectory) . DIRECTORY_SEPARATOR);
22+
define('SUPPORTPATH', realpath(ROOTPATH . 'tests/_support') . DIRECTORY_SEPARATOR);
2223

2324
// Define necessary module test path constants
24-
define('SUPPORTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
25-
define('TESTPATH', realpath(SUPPORTPATH . '../') . DIRECTORY_SEPARATOR);
26-
define('MODULEPATH', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
27-
define('COMPOSER_PATH', MODULEPATH . 'vendor/autoload.php');
25+
define('MODULESUPPORTPATH', realpath(__DIR__) . DIRECTORY_SEPARATOR);
26+
define('TESTPATH', realpath(MODULESUPPORTPATH . '../') . DIRECTORY_SEPARATOR);
27+
define('MODULEPATH', realpath(__DIR__ . '/../../') . DIRECTORY_SEPARATOR);
28+
define('COMPOSER_PATH', MODULEPATH . 'vendor/autoload.php');
2829

2930
// Set environment values that would otherwise stop the framework from functioning during tests.
3031
if (! isset($_SERVER['app.baseURL']))

tests/assets/ConfigHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function setUp(): void
1818

1919
$this->config = new \Tatter\Assets\Config\Assets;
2020
$this->config->silent = false;
21-
$this->config->fileBase = SUPPORTPATH . 'assets/';
21+
$this->config->fileBase = MODULESUPPORTPATH . 'assets/';
2222

2323
// Add mock route paths
2424
$this->config->routes = [

tests/manifests/ManifestTest.php

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
use CodeIgniter\Config\Services;
4+
use org\bovigo\vfs\vfsStream;
45

56
class 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

Comments
 (0)