Skip to content

Commit

Permalink
chore: add pro condition tests for visibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Soare-Robert-Daniel committed Aug 23, 2023
1 parent 9442b1b commit 0901206
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require dirname( dirname( __FILE__ ) ) . '/inc/css/class-css-utility.php';
require dirname( dirname( __FILE__ ) ) . '/inc/plugins/class-block-conditions.php';
require dirname( dirname( __FILE__ ) ) . '/inc/plugins/class-dynamic-content.php';
require dirname( dirname( __FILE__ ) ) . '/plugins/otter-pro/inc/plugins/class-block-conditions.php';

global $current_user;
$current_user = new WP_User( 1 );
Expand Down
113 changes: 110 additions & 3 deletions tests/test-block-conditions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ) );
}
Expand Down Expand Up @@ -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 );
}
}

0 comments on commit 0901206

Please sign in to comment.