diff --git a/src/Actions/RenderAdminNotice.php b/src/Actions/RenderAdminNotice.php index 20bdcb5..ee7ce4c 100644 --- a/src/Actions/RenderAdminNotice.php +++ b/src/Actions/RenderAdminNotice.php @@ -71,7 +71,7 @@ private function getStandardWrapperClasses(AdminNotice $notice): string $classes[] = "is-dismissible"; } - if ($notice->getLocation()->isInline()) { + if ($notice->getLocation() && $notice->getLocation()->isInline()) { $classes[] = 'inline'; } diff --git a/tests/unit/Actions/DisplayNoticesInAdminTest.php b/tests/unit/Actions/DisplayNoticesInAdminTest.php index e266b50..b4beb0f 100644 --- a/tests/unit/Actions/DisplayNoticesInAdminTest.php +++ b/tests/unit/Actions/DisplayNoticesInAdminTest.php @@ -58,7 +58,7 @@ public function testShouldAcceptMultipleNotices(): void $notice1 = $this->getSimpleMockNotice('foo'); $notice2 = $this->getSimpleMockNotice('bar'); - $this->expectOutputString('foobar'); + $this->expectOutputString($this->getSimpleNoticeOutput('foo') . $this->getSimpleNoticeOutput('bar')); $displayNoticesInAdmin($notice1, $notice2); } @@ -73,7 +73,7 @@ public function testPassesDateLimits(AdminNotice $notice, bool $shouldPass): voi $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); if ($shouldPass) { - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); } else { $this->expectOutputString(''); } @@ -111,7 +111,7 @@ public function testPassesWhenCallback(AdminNotice $notice, bool $shouldPass): v $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); if ($shouldPass) { - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); } else { $this->expectOutputString(''); } @@ -152,7 +152,7 @@ public function testPassesUserCapabilities(AdminNotice $notice, bool $shouldPass $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); if ($shouldPass) { - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); } else { $this->expectOutputString(''); } @@ -198,7 +198,7 @@ public function testShouldPassScreenConditionsWhenThereAreNoConditions(): void $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); $notice = $this->getSimpleMockNotice('foo'); - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); $displayNoticesInAdmin($notice); } @@ -209,7 +209,7 @@ public function testShouldPassScreenConditionsWhenConditionIsValidRegex(): void $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); $notice = $this->getSimpleMockNotice('foo')->on('~Dashboard~i'); // check regex flags, too - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); $displayNoticesInAdmin($notice); } @@ -220,7 +220,7 @@ public function testShouldPassScreenConditionsWhenConditionIsValidString(): void $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); $notice = $this->getSimpleMockNotice('foo')->on('dashboard'); - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); $displayNoticesInAdmin($notice); } @@ -234,10 +234,26 @@ public function testShouldPassScreenConditionsWhenConditionMatchesWPScreen(): vo $displayNoticesInAdmin = new DisplayNoticesInAdmin('namespace'); $notice = $this->getSimpleMockNotice('foo')->on(['base' => 'dashboard']); - $this->expectOutputString('foo'); + $this->expectNoticeInOutput('foo'); $displayNoticesInAdmin($notice); } + /** + * @unreleased + */ + public function expectNoticeInOutput(string $expected): void + { + $this->expectOutputString($this->getSimpleNoticeOutput($expected)); + } + + /** + * @unreleased + */ + private function getSimpleNoticeOutput(string $content): string + { + return "