Skip to content

Commit

Permalink
Use stricter testing for PHPUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
keesiemeijer committed Jul 1, 2020
1 parent 1e063cc commit 39274e2
Show file tree
Hide file tree
Showing 16 changed files with 85 additions and 83 deletions.
8 changes: 4 additions & 4 deletions tests/test-admin-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function test_get_settings_defaults() {

$this->delete_settings();

$this->assertEquals( $expected, $settings_obj->get_settings() );
$this->assertSame( $expected, $settings_obj->get_settings() );
}

/**
Expand All @@ -60,7 +60,7 @@ function test_get_settings_in_database() {

update_option( 'custom_post_type_date_archives', $option );

$this->assertEquals( $expected, $settings_obj->get_settings() );
$this->assertSame( $expected, $settings_obj->get_settings() );
}

/**
Expand All @@ -84,7 +84,7 @@ function test_admin_merge_page_settings_add_value() {
);

$merged = $settings_obj->merge_settings( $settings, $new_settings, 'cpt_2' );
$this->assertEquals( $expected, $merged );
$this->assertSame( $expected, $merged );
}

/**
Expand All @@ -107,7 +107,7 @@ function test_admin_merge_page_settings_remove_value() {
);

$merged = $settings_obj->merge_settings( $settings, $new_settings, 'cpt' );
$this->assertEquals( $expected, $merged );
$this->assertSame( $expected, $merged );
}

}
8 changes: 4 additions & 4 deletions tests/test-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function test_admin_page() {
$admin = new CPTDA_Admin();
$admin->cptda_admin_menu();
$expected = admin_url( 'edit.php?post_type=cpt&page=date-archives-cpt' );
$this->assertEquals( $expected, menu_page_url( 'date-archives-cpt', false ) );
$this->assertSame( $expected, menu_page_url( 'date-archives-cpt', false ) );
}

/**
Expand All @@ -47,7 +47,7 @@ function test_admin_get_settings_default() {
'publish_future_posts' => array(),
);

$this->assertEquals( $expected, $admin->get_settings( 'cpt' ) );
$this->assertSame( $expected, $admin->get_settings( 'cpt' ) );
}

/**
Expand All @@ -69,7 +69,7 @@ function test_admin_get_settings_invalid_post_type() {

update_option( 'custom_post_type_date_archives', $option );

$this->assertEquals( $expected, $admin->get_settings( 'cpt' ) );
$this->assertSame( $expected, $admin->get_settings( 'cpt' ) );
}

/**
Expand All @@ -95,6 +95,6 @@ function test_admin_get_settings_when_updating() {
'publish_future_posts' => array(),
);

$this->assertEquals( $expected, $admin->get_settings( 'cpt' ) );
$this->assertSame( $expected, $admin->get_settings( 'cpt' ) );
}
}
14 changes: 7 additions & 7 deletions tests/test-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function test_cptda_get_archives() {

$archive = cptda_get_archives( array( 'post_type' => 'cpt', 'echo' => false ) );

$this->assertEquals( strip_ws( $expected ), strip_ws( $archive ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $archive ) );
}

/**
Expand All @@ -45,14 +45,14 @@ function test_cptda_get_archives_objects_with_filter() {
add_filter( 'cptda_get_archives', array( $this, 'get_objects' ), 10 , 2 );

$expected = array(
'year' => $year,
'year' => "$year",
'month' => '3',
'posts' => '1',
);

$archive = cptda_get_archives( array( 'post_type' => 'cpt', 'echo' => false ) );

$this->assertEquals( $expected, get_object_vars( $this->archive_objects[0] ) );
$this->assertSame( $expected, get_object_vars( $this->archive_objects[0] ) );
$this->archive_objects = null;
}

Expand All @@ -68,14 +68,14 @@ function test_cptda_get_archives_objects() {
$post = $this->factory->post->create( $args );

$expected = array(
'year' => $year,
'year' => "$year",
'month' => '3',
'posts' => '1',
);

$archive = cptda_get_archives( array( 'post_type' => 'cpt', 'echo' => false, 'format' => 'object' ) );

$this->assertEquals( $expected, get_object_vars( $archive[0] ) );
$this->assertSame( $expected, get_object_vars( $archive[0] ) );
}

/**
Expand Down Expand Up @@ -128,8 +128,8 @@ function test_archive_offset() {

$archive = cptda_get_archives( $args );

$this->assertEquals( 1 , count( $archive ) );
$this->assertEquals( '2' , $archive[0]->month );
$this->assertSame( 1 , count( $archive ) );
$this->assertSame( '2' , $archive[0]->month );
}

function get_objects( $html, $objects ) {
Expand Down
8 changes: 4 additions & 4 deletions tests/test-block-archives.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function test_archive_block_in_post_content() {

$expected = "<ul class=\"wp-block-archives cptda-block-archives wp-block-archives-list\">\n{$expected}</ul>";

$this->assertEquals( strip_ws( $expected ), strip_ws( $block ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $block ) );

$archive = cptda_get_archives_html( array(
'post_type' => 'cpt',
Expand All @@ -47,7 +47,7 @@ function test_archive_block_in_post_content() {
);

// Check to see if cptda_get_archives_html() and cptda_render_block_archives() have same output.
$this->assertEquals( strip_ws( $expected ), strip_ws( $archive ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $archive ) );
}

/**
Expand All @@ -73,7 +73,7 @@ function test_output_of_archive_block_is_equal_to_wp_block() {
$expected = "<ul class=\"wp-block-archives wp-block-archives-list\">\n{$expected}</ul>\n";

// Markup same as WP archives block
$this->assertEquals( preg_replace( '/\s+/', '', $expected ), preg_replace( '/\s+/', '', $block ) );
$this->assertSame( preg_replace( '/\s+/', '', $expected ), preg_replace( '/\s+/', '', $block ) );

$archive = cptda_render_block_archives( array(
'post_type' => 'post',
Expand All @@ -84,6 +84,6 @@ function test_output_of_archive_block_is_equal_to_wp_block() {
$archive = str_replace(' cptda-block-archives ', ' ', $archive);

// Markup same as WP archives block
$this->assertEquals( preg_replace( '/\s+/', '', $expected ), preg_replace( '/\s+/', '', $archive ) );
$this->assertSame( preg_replace( '/\s+/', '', $expected ), preg_replace( '/\s+/', '', $archive ) );
}
}
4 changes: 2 additions & 2 deletions tests/test-block-calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function test_calendar_block_in_post_content() {
$monthnum = $previous_monthnum;
$year = $previous_year;

$this->assertEquals( strip_ws( $expected ), strip_ws( $block ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $block ) );
}

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ function test_calendar_block_is_equal_to_wp_calendar_block() {
$year = $previous_year;

// Same as WP calendar
$this->assertEquals( strip_ws( $expected ), strip_ws( $block ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $block ) );
}

}
12 changes: 6 additions & 6 deletions tests/test-block-recent-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function test_recent_posts_block_in_post_content() {
$block_class = 'wp-block-latest-posts wp-block-latest-posts__list cptda-block-latest-posts';
$cptda_latest_posts = "<ul class=\"{$block_class}\">\n{$expected}</ul>\n";

$this->assertEquals( strip_ws( $cptda_latest_posts ), strip_ws( $block ) );
$this->assertSame( strip_ws( $cptda_latest_posts ), strip_ws( $block ) );

$args = array(
'post_type' => 'cpt',
Expand All @@ -49,7 +49,7 @@ function test_recent_posts_block_in_post_content() {

$recent_posts_html = cptda_get_recent_posts_html( $posts, $args );

$this->assertEquals( strip_ws( $cptda_latest_posts ), strip_ws( $recent_posts_html ) );
$this->assertSame( strip_ws( $cptda_latest_posts ), strip_ws( $recent_posts_html ) );
}

/**
Expand All @@ -76,7 +76,7 @@ function test_output_of_latest_posts_block_is_equal_to_wp_block() {
$wp_latest_posts = "<ul class=\"{$block_class}\">{$expected}</ul>\n\n";

// Same as WP latest posts block mark up
$this->assertEquals( strip_ws( $wp_latest_posts ), strip_ws( $block ) );
$this->assertSame( strip_ws( $wp_latest_posts ), strip_ws( $block ) );

$args = array(
'post_type' => 'post',
Expand All @@ -88,7 +88,7 @@ function test_output_of_latest_posts_block_is_equal_to_wp_block() {
$cptda_latest_posts = "<ul class=\"{$block_class}\">{$expected}</ul>\n\n";

// Same as WP latest posts block mark up (with extra newlines)
$this->assertEquals( preg_replace( '/\s+/', '', $cptda_latest_posts ), preg_replace( '/\s+/', '', $recent_posts_html ) );
$this->assertSame( preg_replace( '/\s+/', '', $cptda_latest_posts ), preg_replace( '/\s+/', '', $recent_posts_html ) );
}

function test_no_posts_found() {
Expand All @@ -100,7 +100,7 @@ function test_no_posts_found() {

$recent_posts_html = cptda_render_block_recent_posts( $args );
$expected = '';
$this->assertEquals( strip_ws( $expected ), strip_ws( $recent_posts_html ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $recent_posts_html ) );
}

function test_no_posts_found_message() {
Expand All @@ -113,7 +113,7 @@ function test_no_posts_found_message() {

$recent_posts_html = cptda_render_block_recent_posts( $args );
$expected = "<div class=\"cptda-block-latest-posts cptda-no-posts\">\n<p>No posts found</p>\n</div>";
$this->assertEquals( strip_ws( $expected ), strip_ws( $recent_posts_html ) );
$this->assertSame( strip_ws( $expected ), strip_ws( $recent_posts_html ) );
}

function test_latest_post_empty_for_non_existing_post_types() {
Expand Down
20 changes: 10 additions & 10 deletions tests/test-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ function test_cptda_get_date_archive_cpt() {
$expected = cptda_get_queried_date_archive_post_type();
$deprecated = cptda_get_date_archive_cpt();

$this->assertEquals( 'cpt', $expected );
$this->assertEquals( $expected, $deprecated );
$this->assertSame( 'cpt', $expected );
$this->assertSame( $expected, $deprecated );
} else {
$this->fail( "Posts not created" );
}
Expand All @@ -101,7 +101,7 @@ function test_cptda_get_queried_date_archive_post_type() {
if ( isset( $_posts[0] ) ) {
$year = get_the_date( 'Y', $_posts[0] );
$this->go_to( '?post_type=cpt&year=' . $year );
$this->assertEquals( 'cpt', cptda_get_queried_date_archive_post_type() );
$this->assertSame( 'cpt', cptda_get_queried_date_archive_post_type() );
} else {
$this->fail( "Posts not created" );
}
Expand All @@ -128,7 +128,7 @@ function test_cptda_get_queried_date_archive_post_type_post() {
*/
function test_not_supported_custom_post_type_stati() {
$this->register_post_type( 'no_date_archives' );
$this->assertEquals( array( 'publish' ), cptda_get_cpt_date_archive_stati( 'no_date_archives' ) );
$this->assertSame( array( 'publish' ), cptda_get_cpt_date_archive_stati( 'no_date_archives' ) );
$this->unregister_post_type( 'no_date_archives' );
}

