Skip to content

Commit 2b19a01

Browse files
committed
Test plugin extension logic
1 parent 6890c24 commit 2b19a01

File tree

15 files changed

+89
-15
lines changed

15 files changed

+89
-15
lines changed

classes/PhpBlueprintLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static function loadFromFolder(string $dir): array
1313
$name = basename($path, '.php');
1414
$parentDirectory = basename(dirname($path));
1515
$key = $parentDirectory === 'blueprints' ? $name : $parentDirectory . '/' . $name;
16-
$blueprints[$key] = require $path;
16+
$blueprints[$key] = $path;
1717
}
1818

1919
return $blueprints;

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
},
2020
"autoload": {
2121
"psr-4": {
22-
"PresProg\\MyPlugin\\": "classes/"
22+
"PresProg\\PhpBlueprintLoader\\": "classes/",
23+
"Tests\\PresProg\\PhpBlueprintLoader\\": "tests/"
2324
}
2425
},
2526
"config": {
@@ -29,7 +30,8 @@
2930
"optimize-autoloader": true
3031
},
3132
"extra": {
32-
"installer-name": "php-blueprint-loader"
33+
"installer-name": "php-blueprint-loader",
34+
"kirby-cms-path": false
3335
},
3436
"scripts": {
3537
"analyze": [

index.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use Kirby\Cms\App;
44
use PresProg\PhpBlueprintLoader\PhpBlueprintLoader;
55

6+
@include_once __DIR__ . '/vendor/autoload.php';
7+
68
App::plugin('presprog/php-blueprint-loader', [
79
'hooks' => [
810
'system.loadPlugins:after' => function () {

tests/.gitkeep

Whitespace-only changes.

tests/PhpBlueprintLoaderTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Tests\PresProg\PhpBlueprintLoader;
44

5-
use PHPUnit\Framework\TestCase;
65
use PresProg\PhpBlueprintLoader\PhpBlueprintLoader;
76

87
class PhpBlueprintLoaderTest extends TestCase
@@ -11,14 +10,11 @@ public function testLoadsPhpBlueprintsFromFolder(): void
1110
{
1211
$blueprintDir = __DIR__ . '/fixtures/site/blueprints';
1312

14-
$pageBlueprint = require $blueprintDir . '/pages/php-blueprint.php';
15-
$fileBlueprint = require $blueprintDir . '/files/php-blueprint.php';
16-
1713
$blueprints = PhpBlueprintLoader::loadFromFolder($blueprintDir);
1814

1915
$this->assertEquals([
20-
'pages/php-blueprint' => $pageBlueprint,
21-
'files/php-blueprint' => $fileBlueprint,
16+
'pages/blueprint' => $blueprintDir . '/pages/blueprint.php',
17+
'files/blueprint' => $blueprintDir . '/files/blueprint.php',
2218
], $blueprints);
2319
}
2420
}

tests/PluginTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Tests\PresProg\PhpBlueprintLoader;
4+
5+
use Kirby\Cms\App;
6+
7+
class PluginTest extends TestCase
8+
{
9+
public function testExtendsBlueprintsOnLoad(): void
10+
{
11+
$blueprintDir = __DIR__ . '/temp/site/blueprints';
12+
13+
// Load plugin
14+
require dirname(__DIR__) . '/index.php';
15+
16+
$kirby = new App([
17+
'roots' => [
18+
'index' => self::$tmpDir,
19+
],
20+
]);
21+
22+
$blueprints = $kirby->extensions('blueprints');
23+
24+
$this->assertEquals($blueprints['pages/blueprint'], $blueprintDir . '/pages/blueprint.php');
25+
$this->assertEquals($blueprints['files/blueprint'], $blueprintDir . '/files/blueprint.php');
26+
}
27+
}

tests/TestCase.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Tests\PresProg\PhpBlueprintLoader;
4+
5+
use Kirby\Cms\App;
6+
use Kirby\Filesystem\Dir;
7+
8+
class TestCase extends \PHPUnit\Framework\TestCase
9+
{
10+
protected static string $tmpDir;
11+
12+
public static function setUpBeforeClass(): void
13+
{
14+
self::$tmpDir = __DIR__ . '/temp';
15+
}
16+
17+
protected function setUp(): void
18+
{
19+
// Do not register any error handler
20+
App::$enableWhoops = false;
21+
22+
Dir::copy(__DIR__ . '/fixtures', self::$tmpDir);
23+
}
24+
25+
protected function tearDown(): void
26+
{
27+
Dir::remove(self::$tmpDir);
28+
}
29+
}

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<?php declare(strict_types=1);
22

3-
require __DIR__ . '/../classes/PhpBlueprintLoader.php';
3+
require dirname(__DIR__) . '/vendor/autoload.php';

0 commit comments

Comments
 (0)