Skip to content

Commit 95df80d

Browse files
authored
Merge pull request #48 from tylerdak/fix/taxonomies-blueprint-parent-edit
Fix crash when editing taxonomy blueprints
2 parents 800c28d + 8703d9a commit 95df80d

File tree

5 files changed

+82
-9
lines changed

5 files changed

+82
-9
lines changed

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
"Tdwesten\\StatamicBuilder\\": "src"
99
}
1010
},
11+
"autoload-dev": {
12+
"psr-4": {
13+
"Tests\\": "tests"
14+
}
15+
},
1116
"extra": {
1217
"statamic": {
1318
"name": "Statamic Builder",

src/Http/Controllers/CollectionBlueprintsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class CollectionBlueprintsController extends StatamicCollectionBlueprintsControl
1212

1313
public function edit($collection, $blueprint)
1414
{
15-
$blueprint = $collection->entryBlueprint($blueprint);
15+
$entryBlueprint = $collection->entryBlueprint($blueprint);
1616

17-
$builderBlueprint = BlueprintRepository::findBlueprint($blueprint->namespace(), $blueprint->handle());
17+
$builderBlueprint = BlueprintRepository::findBlueprint($entryBlueprint->namespace(), $entryBlueprint->handle());
1818

1919
if ($builderBlueprint) {
20-
$blueprintPath = BlueprintRepository::findBlueprintPath($blueprint->namespace(), $blueprint->handle());
20+
$blueprintPath = BlueprintRepository::findBlueprintPath($entryBlueprint->namespace(), $entryBlueprint->handle());
2121

2222
return view('statamic-builder::not-editable', [
2323
'type' => 'Blueprint',

src/Http/Controllers/TaxonomyBlueprintsController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ class TaxonomyBlueprintsController extends StatamicTaxonomyBlueprintsController
99
{
1010
public function edit($taxonomy, $blueprint)
1111
{
12-
$blueprint = $taxonomy->termBlueprint($blueprint);
12+
$termBlueprint = $taxonomy->termBlueprint($blueprint);
1313

14-
$builderBlueprint = BlueprintRepository::findBlueprint($blueprint->namespace(), $blueprint->handle());
14+
$builderBlueprint = BlueprintRepository::findBlueprint($termBlueprint->namespace(), $termBlueprint->handle());
1515

1616
if ($builderBlueprint) {
17-
$blueprintPath = BlueprintRepository::findBlueprintPath($blueprint->namespace(), $blueprint->handle());
17+
$blueprintPath = BlueprintRepository::findBlueprintPath($termBlueprint->namespace(), $termBlueprint->handle());
1818

1919
return view('statamic-builder::not-editable', [
2020
'type' => 'Blueprint',

tests/TestCase.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
namespace Tests;
44

5-
use Orchestra\Testbench\TestCase as Orchestra;
5+
use Statamic\Testing\AddonTestCase;
6+
use Tdwesten\StatamicBuilder\ServiceProvider;
67

7-
abstract class TestCase extends Orchestra
8+
abstract class TestCase extends AddonTestCase
89
{
9-
//
10+
protected string $addonServiceProvider = ServiceProvider::class;
1011
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
use Statamic\Facades\Taxonomy;
4+
use Tdwesten\StatamicBuilder\Http\Controllers\TaxonomyBlueprintsController;
5+
use Tests\TestCase;
6+
7+
pest()->extend(TestCase::class);
8+
9+
const TEST_FILES_DIRECTORY = __DIR__.'/../__fixtures__';
10+
const TAX_DIRECTORY = TEST_FILES_DIRECTORY.'/content/taxonomies';
11+
const TEST_TAX_BLUEPRINTS_DIRECTORY = TEST_FILES_DIRECTORY.'/resources/blueprints/taxonomies/test_tax';
12+
13+
test('taxonomy blueprints can be edited', function (): void {
14+
15+
// Prepare fixtures directory
16+
if (! (is_dir(TEST_FILES_DIRECTORY) && is_dir(TAX_DIRECTORY) && is_dir(TEST_TAX_BLUEPRINTS_DIRECTORY))) {
17+
$created = mkdir(TAX_DIRECTORY, recursive: true)
18+
&& mkdir(TEST_TAX_BLUEPRINTS_DIRECTORY, recursive: true);
19+
20+
if (! $created) {
21+
$this->fail('Could not create test files directory (in '.TEST_FILES_DIRECTORY.')');
22+
}
23+
}
24+
25+
$test_tax_blueprint = <<<'BLUEPRINT'
26+
title: Test_Taxonomy_Blueprint
27+
tabs:
28+
main:
29+
display: Main
30+
sections:
31+
-
32+
fields:
33+
-
34+
handle: title
35+
field:
36+
type: text
37+
required: true
38+
validate:
39+
- required
40+
BLUEPRINT;
41+
42+
$test_tax = <<<'TAXONOMY'
43+
title: Test_Tax
44+
TAXONOMY;
45+
46+
file_put_contents(TAX_DIRECTORY.'/test_tax.yaml', $test_tax);
47+
file_put_contents(TEST_TAX_BLUEPRINTS_DIRECTORY.'/test_tax.yaml', $test_tax_blueprint);
48+
49+
// Create a new controller and attempt to edit the taxonomy blueprint with it
50+
(new TaxonomyBlueprintsController)->edit(Taxonomy::findByHandle('test_tax'), 'test_tax');
51+
})
52+
->throwsNoExceptions()
53+
->after(function () {
54+
$it = new RecursiveDirectoryIterator(TEST_FILES_DIRECTORY, RecursiveDirectoryIterator::SKIP_DOTS);
55+
$files = new RecursiveIteratorIterator(
56+
$it,
57+
RecursiveIteratorIterator::CHILD_FIRST
58+
);
59+
foreach ($files as $file) {
60+
if ($file->isDir()) {
61+
rmdir($file->getPathname());
62+
} else {
63+
unlink($file->getPathname());
64+
}
65+
}
66+
rmdir(TEST_FILES_DIRECTORY);
67+
});

0 commit comments

Comments
 (0)