diff --git a/.wp-env.tests.json b/.wp-env.tests.json index 08c195a..8a4b285 100644 --- a/.wp-env.tests.json +++ b/.wp-env.tests.json @@ -4,9 +4,6 @@ "plugins": [ "." ], - "themes": [ - "https://downloads.wordpress.org/theme/twentytwentytwo.zip" - ], "testsEnvironment": false, "config": { "WP_DEBUG": true diff --git a/bin/scaffold.config.js b/bin/scaffold.config.js index 846bb3f..d25277c 100644 --- a/bin/scaffold.config.js +++ b/bin/scaffold.config.js @@ -167,8 +167,15 @@ module.exports = { marker: 'wp:example', groups: [ // Content modeling. + // The example taxonomies attach to the example post types, so removing + // post types also strips that link from the kept taxonomies. capability( 'post-types', 'Post Types', 'Content', { module: 'PostTypes', + strip: [ + 'inc/Modules/Taxonomies/ExampleTaxonomy.php', + 'inc/Modules/Taxonomies/ExampleTaxonomyTwo.php', + 'tests/php/TaxonomiesTest.php', + ], } ), capability( 'taxonomies', 'Taxonomies', 'Content', { module: 'Taxonomies', diff --git a/docs/features.md b/docs/features.md index aa220ff..242388c 100644 --- a/docs/features.md +++ b/docs/features.md @@ -30,7 +30,7 @@ Every set is kept by default. Removing a set at init deletes its module, classes | Init key | Source | What it demonstrates | How to see it | | --- | --- | --- | --- | | `post-types` | `Modules/PostTypes/ExamplePostType.php`, `ExamplePostTypeTwo.php` | `AbstractPostType`: slug, labels, menu icon | Admin menu **Post Type Labels**; `wp post-type list` includes `post-type-slug`. | -| `taxonomies` | `Modules/Taxonomies/ExampleTaxonomy.php`, `ExampleTaxonomyTwo.php` | `AbstractTaxonomy` attached to the example post types via `get_object_types()` | `wp taxonomy list` includes `taxonomy-slug`; it appears on the example post type's editor. | +| `taxonomies` | `Modules/Taxonomies/ExampleTaxonomy.php`, `ExampleTaxonomyTwo.php` | `AbstractTaxonomy` attached to the example post types via `get_object_types()`; removing `post-types` drops that link | `wp taxonomy list` includes `taxonomy-slug`; it appears on the example post type's editor. | | `blocks` | `Modules/Blocks/ExampleDynamicBlock.php`, `src/blocks/example-block*`, `templates/block-templates/example-block-dynamic.php` | A static block, a dynamic block (`AbstractBlock` rendering a template) and an Interactivity API block (`render.php` + `view.js`) | After `npm run build:dev`, insert **Example Block**, **Example Dynamic Block** or **Example Block Interactive** in the editor. | | `shortcodes` | `Modules/Shortcodes/ExampleShortcode.php` | `AbstractShortcode` with default attributes, sanitized input and escaped output | Add `[acme_content_example title="Hello" count="3"]` to a post. | | `rest` | `Modules/REST/ExampleRESTController.php` | `AbstractRESTController` with a real `permission_callback` (`manage_options`) | `GET /wp-json/acme-content-features/v1/examples` as an administrator (see below). | diff --git a/docs/internal/maintenance.md b/docs/internal/maintenance.md index afa5ae1..ff5cf8f 100644 --- a/docs/internal/maintenance.md +++ b/docs/internal/maintenance.md @@ -38,11 +38,13 @@ Modules\Cron::class, // wp:example:cron:end ``` -On removal the engine deletes the region; on keep it deletes only the two marker lines. Current marked files are `inc/Main.php` (every set), `inc/Core/Assets.php` (`blocks`: the `STATIC_BLOCKS` entries) and `inc/Core/PluginSetup.php` (`cron`: the `use` import and the unschedule call). CI workflows use `wp:ci:`. +On removal the engine deletes the region; on keep it deletes only the two marker lines. Current marked files are `inc/Main.php` (every set), `inc/Core/Assets.php` (`blocks`: the `STATIC_BLOCKS` entries), `inc/Core/PluginSetup.php` (`cron`: the `use` import and the unschedule call), and the example taxonomies and their test (`post-types`: the link to the example post types). CI workflows use `wp:ci:`. Rules that keep init working for every downstream project: - Keep marker pairs balanced and on their own lines. A broken pair breaks removal for everyone. +- End new markers with a full stop (`// wp:example:.`) so PHPCS accepts them. Init still recognises them. +- Inside an array, keep one comment line outside the markers, so the array still passes PHPCS when init empties it. - A capability's footprint must be complete: module file, class folder, test file, and every coupled region. Anything left behind references deleted classes. - Markers are consumed by the first run, so removal is one-shot by design. diff --git a/inc/Modules/Taxonomies/ExampleTaxonomy.php b/inc/Modules/Taxonomies/ExampleTaxonomy.php index 783e972..c4f1723 100644 --- a/inc/Modules/Taxonomies/ExampleTaxonomy.php +++ b/inc/Modules/Taxonomies/ExampleTaxonomy.php @@ -9,7 +9,9 @@ namespace Project_Name\Features\Modules\Taxonomies; +// wp:example:post-types. use Project_Name\Features\Modules\PostTypes\ExamplePostType; +// wp:example:post-types:end. use rtCamp\WPPrimitives\Contracts\Abstracts\AbstractTaxonomy; /** @@ -28,7 +30,12 @@ public static function get_slug(): string { * {@inheritDoc} */ public static function get_object_types(): array { - return [ ExamplePostType::get_slug() ]; + return [ + // Post types this taxonomy attaches to. + // wp:example:post-types. + ExamplePostType::get_slug(), + // wp:example:post-types:end. + ]; } /** diff --git a/inc/Modules/Taxonomies/ExampleTaxonomyTwo.php b/inc/Modules/Taxonomies/ExampleTaxonomyTwo.php index d7feca4..afe0759 100644 --- a/inc/Modules/Taxonomies/ExampleTaxonomyTwo.php +++ b/inc/Modules/Taxonomies/ExampleTaxonomyTwo.php @@ -9,7 +9,9 @@ namespace Project_Name\Features\Modules\Taxonomies; +// wp:example:post-types. use Project_Name\Features\Modules\PostTypes\ExamplePostTypeTwo; +// wp:example:post-types:end. use rtCamp\WPPrimitives\Contracts\Abstracts\AbstractTaxonomy; /** @@ -28,7 +30,12 @@ public static function get_slug(): string { * {@inheritDoc} */ public static function get_object_types(): array { - return [ ExamplePostTypeTwo::get_slug() ]; + return [ + // Post types this taxonomy attaches to. + // wp:example:post-types. + ExamplePostTypeTwo::get_slug(), + // wp:example:post-types:end. + ]; } /** diff --git a/package.json b/package.json index dc232d3..e5fba42 100644 --- a/package.json +++ b/package.json @@ -100,7 +100,7 @@ "test": "npm-run-all --parallel test:js test:php", "test:js": "wp-scripts test-unit-jest --config=tests/js/jest.config.js --passWithNoTests", "test:js:watch": "npm run test:js -- --watch", - "pretest:php": "wp-env start --config=.wp-env.tests.json && wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'test -f vendor/autoload.php || composer install --no-interaction'", + "pretest:php": "(wp-env run --config=.wp-env.tests.json cli true >/dev/null 2>&1 || wp-env start --config=.wp-env.tests.json) && ([ vendor/autoload.php -nt composer.lock ] || wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- composer install --no-interaction)", "test:php": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- vendor/bin/phpunit -c phpunit.xml.dist", "pretest:php:coverage": "echo \"\\e[1m\\e[32mMake sure you have run npm run wp-env start -- --config=.wp-env.tests.json --xdebug=coverage before using this command\\e[0m\" && wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- sh -c 'test -f vendor/autoload.php || composer install --no-interaction'", "test:php:coverage": "wp-env run --config=.wp-env.tests.json cli --env-cwd=wp-content/plugins/$(basename \"$PWD\") -- vendor/bin/phpunit -c phpunit.xml.dist --coverage-html coverage", diff --git a/tests/php/TaxonomiesTest.php b/tests/php/TaxonomiesTest.php index 8d7b8f6..6d7a1e4 100644 --- a/tests/php/TaxonomiesTest.php +++ b/tests/php/TaxonomiesTest.php @@ -58,10 +58,14 @@ public function test_examples_are_taxonomy_instances(): void { */ public function test_static_accessors_are_accessible(): void { $this->assertSame( 'taxonomy-slug', ExampleTaxonomy::get_slug() ); + // wp:example:post-types. $this->assertSame( [ 'post-type-slug' ], ExampleTaxonomy::get_object_types() ); + // wp:example:post-types:end. $this->assertSame( 'taxonomy-slug-two', ExampleTaxonomyTwo::get_slug() ); + // wp:example:post-types. $this->assertSame( [ 'post-type-slug-two' ], ExampleTaxonomyTwo::get_object_types() ); + // wp:example:post-types:end. } /** @@ -78,7 +82,9 @@ public function test_example_taxonomy_registers(): void { $this->assertTrue( $object->public ); $this->assertTrue( $object->show_in_rest ); $this->assertTrue( $object->hierarchical ); + // wp:example:post-types. $this->assertContains( 'post-type-slug', $object->object_type ); + // wp:example:post-types:end. $this->assertSame( 'Taxonomy Label', $object->labels->singular_name ); $this->assertSame( 'Taxonomy Labels', $object->labels->name ); } @@ -95,7 +101,9 @@ public function test_example_taxonomy_two_registers(): void { $object = get_taxonomy( 'taxonomy-slug-two' ); $this->assertNotFalse( $object ); $this->assertFalse( $object->hierarchical ); + // wp:example:post-types. $this->assertContains( 'post-type-slug-two', $object->object_type ); + // wp:example:post-types:end. $this->assertSame( 'Taxonomy Two Label', $object->labels->singular_name ); $this->assertSame( 'Taxonomy Two Labels', $object->labels->name ); }