Skip to content

Commit

Permalink
Adding test case - 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajinsharwar committed Nov 14, 2023
1 parent 898a96c commit eb2db0c
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions tests/phpunit/includes/testcase-canonical.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,52 +287,59 @@ public static function delete_shared_fixtures() {
*/
public function assertCanonical( $test_url, $expected, $ticket = 0, $expected_doing_it_wrong = array() ) {
$this->expected_doing_it_wrong = array_merge( $this->expected_doing_it_wrong, (array) $expected_doing_it_wrong );

Check failure on line 290 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
$ticket_ref = ( $ticket > 0 ) ? 'Ticket #' . $ticket : '';

Check failure on line 292 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
if ( is_string( $expected ) ) {
$expected = array( 'url' => $expected );
} elseif ( is_array( $expected ) && ! isset( $expected['url'] ) && ! isset( $expected['qv'] ) ) {
$expected = array( 'qv' => $expected );
}

Check failure on line 298 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
if ( ! isset( $expected['url'] ) && ! isset( $expected['qv'] ) ) {
$this->fail( 'No valid expected output was provided' );
}

Check failure on line 302 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
$this->go_to( home_url( $test_url ) );

Check failure on line 304 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
// Does the redirect match what's expected?
$can_url = $this->get_canonical( $test_url );
$parsed_can_url = parse_url( $can_url );

Check failure on line 308 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
// Just test the path and query if present.
if ( isset( $expected['url'] ) ) {
// Check for post type privacy settings.
$post_type_obj = get_post_type_object( get_post_type() );
if ( $post_type_obj && isset( $post_type_obj->publicly_queryable ) && ! $post_type_obj->publicly_queryable ) {
// If the post type is not publicly queryable, ignore the test.
return;
}

Check failure on line 317 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
$this->assertSame( $expected['url'], $parsed_can_url['path'] . ( ! empty( $parsed_can_url['query'] ) ? '?' . $parsed_can_url['query'] : '' ), $ticket_ref );
}

Check failure on line 320 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
// If the test data doesn't include expected query vars, then we're done here.
if ( ! isset( $expected['qv'] ) ) {
return;
}

Check failure on line 325 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
// "make" that the request and check the query is correct.
$this->go_to( $can_url );

Check failure on line 328 in tests/phpunit/includes/testcase-canonical.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Whitespace found at end of line
// Are all query vars accounted for, and correct?
global $wp;

$query_vars = array_diff( $wp->query_vars, $wp->extra_query_vars );
if ( ! empty( $parsed_can_url['query'] ) ) {
parse_str( $parsed_can_url['query'], $_qv );

// $_qv should not contain any elements which are set in $query_vars already
// (i.e. $_GET vars should not be present in the Rewrite).
$this->assertSame( array(), array_intersect( $query_vars, $_qv ), 'Query vars are duplicated from the Rewrite into $_GET; ' . $ticket_ref );

$query_vars = array_merge( $query_vars, $_qv );
}

$this->assertEquals( $expected['qv'], $query_vars );
}

Expand Down

0 comments on commit eb2db0c

Please sign in to comment.