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
1 change: 1 addition & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Thank you for wanting to make FakerPress better for everyone! [We salute you](ht

= 0.9.2 — 15 of July 2026 =

* Fix - "Erase faked data" now deletes generated categories and other terms; `Term::fetch()`/`delete()` were reading the singular `fakerpress.module_flag.term` option while generation wrote the plural `fakerpress.module_flag.terms`, so no terms were ever collected for deletion. [[#228](https://github.com/bordoni/fakerpress/pull/228)]
* Fix - Generate terms in the selected taxonomy again; the Terms endpoint no longer lets the singular `taxonomy` alias's `category` default overwrite the admin form's plural `taxonomies` value, so choosing Tags now creates tags instead of categories. [[#227](https://github.com/bordoni/fakerpress/pull/227)]
* Fix - Stop the `explode(): Passing null to parameter #2` PHP 8.1+ deprecation when generating posts with a sparse payload; the `Post` module now defaults every splittable request value (comment status, author, post types, HTML tags, post parent, image origins) to an empty string before splitting. [[#224](https://github.com/bordoni/fakerpress/pull/224)]
* Fix - Resolve the fatal error on WordPress 7.0 when generating attachments (`Call to undefined function FakerPress\Module\media_handle_sideload()`); WordPress 7.0 preloads `wp-admin/includes/file.php`, so the single `download_url()` guard skipped `media.php`. Each admin include is now guarded by the function it actually provides. [[#221](https://github.com/bordoni/fakerpress/pull/221)]
Expand Down
4 changes: 2 additions & 2 deletions src/FakerPress/Module/Term.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function hook(): void {
* @inheritDoc
*/
public static function fetch( array $args = [] ): array {
return get_option( 'fakerpress.module_flag.term', [] );
return get_option( 'fakerpress.module_flag.' . static::get_slug(), [] );
}

/**
Expand All @@ -54,7 +54,7 @@ public static function delete( $items ) {
}
}

delete_option( 'fakerpress.module_flag.term' );
delete_option( 'fakerpress.module_flag.' . static::get_slug() );

return $deleted;
}
Expand Down
80 changes: 80 additions & 0 deletions tests/wpunit/Module/TermEraseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?php
/**
* Tests for the Term module flag / fetch / delete (erase) cycle.
*
* @since 0.9.2
*
* @package FakerPress\Tests\Module
*/

namespace FakerPress\Tests\Module;

use FakerPress\Module\Term;

/**
* Class TermEraseTest
*
* Regression coverage for issue #219: "Erase faked data" did not delete generated categories,
* because creation flagged terms under the option `fakerpress.module_flag.terms` (plural) while
* fetch()/delete() read and cleared the singular `fakerpress.module_flag.term`.
*
* @since 0.9.2
*/
class TermEraseTest extends \Codeception\TestCase\WPTestCase {

/**
* Create a flagged term through the module, mirroring real generation.
*
* @param string $taxonomy Taxonomy slug.
*
* @return int The created term ID.
*/
private function create_flagged_term( string $taxonomy ): int {
$module = new Term();

return (int) $module->filter_save_response(
null,
[
'name' => 'FP Erase ' . $taxonomy . ' ' . wp_generate_password( 6, false ),
'taxonomy' => $taxonomy,
'description' => 'Generated by FakerPress test.',
'parent_term' => 0,
],
$module
);
}

/**
* fetch() must return the terms that creation flagged (same option key on both sides).
*
* @test
*/
public function it_should_fetch_flagged_terms(): void {
$term_id = $this->create_flagged_term( 'category' );

$flagged = Term::fetch();

$this->assertNotEmpty( $flagged, 'fetch() should return the flagged terms, not an empty array.' );
$this->assertArrayHasKey( 'category', $flagged );
$this->assertContains( $term_id, $flagged['category'] );
}

/**
* delete() must remove the flagged terms and clear the flag option — the full erase path.
*
* @test
*/
public function it_should_delete_flagged_terms_and_clear_the_option(): void {
$category_id = $this->create_flagged_term( 'category' );
$tag_id = $this->create_flagged_term( 'post_tag' );

$items = Term::fetch();
$this->assertNotEmpty( $items );

Term::delete( $items );

$this->assertNull( get_term( $category_id ), 'Generated category should be deleted.' );
$this->assertNull( get_term( $tag_id ), 'Generated tag should be deleted.' );
$this->assertEmpty( Term::fetch(), 'The flag option should be cleared after delete().' );
}
}
Loading