Skip to content

Commit 1fc20af

Browse files
committed
Add template conditional assertions
1 parent 7c0cfe1 commit 1fc20af

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

plugins/optimization-detective/tests/storage/test-data.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ public function data_provider_test_od_get_current_url_metrics_etag(): array {
303303
$GLOBALS['template'] = trailingslashit( get_template_directory() ) . 'home.php';
304304

305305
return function ( array $etag_data, Closure $get_etag ) use ( $post ): void {
306+
$this->assertTrue( is_home() );
307+
$this->assertTrue( is_front_page() );
306308
$this->assertNull( $etag_data['queried_object']['id'] );
307309
$this->assertNull( $etag_data['queried_object']['type'] );
308310
$this->assertCount( 1, $etag_data['queried_posts'] );
@@ -340,6 +342,7 @@ static function ( $data ) {
340342
$GLOBALS['template'] = trailingslashit( get_template_directory() ) . 'single.php';
341343

342344
return function ( array $etag_data, Closure $get_etag ) use ( $post ): void {
345+
$this->assertTrue( is_single( $post ) );
343346
$this->assertSame( $post->ID, $etag_data['queried_object']['id'] );
344347
$this->assertSame( 'post', $etag_data['queried_object']['type'] );
345348
$this->assertArrayHasKey( 'post_modified_gmt', $etag_data['queried_object'] );
@@ -378,6 +381,7 @@ static function ( $data ) {
378381
$GLOBALS['template'] = trailingslashit( get_template_directory() ) . 'category.php';
379382

380383
return function ( array $etag_data ) use ( $term, $post_ids ): void {
384+
$this->assertTrue( is_category( $term ) );
381385
$this->assertSame( $term->term_id, $etag_data['queried_object']['id'] );
382386
$this->assertSame( 'term', $etag_data['queried_object']['type'] );
383387
$this->assertCount( 2, $etag_data['queried_posts'] );
@@ -396,6 +400,7 @@ static function ( $data ) {
396400
$GLOBALS['template'] = trailingslashit( get_template_directory() ) . 'author.php';
397401

398402
return function ( array $etag_data ) use ( $user_id, $post_ids ): void {
403+
$this->assertTrue( is_author( $user_id ), 'Expected is_author() after having gone to ' . get_author_posts_url( $user_id ) );
399404
$this->assertSame( $user_id, $etag_data['queried_object']['id'] );
400405
$this->assertSame( 'user', $etag_data['queried_object']['type'] );
401406
$this->assertCount( 3, $etag_data['queried_posts'] );
@@ -419,6 +424,7 @@ static function ( $data ) {
419424
$GLOBALS['template'] = trailingslashit( get_template_directory() ) . 'archive-book.php';
420425

421426
return function ( array $etag_data ) use ( $post_ids ): void {
427+
$this->assertTrue( is_post_type_archive( 'book' ) );
422428
$this->assertNull( $etag_data['queried_object']['id'] );
423429
$this->assertSame( 'book', $etag_data['queried_object']['type'] );
424430
$this->assertCount( 4, $etag_data['queried_posts'] );
@@ -439,6 +445,8 @@ static function ( $data ) {
439445
$GLOBALS['template'] = trailingslashit( get_template_directory() ) . 'home.php';
440446

441447
return function ( array $etag_data ) use ( $page_id, $post_ids ): void {
448+
$this->assertTrue( is_home() );
449+
$this->assertFalse( is_front_page() );
442450
$this->assertSame( $page_id, $etag_data['queried_object']['id'] );
443451
$this->assertSame( 'post', $etag_data['queried_object']['type'] );
444452
$this->assertCount( 5, $etag_data['queried_posts'] );
@@ -455,6 +463,8 @@ static function ( $data ) {
455463
update_option( 'template', 'block-theme' );
456464
update_option( 'stylesheet', 'block-theme' );
457465
$this->go_to( '/' );
466+
$this->assertTrue( is_home() );
467+
$this->assertTrue( is_front_page() );
458468
$GLOBALS['_wp_current_template_id'] = 'block-theme//index';
459469

460470
return function ( array $etag_data ): void {

0 commit comments

Comments
 (0)