-
Notifications
You must be signed in to change notification settings - Fork 7
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
Merged
rajanvijayan
merged 4 commits into
247-fix/delete-term-meta
from
350-fix/delete-term-meta-test
Aug 15, 2018
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
182 changes: 182 additions & 0 deletions
182
tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
<?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'; | ||
$another_meta_key = 'another'; | ||
$another_meta_value = 'Another'; | ||
|
||
$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_meta_key, $another_meta_value ); | ||
|
||
// 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_meta_key ); | ||
|
||
$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'; | ||
$another_meta_key = 'another'; | ||
$another_meta_value = 'Another'; | ||
|
||
$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_meta_key, $another_meta_value ); | ||
|
||
// 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_meta_key ); | ||
|
||
$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'; | ||
$another_meta_key = 'another'; | ||
$another_meta_value = 'Another'; | ||
|
||
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_meta_key, $another_meta_value ); | ||
|
||
// 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_meta_key ); | ||
|
||
$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'; | ||
$another_meta_key = 'another'; | ||
$another_meta_value = 'Another'; | ||
|
||
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_meta_key, $another_meta_value ); | ||
|
||
// 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_meta_key ); | ||
|
||
$this->assertEquals( 1, count( $meta ) ); | ||
} | ||
|
||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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