-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add pro condition tests for visibility
- Loading branch information
1 parent
9442b1b
commit 0901206
Showing
2 changed files
with
111 additions
and
3 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
|
@@ -40,8 +40,11 @@ class TestBlockConditions extends WP_UnitTestCase | |
*/ | ||
public function set_up() { | ||
parent::set_up(); | ||
$this->block_conditions = new Block_Conditions(); | ||
$this->user_id = wp_create_user( 'test_user_deletion', 'userlogin', '[email protected]' ); | ||
$this->block_conditions = new Block_Conditions(); | ||
$this->otter_pro_blocks_conditions = new \ThemeIsle\OtterPro\Plugins\Block_Conditions(); | ||
$this->user_id = wp_create_user( 'test_user_deletion', 'userlogin', '[email protected]' ); | ||
|
||
$this->block_conditions->init(); | ||
|
||
/** | ||
* Create a test post. | ||
|
@@ -64,6 +67,12 @@ public function set_up() { | |
) | ||
); | ||
|
||
// Add some meta values to the post. | ||
update_post_meta( $this->post_id, 'test_meta', 'test' ); | ||
|
||
// Add some meta to the user. | ||
update_user_meta( $this->user_id, 'test_meta', 'test' ); | ||
|
||
// Set the post as the current post. | ||
$this->go_to( get_permalink( $this->post_id ) ); | ||
} | ||
|
@@ -226,5 +235,103 @@ public function test_post_category_on_invalid() { | |
$this->assertFalse( $result ); | ||
} | ||
|
||
|
||
/** | ||
* Test logged in user meta. | ||
*/ | ||
public function test_logged_in_user_meta() { | ||
wp_set_current_user( $this->user_id ); | ||
|
||
$condition = array( | ||
'type' => 'loggedInUserMeta', | ||
'meta_key' => 'test_meta', | ||
'meta_compare' => 'is_true', | ||
); | ||
|
||
$result = $this->otter_pro_blocks_conditions->evaluate_condition( true, $condition, true ); | ||
|
||
$this->assertTrue( $result ); | ||
} | ||
|
||
/** | ||
* Test logged in user meta. | ||
*/ | ||
public function test_logged_in_user_meta_invalid() { | ||
wp_set_current_user( $this->user_id ); | ||
|
||
$condition = array( | ||
'type' => 'loggedInUserMeta', | ||
'meta_key' => 'test_', | ||
'meta_compare' => 'is_true', | ||
); | ||
|
||
$result = $this->otter_pro_blocks_conditions->evaluate_condition( true, $condition, true ); | ||
|
||
$this->assertFalse( $result ); | ||
} | ||
|
||
/** | ||
* Test post meta. | ||
*/ | ||
public function test_post_meta() { | ||
wp_set_current_user( $this->user_id ); | ||
|
||
$condition = array( | ||
'type' => 'postMeta', | ||
'meta_key' => 'test_meta', | ||
'meta_compare' => 'is_true', | ||
); | ||
|
||
$result = $this->otter_pro_blocks_conditions->evaluate_condition( true, $condition, true ); | ||
|
||
$this->assertTrue( $result ); | ||
} | ||
|
||
/** | ||
* Test post meta. | ||
*/ | ||
public function test_post_meta_invalid() { | ||
wp_set_current_user( $this->user_id ); | ||
|
||
$condition = array( | ||
'type' => 'postMeta', | ||
'meta_key' => 'test_', | ||
'meta_compare' => 'is_true', | ||
); | ||
|
||
$result = $this->otter_pro_blocks_conditions->evaluate_condition( true, $condition, true ); | ||
|
||
$this->assertFalse( $result ); | ||
} | ||
|
||
/** | ||
* Test data range. | ||
*/ | ||
public function test_date_range() { | ||
|
||
$condition = array( | ||
'type' => 'dateRange', | ||
'start_date' => '2020-01-01', | ||
'end_date' => '2030-12-31', | ||
); | ||
|
||
$result = $this->otter_pro_blocks_conditions->evaluate_condition( true, $condition, true ); | ||
|
||
$this->assertTrue( $result ); | ||
} | ||
|
||
/** | ||
* Test data range. | ||
*/ | ||
public function test_date_range_invalid() { | ||
|
||
$condition = array( | ||
'type' => 'dateRange', | ||
'start_date' => '2020-01-01', | ||
'end_date' => '2020-12-31', | ||
); | ||
|
||
$result = $this->otter_pro_blocks_conditions->evaluate_condition( true, $condition, true ); | ||
|
||
$this->assertFalse( $result ); | ||
} | ||
} |