Note: This seems like it's a duplicate of #61 but is just the sole code to be merged from develop->master, so is being treated as its own PR. — @ampersarnie
Description
Fixes #47 - Adds functionality to use a seeder clean-up routine in tests and the CLI. This allows for an optional method to be added to seeders as clean() - this should be used for any clean/tidy routines to remove any data created by the a seeder. I've also added a wp-cypress seed command to shorten the manual usage which also takes advantage of the clean routines (See usage examples below).
describe("Categories.", () => {
before(() => {
cy.cleanThenSeed("CategoriesSeeder"); // Run the cleaner then seed.
});
it("I can add a new category.", () => {
cy.visitAdmin();
cy.visit("/wp-admin/edit-tags.php?taxonomy=category");
// ...
});
after(() => {
cy.seedClean("CategoriesSeeder"); // Only clean, no seeding.
});
});
Seeder
<?php
use WP_Cypress\Seeder\Seeder;
class CategoriesSeeder extends Seeder {
const CATEGORIES = [
'Test',
'New Test',
];
public function run() {
foreach( self::CATEGORIES as $category ) {
wp_insert_term( $category, 'category' );
}
}
public function clean() {
foreach( self::CATEGORIES as $category ) {
$term = get_term_by( 'name', $category, 'category' );
wp_delete_term( $term->term_id, 'category' );
}
}
}
Change Log
Adds seedClean(<seeder>) to cy methods.
Adds cleanThenSeed(<seeder>) to cy methods.
Adds wp-cypress seed <seeder> [--clean] [--clean-first] command as a shortcut to wp-cypress wp "<command>"
Types of changes (if applicable):
[x] Bug fix (non-breaking change which fixes an issue).
[ ] New feature (non-breaking change which adds functionality).
[ ] Breaking change (fix or feature that would cause existing functionality to not work as expected).
Note: This seems like it's a duplicate of #61 but is just the sole code to be merged from develop->master, so is being treated as its own PR. — @ampersarnie
Description
Fixes #47 - Adds functionality to use a seeder clean-up routine in tests and the CLI. This allows for an optional method to be added to seeders as
clean()
- this should be used for any clean/tidy routines to remove any data created by the a seeder. I've also added awp-cypress seed
command to shorten the manual usage which also takes advantage of the clean routines (See usage examples below).Usage Examples
Command
Spec
Seeder
Change Log
seedClean(<seeder>)
tocy
methods.cleanThenSeed(<seeder>)
tocy
methods.wp-cypress seed <seeder> [--clean] [--clean-first]
command as a shortcut towp-cypress wp "<command>"
Types of changes (if applicable):
Checklist (if applicable):