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 "
$content
"; + } + /** * Produces a simple mock with predictable output. * @@ -246,7 +262,6 @@ public function testShouldPassScreenConditionsWhenConditionMatchesWPScreen(): vo private function getSimpleMockNotice($output): AdminNotice { return (new AdminNotice('test_id', $output)) - ->withoutWrapper() ->withoutAutoParagraph(); } } diff --git a/tests/unit/Actions/RenderAdminNoticeTest.php b/tests/unit/Actions/RenderAdminNoticeTest.php index 8a6651c..ca0889a 100644 --- a/tests/unit/Actions/RenderAdminNoticeTest.php +++ b/tests/unit/Actions/RenderAdminNoticeTest.php @@ -14,12 +14,14 @@ class RenderAdminNoticeTest extends TestCase public function testShouldRenderNoticeWithoutWrapper(): void { $notice = (new AdminNotice('test_id', 'Hello world!')) - ->withoutAutoParagraph() - ->withoutWrapper(); + ->withoutAutoParagraph(); $renderAdminNotice = new RenderAdminNotice('namespace'); - $this->assertEquals('Hello world!', $renderAdminNotice($notice)); + $this->assertEquals( + '
Hello world!
', + $renderAdminNotice($notice) + ); } /** diff --git a/tests/unit/AdminNoticeTest.php b/tests/unit/AdminNoticeTest.php index 7454b6a..78ab96c 100644 --- a/tests/unit/AdminNoticeTest.php +++ b/tests/unit/AdminNoticeTest.php @@ -218,64 +218,6 @@ public function testUrgency(): void $this->assertEquals('warning', $notice->getUrgency()); } - /** - * @covers ::withWrapper - * @covers ::withoutWrapper - * @covers ::usesWrapper - */ - public function testWithWrapper(): void - { - // Defaults to true - $notice = new AdminNotice('test_id', 'test'); - $this->assertTrue($notice->usesWrapper()); - - // Method can be set to false - $self = $notice->withWrapper(false); - $this->assertFalse($notice->usesWrapper()); - $this->assertSame($notice, $self); - - // Method can be explicitly set to true - $notice->withWrapper(true); - $this->assertTrue($notice->usesWrapper()); - - // withoutWrapper is an alias for withWrapper(false) - $self = $notice->withoutWrapper(); - $this->assertFalse($notice->usesWrapper()); - $this->assertSame($notice, $self); - } - - /** - * @covers ::inline - * @covers ::notInline - * @covers ::isInline - * - * @since 1.2.0 - */ - public function testInline(): void - { - // Defaults to false - $notice = new AdminNotice('test_id', 'test'); - $this->assertFalse($notice->isInline()); - - // Method defaults to true - $self = $notice->inline(); - $this->assertTrue($notice->isInline()); - $this->assertSame($notice, $self); - - // Method can be explicitly set to false - $notice->inline(false); - $this->assertFalse($notice->isInline()); - - // Method can be set to true - $notice->inline(true); - $this->assertTrue($notice->isInline()); - - // notInline is an alias for inline(false) - $self = $notice->notInline(); - $this->assertFalse($notice->isInline()); - $this->assertSame($notice, $self); - } - /** * @covers ::dismissible * @covers ::notDismissible