Skip to content

Commit

Permalink
NEW test for allow_query_vars() method
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Sep 30, 2024
1 parent 0b2d460 commit d0c9618
Showing 1 changed file with 76 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public function test___construct(): void {
new Endpoint_Redirect( 'endpoint_redirect_1', $callback ),
);
$reg_ex = 'reg_ex';

$instance = new Endpoint(
$query_var,
$post_type,
Expand Down Expand Up @@ -67,18 +66,23 @@ public function test_get_slugs(): void {
// ini_set('display_startup_errors', '1');
// error_reporting(E_ALL);

$callback = function(){};
$instance = new Endpoint(
'query_var',
'gatherpress_event',
$query_var = 'query_var';
$post_type = 'gatherpress_event';
$callback = function(){};
$types = array(
new Endpoint_Template( 'endpoint_template_1', $callback ),
new Endpoint_Template( 'endpoint_template_2', $callback ),
new Endpoint_Redirect( 'endpoint_redirect_1', $callback ),
);
$reg_ex = 'reg_ex';
$instance = new Endpoint(
$query_var,
$post_type,
$callback,
array(
new Endpoint_Template( 'endpoint_template_1', $callback ),
new Endpoint_Template( 'endpoint_template_2', $callback ),
new Endpoint_Redirect( 'endpoint_redirect_1', $callback ),
),
'reg_ex',
$types,
$reg_ex,
);

$this->assertSame(
array(
'endpoint_template_1',
Expand All @@ -98,18 +102,23 @@ public function test_get_slugs(): void {
* @return void
*/
public function test_get_rewrite_atts(): void {
$callback = function(){};
$instance = new Endpoint(
'query_var',
'gatherpress_event',
$query_var = 'query_var';
$post_type = 'gatherpress_event';
$callback = function(){};
$types = array(
new Endpoint_Template( 'endpoint_template_1', $callback ),
new Endpoint_Template( 'endpoint_template_2', $callback ),
new Endpoint_Redirect( 'endpoint_redirect_1', $callback ),
);
$reg_ex = 'reg_ex';
$instance = new Endpoint(
$query_var,
$post_type,
$callback,
array(
new Endpoint_Template( 'endpoint_template_1', $callback ),
new Endpoint_Template( 'endpoint_template_2', $callback ),
new Endpoint_Redirect( 'endpoint_redirect_1', $callback ),
),
'reg_ex',
$types,
$reg_ex,
);

$this->assertSame(
array(
'gatherpress_event' => '$matches[1]',
Expand All @@ -119,4 +128,50 @@ public function test_get_rewrite_atts(): void {
'Failed to assert that rewrite attributes match.'
);
}

/**
* Coverage for maybe_flush_rewrite_rules method.
*
* @covers ::maybe_flush_rewrite_rules
*
* @return void
*/
public function test_maybe_flush_rewrite_rules(): void {}

/**
* Coverage for allow_query_vars method.
*
* @covers ::allow_query_vars
*
* @return void
*/
public function test_allow_query_vars(): void {
$query_var = 'query_var';
$post_type = 'gatherpress_event';
$callback = function(){};
$types = array(
new Endpoint_Template( 'endpoint_template_1', $callback ),
new Endpoint_Template( 'endpoint_template_2', $callback ),
new Endpoint_Redirect( 'endpoint_redirect_1', $callback ),
);
$reg_ex = 'reg_ex';
$instance = new Endpoint(
$query_var,
$post_type,
$callback,
$types,
$reg_ex,
);

$this->assertSame(
array(
'apples',
'oranges',
'query_var',
),
$instance->allow_query_vars( array( 'apples', 'oranges' )),
'Failed to assert that merged query variables match.'
);
}

}

0 comments on commit d0c9618

Please sign in to comment.