Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"Tdwesten\\StatamicBuilder\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests"
}
},
"extra": {
"statamic": {
"name": "Statamic Builder",
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/CollectionBlueprintsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ class CollectionBlueprintsController extends StatamicCollectionBlueprintsControl

public function edit($collection, $blueprint)
{
$blueprint = $collection->entryBlueprint($blueprint);
$entryBlueprint = $collection->entryBlueprint($blueprint);

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

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

return view('statamic-builder::not-editable', [
'type' => 'Blueprint',
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Controllers/TaxonomyBlueprintsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ class TaxonomyBlueprintsController extends StatamicTaxonomyBlueprintsController
{
public function edit($taxonomy, $blueprint)
{
$blueprint = $taxonomy->termBlueprint($blueprint);
$termBlueprint = $taxonomy->termBlueprint($blueprint);

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

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

return view('statamic-builder::not-editable', [
'type' => 'Blueprint',
Expand Down
7 changes: 4 additions & 3 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Tests;

use Orchestra\Testbench\TestCase as Orchestra;
use Statamic\Testing\AddonTestCase;
use Tdwesten\StatamicBuilder\ServiceProvider;

abstract class TestCase extends Orchestra
abstract class TestCase extends AddonTestCase
{
//
protected string $addonServiceProvider = ServiceProvider::class;
}
67 changes: 67 additions & 0 deletions tests/Unit/TaxonomyBlueprintTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

use Statamic\Facades\Taxonomy;
use Tdwesten\StatamicBuilder\Http\Controllers\TaxonomyBlueprintsController;
use Tests\TestCase;

pest()->extend(TestCase::class);

const TEST_FILES_DIRECTORY = __DIR__.'/../__fixtures__';
const TAX_DIRECTORY = TEST_FILES_DIRECTORY.'/content/taxonomies';
const TEST_TAX_BLUEPRINTS_DIRECTORY = TEST_FILES_DIRECTORY.'/resources/blueprints/taxonomies/test_tax';

test('taxonomy blueprints can be edited', function (): void {

// Prepare fixtures directory
if (! (is_dir(TEST_FILES_DIRECTORY) && is_dir(TAX_DIRECTORY) && is_dir(TEST_TAX_BLUEPRINTS_DIRECTORY))) {
$created = mkdir(TAX_DIRECTORY, recursive: true)
&& mkdir(TEST_TAX_BLUEPRINTS_DIRECTORY, recursive: true);

if (! $created) {
$this->fail('Could not create test files directory (in '.TEST_FILES_DIRECTORY.')');
}
}

$test_tax_blueprint = <<<'BLUEPRINT'
title: Test_Taxonomy_Blueprint
tabs:
main:
display: Main
sections:
-
fields:
-
handle: title
field:
type: text
required: true
validate:
- required
BLUEPRINT;

$test_tax = <<<'TAXONOMY'
title: Test_Tax
TAXONOMY;

file_put_contents(TAX_DIRECTORY.'/test_tax.yaml', $test_tax);
file_put_contents(TEST_TAX_BLUEPRINTS_DIRECTORY.'/test_tax.yaml', $test_tax_blueprint);

// Create a new controller and attempt to edit the taxonomy blueprint with it
(new TaxonomyBlueprintsController)->edit(Taxonomy::findByHandle('test_tax'), 'test_tax');
})
->throwsNoExceptions()
->after(function () {
$it = new RecursiveDirectoryIterator(TEST_FILES_DIRECTORY, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator(
$it,
RecursiveIteratorIterator::CHILD_FIRST
);
foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getPathname());
} else {
unlink($file->getPathname());
}
}
rmdir(TEST_FILES_DIRECTORY);
});