Expand All @@ -153,23 +153,23 @@ function test_post_status_publish_post_type_post() {
function test_post_status_future() {
$this->future_init();
add_filter( 'cptda_post_stati', array( $this, 'add_future_status' ), 10 , 2 );
$this->assertEquals( array( 'publish', 'future' ), cptda_get_cpt_date_archive_stati( 'cpt' ) );
$this->assertSame( array( 'publish', 'future' ), cptda_get_cpt_date_archive_stati( 'cpt' ) );
}

/**
* Test cptda_get_post_types
*/
function test_cptda_get_post_types() {
$this->init();
$this->assertEquals( array( 'cpt' => 'Custom Post Type' ), cptda_get_post_types( 'labels' ) );
$this->assertSame( array( 'cpt' => 'Custom Post Type' ), cptda_get_post_types( 'labels' ) );
}

/**
* Test cptda_get_post_types
*/
function test_cptda_get_post_types_future() {
$this->future_init();
$this->assertEquals( array( 'cpt' => 'Custom Post Type' ), cptda_get_post_types( 'labels', 'publish_future' ) );
$this->assertSame( array( 'cpt' => 'Custom Post Type' ), cptda_get_post_types( 'labels', 'publish_future' ) );
}

/**
Expand All @@ -192,7 +192,7 @@ function test_cptda_get_admin_post_types_deprecated() {
$this->init();
$expected = cptda_get_post_types( 'labels', 'admin' );
$deprecated = cptda_get_admin_post_types( 'names' );
$this->assertEquals( $expected, $deprecated );
$this->assertSame( $expected, $deprecated );
}

/**
Expand All @@ -207,9 +207,9 @@ function test_cptda_get_admin_post_types() {
register_post_type( 'cpt_2', $args );
$this->cpt_setup( 'cpt_2' );

$this->assertEquals( array( 'cpt' ), cptda_get_post_types( 'names', 'admin' ) );
$this->assertSame( array( 'cpt' ), cptda_get_post_types( 'names', 'admin' ) );

$this->assertEquals( array( 'cpt', 'cpt_2' ), cptda_get_post_types( 'names' ) );
$this->assertSame( array( 'cpt', 'cpt_2' ), cptda_get_post_types( 'names' ) );
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/test-post-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function tearDown() {
function test_cpt_slug_with_front() {
$this->init();
$slug = cptda_get_post_type_base( 'cpt' );
$this->assertEquals( 'blog/cpt', $slug );
$this->assertSame( 'blog/cpt', $slug );
}

/**
Expand All @@ -36,7 +36,7 @@ function test_cpt_slug() {
$this->set_permalink_structure( '/%postname%/' );
$this->init();
$slug = cptda_get_post_type_base( 'cpt' );
$this->assertEquals( 'cpt', $slug );
$this->assertSame( 'cpt', $slug );
}

/**
Expand All @@ -45,7 +45,7 @@ function test_cpt_slug() {
function test_cpt_rewrite_slug() {
$this->init( 'cpt', 'publish', array( 'slug' => 'rewrite', 'with_front' => true ) );
$slug = cptda_get_post_type_base( 'cpt' );
$this->assertEquals( 'blog/rewrite', $slug );
$this->assertSame( 'blog/rewrite', $slug );
}

/**
Expand All @@ -55,7 +55,7 @@ function test_cpt_rewrite_slug_without_front() {
$this->init( 'cpt', 'publish', array( 'slug' => 'rewrite', 'with_front' => false ) );
$plugin = cptda_date_archives();
$slug = cptda_get_post_type_base( 'cpt' );
$this->assertEquals( 'rewrite', $slug );
$this->assertSame( 'rewrite', $slug );
}

/**
Expand All @@ -68,7 +68,7 @@ function test_cpt_rewrite_slug_rewrite_false() {
$this->cpt_setup( 'cpt' );
$post_type = get_post_type_object( 'cpt' );
$slug = cptda_get_post_type_base( 'cpt' );
$this->assertEquals( '', $slug );
$this->assertSame( '', $slug );
}

}
Loading

0 comments on commit 39274e2

Please sign in to comment.