Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Tests for ACF_Location_Attachment class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Attachment.
*/
class Test_ACF_Location_Attachment extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Test match returns false without screen args.
*/
public function test_match_returns_false_without_screen_args() {
$location = acf_get_location_type( 'attachment' );

$rule = array(
'param' => 'attachment',
'operator' => '==',
'value' => 'image',
);

$this->assertFalse( $location->match( $rule, array(), array() ), 'Should return false without attachment in screen' );
}
}
74 changes: 74 additions & 0 deletions tests/php/includes/locations/test-class-acf-location-block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Tests for ACF_Location_Block class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Block.
*/
class Test_ACF_Location_Block extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Data provider for match tests.
*
* @return array
*/
public function data_provider_match() {
return array(
'matches block from screen' => array(
array( 'block' => 'acf/testimonial' ),
'acf/testimonial',
true,
),
'does not match different block' => array(
array( 'block' => 'acf/hero' ),
'acf/testimonial',
false,
),
'all value matches any block' => array(
array( 'block' => 'acf/custom' ),
'all',
true,
),
'returns false without screen args' => array(
array(),
'acf/testimonial',
false,
),
);
}

/**
* Test match method.
*
* @dataProvider data_provider_match
* @param array $screen Screen args.
* @param string $rule_value Rule value.
* @param bool $expected Expected result.
*/
public function test_match( $screen, $rule_value, $expected ) {
$location = acf_get_location_type( 'block' );

$rule = array(
'param' => 'block',
'operator' => '==',
'value' => $rule_value,
);

$result = $location->match( $rule, $screen, array() );

$this->assertSame( $expected, $result );
}
}
69 changes: 69 additions & 0 deletions tests/php/includes/locations/test-class-acf-location-comment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Tests for ACF_Location_Comment class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Comment.
*/
class Test_ACF_Location_Comment extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Data provider for match tests.
*
* @return array
*/
public function data_provider_match() {
return array(
'matches comment from screen' => array(
array( 'comment' => 'post' ),
'post',
true,
),
'all value matches any comment' => array(
array( 'comment' => 'page' ),
'all',
true,
),
'returns false without screen args' => array(
array(),
'post',
false,
),
);
}

/**
* Test match method.
*
* @dataProvider data_provider_match
* @param array $screen Screen args.
* @param string $rule_value Rule value.
* @param bool $expected Expected result.
*/
public function test_match( $screen, $rule_value, $expected ) {
$location = acf_get_location_type( 'comment' );

$rule = array(
'param' => 'comment',
'operator' => '==',
'value' => $rule_value,
);

$result = $location->match( $rule, $screen, array() );

$this->assertSame( $expected, $result );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Tests for ACF_Location_Current_User_Role class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Current_User_Role.
*/
class Test_ACF_Location_Current_User_Role extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Test location is registered.
*/
public function test_location_is_registered() {
$location = acf_get_location_type( 'current_user_role' );

$this->assertInstanceOf( 'ACF_Location_Current_User_Role', $location );
$this->assertSame( 'current_user_role', $location->name );
}

/**
* Test get_values returns roles.
*/
public function test_get_values_returns_array() {
$location = acf_get_location_type( 'current_user_role' );

$values = $location->get_values( array() );

$this->assertIsArray( $values, 'Should return an array' );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Tests for ACF_Location_Current_User class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Current_User.
*/
class Test_ACF_Location_Current_User extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Test get_values returns expected options.
*/
public function test_get_values() {
$location = acf_get_location_type( 'current_user' );

$values = $location->get_values( array() );

$this->assertIsArray( $values, 'Should return an array' );
$this->assertArrayHasKey( 'logged_in', $values, 'Should have "logged_in" option' );
$this->assertArrayHasKey( 'viewing_front', $values, 'Should have "viewing_front" option' );
$this->assertArrayHasKey( 'viewing_back', $values, 'Should have "viewing_back" option' );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Tests for ACF_Location_Nav_Menu_Item class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Nav_Menu_Item.
*/
class Test_ACF_Location_Nav_Menu_Item extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Test match returns false without screen args.
*/
public function test_match_returns_false_without_screen_args() {
$location = acf_get_location_type( 'nav_menu_item' );

$rule = array(
'param' => 'nav_menu_item',
'operator' => '==',
'value' => 'all',
);

$this->assertFalse( $location->match( $rule, array(), array() ), 'Should return false without nav_menu_item in screen' );
}
}
69 changes: 69 additions & 0 deletions tests/php/includes/locations/test-class-acf-location-nav-menu.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* Tests for ACF_Location_Nav_Menu class.
*
* @package wordpress/secure-custom-fields
*/

use WorDBless\BaseTestCase;

/**
* Tests for ACF_Location_Nav_Menu.
*/
class Test_ACF_Location_Nav_Menu extends BaseTestCase {

/**
* Set up test fixtures.
*/
public function setUp(): void {
parent::setUp();
acf_init();
}

/**
* Data provider for match tests.
*
* @return array
*/
public function data_provider_match() {
return array(
'matches nav_menu ID from screen' => array(
array( 'nav_menu' => 5 ),
5,
true,
),
'all value matches any nav_menu' => array(
array( 'nav_menu' => 99 ),
'all',
true,
),
'returns false without screen args' => array(
array(),
5,
false,
),
);
}

/**
* Test match method.
*
* @dataProvider data_provider_match
* @param array $screen Screen args.
* @param string|int $rule_value Rule value.
* @param bool $expected Expected result.
*/
public function test_match( $screen, $rule_value, $expected ) {
$location = acf_get_location_type( 'nav_menu' );

$rule = array(
'param' => 'nav_menu',
'operator' => '==',
'value' => $rule_value,
);

$result = $location->match( $rule, $screen, array() );

$this->assertSame( $expected, $result );
}
}
Loading
Loading