-
-
+
diff --git a/tests/Unit/BaseFixture/ClearedCache.php b/tests/Unit/BaseFixture/ClearedCache.php
new file mode 100644
index 0000000000..ae9906f2f6
--- /dev/null
+++ b/tests/Unit/BaseFixture/ClearedCache.php
@@ -0,0 +1,20 @@
+laravel->app[Cache\Repository::class];
+ $cache->clear();
+ }
+}
diff --git a/tests/Unit/Seo/Link/Fixture/Assertion.php b/tests/Unit/Seo/Link/Fixture/Assertion.php
index 8730905ffe..278a236576 100644
--- a/tests/Unit/Seo/Link/Fixture/Assertion.php
+++ b/tests/Unit/Seo/Link/Fixture/Assertion.php
@@ -2,23 +2,14 @@
namespace Tests\Unit\Seo\Link\Fixture;
use Coyote\Services\Parser\Factories\PostFactory;
-use Illuminate\Contracts\Cache;
use PHPUnit\Framework\Assert;
+use Tests\Unit\BaseFixture;
use Tests\Unit\BaseFixture\Server\Laravel;
trait Assertion
{
use Laravel\Application;
-
- /**
- * @before
- */
- function clearCache(): void
- {
- /** @var Cache\Repository $cache */
- $cache = $this->laravel->app[Cache\Repository::class];
- $cache->clear();
- }
+ use BaseFixture\ClearedCache;
function assertRenderPost(string $text, string $expected): void
{
diff --git a/tests/Unit/WhatsNew/Fixture/Models.php b/tests/Unit/WhatsNew/Fixture/Models.php
new file mode 100644
index 0000000000..62473623f9
--- /dev/null
+++ b/tests/Unit/WhatsNew/Fixture/Models.php
@@ -0,0 +1,50 @@
+newMicroblog(
+ $text,
+ new Carbon($dateTime),
+ $this->newTag('4programmers.net'));
+ }
+
+ function newMicroblog(string $text, Carbon $date, Tag $tag): int
+ {
+ $microblog = new Microblog([
+ 'user_id' => $this->systemUser()->id,
+ 'text' => $text,
+ ]);
+ $microblog->created_at = $date;
+ $microblog->save();
+ $microblog->tags()->save($tag);
+ return $microblog->id;
+ }
+
+ function newTag(string $name): Tag
+ {
+ $tag = new Tag(['name' => $name]);
+ $tag->save();
+ return $tag;
+ }
+
+ function systemUser(): User
+ {
+ $user = new User();
+ $user->name = '4programmers.net';
+ $user->email = 'irrelevant';
+ $user->save();
+ return $user;
+ }
+}
diff --git a/tests/Unit/WhatsNew/Fixture/NewsItems.php b/tests/Unit/WhatsNew/Fixture/NewsItems.php
new file mode 100644
index 0000000000..584b21fde5
--- /dev/null
+++ b/tests/Unit/WhatsNew/Fixture/NewsItems.php
@@ -0,0 +1,36 @@
+htmlView('/'));
+ /** @var \DOMElement $listItem */
+ foreach ($dom->elements(xPath:'//aside//div[@class="card bg-dark"]//ul/li') as $listItem) {
+ return $this->listItem($listItem);
+ }
+ throw new \AssertionError("Failed finding news item.");
+ }
+
+ function listItem(\DOMElement $listItem): array
+ {
+ $item = [];
+ /** @var \DOMElement $child */
+ foreach ($listItem->childNodes as $child) {
+ if ($child->nodeName === 'a') {
+ $item['text'] = $child->textContent;
+ $item['href'] = $child->getAttribute('href');
+ }
+ if ($child->nodeName === 'div') {
+ $item['date'] = $child->textContent;
+ }
+ }
+ return $item;
+ }
+}
diff --git a/tests/Unit/WhatsNew/Fixture/TrimmedString.php b/tests/Unit/WhatsNew/Fixture/TrimmedString.php
new file mode 100644
index 0000000000..1d21afa15c
--- /dev/null
+++ b/tests/Unit/WhatsNew/Fixture/TrimmedString.php
@@ -0,0 +1,42 @@
+value === \trim($other);
+ if ($returnResult) {
+ return $success;
+ }
+ if (!$success) {
+ $this->fail($other, $description, new ComparisonFailure(
+ $this->value,
+ $other,
+ "'$this->value'",
+ "'$other'",
+ ));
+ }
+ return null;
+ }
+
+ public function toString(): string
+ {
+ return 'is identical to trimmed ' . $this->exporter()->export($this->value);
+ }
+
+ protected function failureDescription($other): string
+ {
+ if (\is_string($other)) {
+ return 'two strings are identical';
+ }
+ return parent::failureDescription($other);
+ }
+}
diff --git a/tests/Unit/WhatsNew/Test.php b/tests/Unit/WhatsNew/Test.php
new file mode 100644
index 0000000000..8b4b0de8fb
--- /dev/null
+++ b/tests/Unit/WhatsNew/Test.php
@@ -0,0 +1,29 @@
+newWhatsNewItem('Valar morghulis.', '2005-04-02 21:37:13');
+ $this->assertThat(
+ $this->newsItem(),
+ $this->logicalAnd(
+ new ArrayKey('text', new TrimmedString('Valar morghulis.')),
+ new ArrayKey('href', $this->relativeUri("/Mikroblogi/View/$id")),
+ new ArrayKey('date', new TrimmedString('— 02 kwi 05')),
+ ));
+ }
+}