-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add test case for delete term meta module #453
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
<?php | ||
|
||
namespace BulkWP\BulkDelete\Core\Metas\Modules; | ||
|
||
use BulkWP\Tests\WPCore\WPCoreUnitTestCase; | ||
|
||
/** | ||
* Test Delete Term Meta Module. | ||
* | ||
* Tests \BulkWP\BulkDelete\Core\Metas\Modules\DeleteTermMetaModule | ||
* | ||
* @since 6.0.0 | ||
*/ | ||
class DeleteTermMetaModuleTest extends WPCoreUnitTestCase { | ||
|
||
/** | ||
* The module that is getting tested. | ||
* | ||
* @var \BulkWP\BulkDelete\Core\Metas\Modules\DeleteTermMetaModule | ||
*/ | ||
protected $module; | ||
|
||
/** | ||
* Setup the Module. | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
|
||
$this->module = new DeleteTermMetaModule(); | ||
} | ||
|
||
/** | ||
* Add to test delete default taxonomy term meta with equal value. | ||
*/ | ||
public function test_that_term_meta_can_be_deleted_with_default_taxonomy_in_equal_value() { | ||
|
||
$term = 'Apple'; | ||
$taxonomy = 'category'; | ||
$meta_key = 'grade'; | ||
$meta_value = 'A1'; | ||
|
||
$term_array = wp_insert_term( $term, $taxonomy ); | ||
|
||
add_term_meta( $term_array['term_id'], $meta_key, $meta_value ); | ||
|
||
add_term_meta( $term_array['term_id'], 'another', 'Another' ); | ||
|
||
// call our method. | ||
$delete_options = array( | ||
'term' => $term_array['term_id'], | ||
'term_meta' => $meta_key, | ||
'term_meta_value' => $meta_value, | ||
'term_meta_option' => 'equal', | ||
); | ||
|
||
$meta_deleted = $this->module->delete( $delete_options ); | ||
|
||
// Assert that post meta deleted. | ||
$this->assertEquals( 1, $meta_deleted ); | ||
|
||
$meta = get_term_meta( $term_array['term_id'], 'another' ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Make sure you store the value in a variable before accessing it. This problem is happening in all test cases. Fix it in all places. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
||
$this->assertEquals( 1, count( $meta ) ); | ||
|
||
} | ||
|
||
/** | ||
* Add to test delete default taxonomy term meta with not equal value. | ||
*/ | ||
public function test_that_term_meta_can_be_deleted_with_default_taxonomy_in_not_equal_value() { | ||
|
||
$term = 'Apple'; | ||
$taxonomy = 'category'; | ||
$meta_key = 'grade'; | ||
$meta_value = 'A1'; | ||
|
||
$term_array = wp_insert_term( $term, $taxonomy ); | ||
|
||
add_term_meta( $term_array['term_id'], $meta_key, $meta_value ); | ||
|
||
add_term_meta( $term_array['term_id'], 'another', 'Another' ); | ||
|
||
// call our method. | ||
$delete_options = array( | ||
'term' => $term_array['term_id'], | ||
'term_meta' => $meta_key, | ||
'term_meta_value' => 'Unknown', | ||
'term_meta_option' => 'not_equal', | ||
); | ||
|
||
$meta_deleted = $this->module->delete( $delete_options ); | ||
|
||
// Assert that post meta deleted. | ||
$this->assertEquals( 1, $meta_deleted ); | ||
|
||
$meta = get_term_meta( $term_array['term_id'], 'another' ); | ||
|
||
$this->assertEquals( 1, count( $meta ) ); | ||
} | ||
|
||
/** | ||
* Add to test delete custom taxonomy term meta with equal value. | ||
*/ | ||
public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_equal_value() { | ||
|
||
$term = 'Apple'; | ||
$taxonomy = 'fruit'; | ||
$meta_key = 'grade'; | ||
$meta_value = 'A1'; | ||
|
||
register_taxonomy( $taxonomy, 'post' ); | ||
|
||
$term_array = wp_insert_term( $term, $taxonomy ); | ||
|
||
add_term_meta( $term_array['term_id'], $meta_key, $meta_value ); | ||
|
||
add_term_meta( $term_array['term_id'], 'another', 'Another' ); | ||
|
||
// call our method. | ||
$delete_options = array( | ||
'term' => $term_array['term_id'], | ||
'term_meta' => $meta_key, | ||
'term_meta_value' => $meta_value, | ||
'term_meta_option' => 'equal', | ||
); | ||
|
||
$meta_deleted = $this->module->delete( $delete_options ); | ||
|
||
// Assert that post meta deleted. | ||
$this->assertEquals( 1, $meta_deleted ); | ||
|
||
$meta = get_term_meta( $term_array['term_id'], 'another' ); | ||
|
||
$this->assertEquals( 1, count( $meta ) ); | ||
} | ||
|
||
/** | ||
* Add to test delete custom taxonomy term meta with not equal value. | ||
*/ | ||
public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_not_equal_value() { | ||
|
||
$term = 'Apple'; | ||
$taxonomy = 'fruit'; | ||
$meta_key = 'grade'; | ||
$meta_value = 'A1'; | ||
|
||
register_taxonomy( $taxonomy, 'post' ); | ||
|
||
$term_array = wp_insert_term( $term, $taxonomy ); | ||
|
||
add_term_meta( $term_array['term_id'], $meta_key, $meta_value ); | ||
|
||
add_term_meta( $term_array['term_id'], 'another', 'Another' ); | ||
|
||
// call our method. | ||
$delete_options = array( | ||
'term' => $term_array['term_id'], | ||
'term_meta' => $meta_key, | ||
'term_meta_value' => 'Unknown', | ||
'term_meta_option' => 'not_equal', | ||
); | ||
|
||
$meta_deleted = $this->module->delete( $delete_options ); | ||
|
||
// Assert that post meta deleted. | ||
$this->assertEquals( 1, $meta_deleted ); | ||
|
||
$meta = get_term_meta( $term_array['term_id'], 'another' ); | ||
|
||
$this->assertEquals( 1, count( $meta ) ); | ||
} | ||
|
||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You also need to add some terms that won't be deleted in the test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed