From 27440dda0afaa11dbc6a528488157f6fe7299572 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 30 Jul 2018 06:23:11 +0530 Subject: [PATCH 1/4] Add test case for delete term meta module Fix #350 --- .../Modules/DeleteTermMetaModuleTest.php | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php diff --git a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php new file mode 100644 index 000000000..ad00b8dab --- /dev/null +++ b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php @@ -0,0 +1,89 @@ +module = new DeleteTermMetaModule(); + } + + /** + * Add to test delete default taxonomy term meta with equal value. + */ + public function test_that_delete_default_taxonomy_term_meta_with_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 ); + + // call our method. + $delete_options = array( + 'term' => $term, + '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, count( $meta_deleted ) ); + } + + /** + * Add to test delete default taxonomy term meta with not equal value. + */ + public function test_that_delete_default_taxonomy_term_meta_with_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 ); + + // call our method. + $delete_options = array( + 'term' => $term, + '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, count( $meta_deleted ) ); + } + + +} From 0a272a894eaf2b94298d883ccad7f7f6a22247c0 Mon Sep 17 00:00:00 2001 From: Rajan Date: Tue, 31 Jul 2018 06:07:07 +0530 Subject: [PATCH 2/4] Add test cases for delete term custom taxonomies Fix #350 --- .../Modules/DeleteTermMetaModuleTest.php | 68 +++++++++++++++++-- 1 file changed, 64 insertions(+), 4 deletions(-) diff --git a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php index ad00b8dab..9db3b9d9a 100644 --- a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php +++ b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php @@ -45,7 +45,7 @@ public function test_that_delete_default_taxonomy_term_meta_with_equal_value() { // call our method. $delete_options = array( - 'term' => $term, + 'term' => $term_array['term_id'], 'term_meta' => $meta_key, 'term_meta_value' => $meta_value, 'term_meta_option' => 'equal', @@ -54,7 +54,7 @@ public function test_that_delete_default_taxonomy_term_meta_with_equal_value() { $meta_deleted = $this->module->delete( $delete_options ); // Assert that post meta deleted. - $this->assertEquals( 1, count( $meta_deleted ) ); + $this->assertEquals( 1, $meta_deleted ); } /** @@ -73,7 +73,7 @@ public function test_that_delete_default_taxonomy_term_meta_with_not_equal_value // call our method. $delete_options = array( - 'term' => $term, + 'term' => $term_array['term_id'], 'term_meta' => $meta_key, 'term_meta_value' => 'Unknown', 'term_meta_option' => 'not_equal', @@ -82,7 +82,67 @@ public function test_that_delete_default_taxonomy_term_meta_with_not_equal_value $meta_deleted = $this->module->delete( $delete_options ); // Assert that post meta deleted. - $this->assertEquals( 1, count( $meta_deleted ) ); + $this->assertEquals( 1, $meta_deleted ); + } + + /** + * Add to test delete custom taxonomy term meta with equal value. + */ + public function test_that_delete_custom_taxonomy_term_meta_with_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 ); + + // 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 ); + } + + /** + * Add to test delete custom taxonomy term meta with not equal value. + */ + public function test_that_delete_custom_taxonomy_term_meta_with_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 ); + + // 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 ); } From 92ce4da2f5e2e5aff03763309c65ded384cb0990 Mon Sep 17 00:00:00 2001 From: Rajan Date: Sun, 12 Aug 2018 05:45:35 +0530 Subject: [PATCH 3/4] Update function names Add explicit checks Fix #350 --- .../Modules/DeleteTermMetaModuleTest.php | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php index 9db3b9d9a..fb8791722 100644 --- a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php +++ b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php @@ -32,7 +32,7 @@ public function setUp() { /** * Add to test delete default taxonomy term meta with equal value. */ - public function test_that_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'; @@ -43,6 +43,8 @@ public function test_that_delete_default_taxonomy_term_meta_with_equal_value() { 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'], @@ -55,12 +57,17 @@ public function test_that_delete_default_taxonomy_term_meta_with_equal_value() { // 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 default taxonomy term meta with not equal value. */ - public function test_that_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'; @@ -71,6 +78,8 @@ public function test_that_delete_default_taxonomy_term_meta_with_not_equal_value 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'], @@ -83,12 +92,16 @@ public function test_that_delete_default_taxonomy_term_meta_with_not_equal_value // 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_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'; @@ -101,6 +114,8 @@ public function test_that_delete_custom_taxonomy_term_meta_with_equal_value() { 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'], @@ -113,12 +128,16 @@ public function test_that_delete_custom_taxonomy_term_meta_with_equal_value() { // 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_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'; @@ -131,6 +150,8 @@ public function test_that_delete_custom_taxonomy_term_meta_with_not_equal_value( 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'], @@ -143,6 +164,10 @@ public function test_that_delete_custom_taxonomy_term_meta_with_not_equal_value( // Assert that post meta deleted. $this->assertEquals( 1, $meta_deleted ); + + $meta = get_term_meta( $term_array['term_id'], 'another' ); + + $this->assertEquals( 1, count( $meta ) ); } From 8ee9283d2d92b5569d5c7e5f113f4711c3dbd5b7 Mon Sep 17 00:00:00 2001 From: Rajan Date: Mon, 13 Aug 2018 05:33:01 +0530 Subject: [PATCH 4/4] Update explicit test case with variable Fix #350 --- .../Modules/DeleteTermMetaModuleTest.php | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php index fb8791722..930b4949a 100644 --- a/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php +++ b/tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php @@ -34,16 +34,18 @@ public function setUp() { */ 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 = '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', 'Another' ); + add_term_meta( $term_array['term_id'], $another_meta_key, $another_meta_value ); // call our method. $delete_options = array( @@ -58,7 +60,7 @@ public function test_that_term_meta_can_be_deleted_with_default_taxonomy_in_equa // Assert that post meta deleted. $this->assertEquals( 1, $meta_deleted ); - $meta = get_term_meta( $term_array['term_id'], 'another' ); + $meta = get_term_meta( $term_array['term_id'], $another_meta_key ); $this->assertEquals( 1, count( $meta ) ); @@ -69,16 +71,18 @@ public function test_that_term_meta_can_be_deleted_with_default_taxonomy_in_equa */ 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 = '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', 'Another' ); + add_term_meta( $term_array['term_id'], $another_meta_key, $another_meta_value ); // call our method. $delete_options = array( @@ -93,7 +97,7 @@ public function test_that_term_meta_can_be_deleted_with_default_taxonomy_in_not_ // Assert that post meta deleted. $this->assertEquals( 1, $meta_deleted ); - $meta = get_term_meta( $term_array['term_id'], 'another' ); + $meta = get_term_meta( $term_array['term_id'], $another_meta_key ); $this->assertEquals( 1, count( $meta ) ); } @@ -103,10 +107,12 @@ public function test_that_term_meta_can_be_deleted_with_default_taxonomy_in_not_ */ 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'; + $term = 'Apple'; + $taxonomy = 'fruit'; + $meta_key = 'grade'; + $meta_value = 'A1'; + $another_meta_key = 'another'; + $another_meta_value = 'Another'; register_taxonomy( $taxonomy, 'post' ); @@ -114,7 +120,7 @@ public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_equal add_term_meta( $term_array['term_id'], $meta_key, $meta_value ); - add_term_meta( $term_array['term_id'], 'another', 'Another' ); + add_term_meta( $term_array['term_id'], $another_meta_key, $another_meta_value ); // call our method. $delete_options = array( @@ -129,7 +135,7 @@ public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_equal // Assert that post meta deleted. $this->assertEquals( 1, $meta_deleted ); - $meta = get_term_meta( $term_array['term_id'], 'another' ); + $meta = get_term_meta( $term_array['term_id'], $another_meta_key ); $this->assertEquals( 1, count( $meta ) ); } @@ -139,10 +145,12 @@ public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_equal */ 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'; + $term = 'Apple'; + $taxonomy = 'fruit'; + $meta_key = 'grade'; + $meta_value = 'A1'; + $another_meta_key = 'another'; + $another_meta_value = 'Another'; register_taxonomy( $taxonomy, 'post' ); @@ -150,7 +158,7 @@ public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_not_e add_term_meta( $term_array['term_id'], $meta_key, $meta_value ); - add_term_meta( $term_array['term_id'], 'another', 'Another' ); + add_term_meta( $term_array['term_id'], $another_meta_key, $another_meta_value ); // call our method. $delete_options = array( @@ -165,7 +173,7 @@ public function test_that_term_meta_can_be_deleted_with_custom_taxonomy_in_not_e // Assert that post meta deleted. $this->assertEquals( 1, $meta_deleted ); - $meta = get_term_meta( $term_array['term_id'], 'another' ); + $meta = get_term_meta( $term_array['term_id'], $another_meta_key ); $this->assertEquals( 1, count( $meta ) ); }