Skip to content

Commit

Permalink
NEW test for constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
carstingaxion committed Sep 30, 2024
1 parent 80a1c51 commit 35a8512
Showing 1 changed file with 29 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,33 @@ class Test_Endpoint extends Base {
* @covers ::__construct
*
* @return void
*/
public function test___construct(): void {
$slug = 'custom-endpoint';
$callback = function () {
return array(
'file_name' => 'endpoint-template.php',
'dir_path' => '/path/to/theme',
);
};
$plugin_default = '/mock/plugin/templates';
$template_default = '/default/template.php';
$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';

// Create a mock for Endpoint.
$endpoint_template = new Endpoint_Template( $slug, $callback, $plugin_default );
$instance = new Endpoint(
$query_var,
$post_type,
$callback,
$types,
$reg_ex,
);

} */
$this->assertSame( $query_var, $instance->query_var, 'Failed to assert that query_var is persisted.' );
$this->assertSame( get_post_type_object( $post_type ), $instance->type_object, 'Failed to assert that type_object is persisted.' );
$this->assertSame( $callback, $instance->validation_callback, 'Failed to assert that validation_callback is persisted.' );
$this->assertSame( $types, $instance->types, 'Failed to assert that endpoint types are persisted.' );
$this->assertSame( $reg_ex, $instance->reg_ex, 'Failed to assert that reg_ex is persisted.' );
$this->assertSame( 'post_type', $instance->object_type, 'Failed to assert that object_type is set by default.' );
}

/**
* Coverage for get_slugs method.
Expand All @@ -52,14 +63,15 @@ public function test___construct(): void {
* @return void
*/
public function test_get_slugs(): void {
// ini_set('display_errors', '1');
// ini_set('display_startup_errors', '1');
// error_reporting(E_ALL);

// // Simulate 'init' hook being fired
// \do_action('init');

$callback = function(){};
$instance = new Endpoint(
'query_var',
'post',
// 'post', // has rewrite=false , why?
'gatherpress_event',
$callback,
array(
new Endpoint_Template( 'endpoint_template_1', $callback ),
Expand All @@ -68,8 +80,6 @@ public function test_get_slugs(): void {
),
'reg_ex',
);
// var_dump($instance->types);

$this->assertSame(
array(
'endpoint_template_1',
Expand All @@ -79,9 +89,6 @@ public function test_get_slugs(): void {
Utility::invoke_hidden_method( $instance, 'get_slugs' ),
'Failed to assert that endpoint slugs match.'
);

// $this->mock->wp()->reset();

}

}

0 comments on commit 35a8512

Please sign in to comment.