Skip to content
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
merged 4 commits into from
Aug 15, 2018
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
174 changes: 174 additions & 0 deletions tests/wp-unit/include/Core/Metas/Modules/DeleteTermMetaModuleTest.php
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 );
Copy link
Owner

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed


// Assert that post meta deleted.
$this->assertEquals( 1, $meta_deleted );

$meta = get_term_meta( $term_array['term_id'], 'another' );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In add_term_meta you are using the value Another and here you are checking for another.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 ) );
}


}