Skip to content

Commit b6e5e56

Browse files
committed
throw exception if post cannot be found
1 parent d20b701 commit b6e5e56

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

includes/Checker/Checks/Enqueued_Scripts_Size_Check.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ function ( $url ) use ( $result ) {
130130
* @since n.e.x.t
131131
*
132132
* @return array List of URL strings (either full URLs or paths).
133+
*
134+
* @throws Exception Thrown when a post type URL cannot be retrieved.
133135
*/
134136
protected function get_urls() {
135137
$urls = array( home_url() );
@@ -139,12 +141,21 @@ protected function get_urls() {
139141
array(
140142
'posts_per_page' => 1,
141143
'post_type' => $post_type,
142-
'post_status' => 'publish',
144+
'post_status' => array( 'publish', 'inherit' ),
143145
)
144146
);
145-
if ( isset( $posts[0] ) ) {
146-
$urls[] = get_permalink( $posts[0] );
147+
148+
if ( ! isset( $posts[0] ) ) {
149+
throw new Exception(
150+
sprintf(
151+
/* translators: %s: The Post Type name. */
152+
__( 'Unable to retrieve post URL for post type: %s', 'plugin-check' ),
153+
$post_type
154+
)
155+
);
147156
}
157+
158+
$urls[] = get_permalink( $posts[0] );
148159
}
149160

150161
return $urls;

tests/Checker/Checks/Enqueued_Scripts_Size_Check_Tests.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function test_run_with_errors() {
9494
$this->assertNotEmpty( $warnings );
9595

9696
$this->assertEquals( 0, $results->get_error_count() );
97-
$this->assertEquals( 3, $results->get_warning_count() );
97+
$this->assertEquals( 4, $results->get_warning_count() );
9898
}
9999

100100
public function test_run_with_errors_for_inline_script() {
@@ -113,6 +113,6 @@ public function test_run_with_errors_for_inline_script() {
113113
$this->assertNotEmpty( $warnings );
114114

115115
$this->assertEquals( 0, $results->get_error_count() );
116-
$this->assertEquals( 3, $results->get_warning_count() );
116+
$this->assertEquals( 4, $results->get_warning_count() );
117117
}
118118
}

tests/Checker/Preparations/Demo_Posts_Creation_Preparation_Tests.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function test_prepare_throws_exception() {
6161
$this->expectException( 'Exception' );
6262
$this->expectExceptionMessage( 'Content, title, and excerpt are empty.' );
6363

64-
$preparation->prepare();
64+
$cleanup = $preparation->prepare();
65+
$cleanup();
6566
}
6667
}

0 commit comments

Comments
 (0)