Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/Cp/IconSets.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function register(IconSet ...$iconSets): void
}

/**
* Defers a callback until the icon sets are first read, for registration that
* Defers a callback until the icon sets are next read, for registration that
* needs request state. It runs once.
*
* @param Closure(self): void $callback
Expand All @@ -113,12 +113,14 @@ public function getIconSets(): array
self::CUSTOM => new DirectoryIconSet(self::CUSTOM, t('Custom'), $customIconPath),
] + $this->iconSets;
}
}

foreach ($this->deferred as $callback) {
$callback($this);
}
// Also runs callbacks deferred after the first read
$callbacks = $this->deferred;
$this->deferred = [];

$this->deferred = [];
foreach ($callbacks as $callback) {
$callback($this);
}

return $this->iconSets;
Expand Down
6 changes: 3 additions & 3 deletions src/Entry/Commands/UpdateStatusesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function () use ($condition, $status) {
->site('*')
->unique()
->status(null)
->where('status', '!=', $status)
->where('entries.status', '!=', $status)
->where($condition);

$this->resaveEntries($query);
Expand All @@ -80,8 +80,8 @@ private function conditions(string $now): array
Entry::STATUS_LIVE => function (Builder $query) use ($now) {
$query->where('entries.postDate', '<=', $now)
->where(function (Builder $query) use ($now) {
$query->whereNull('expiryDate')
->orWhere('expiryDate', '>', $now);
$query->whereNull('entries.expiryDate')
->orWhere('entries.expiryDate', '>', $now);
});
},
Entry::STATUS_PENDING => function (Builder $query) use ($now) {
Expand Down
2 changes: 1 addition & 1 deletion src/Update/Data/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function latest(): ?UpdateRelease
/** @param array<string, bool|float|string|array<array-key, array<string, bool|string|null>>|null> $data */
public static function fromArray(array $data): self
{
$data['status'] = UpdateStatus::tryFrom($data['status'] ?? '');
$data['status'] = UpdateStatus::tryFrom($data['status'] ?? '') ?? UpdateStatus::ELIGIBLE;
$data['releases'] = array_map(
UpdateRelease::fromArray(...),
$data['releases'] ?? [],
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/Cp/IconSetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@ public function getSvg(string $icon): ?string
->and(Icons::svg('my-icons:dot'))->toContain('<circle');
});

it('runs callbacks deferred after the icon sets were first read', function () {
$iconSets = app(IconSets::class);
$iconSets->getIconSets();

$iconSets->defer(fn (IconSets $iconSets) => $iconSets->register(new class('late-icons', 'Late Icons') extends IconSet
{
public function getIcons(): array
{
return [];
}

public function getKeywords(string $icon): array
{
return [];
}

public function getSvg(string $icon): ?string
{
return null;
}
}));

expect($iconSets->getIconSets())->toHaveKey('late-icons');
});

it('rejects icon sets with invalid handles', function (string $handle) {
app(IconSets::class)->register(new class($handle, 'Bad') extends IconSet
{
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Update/Data/UpdateTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

use CraftCms\Cms\Update\Data\Update;
use CraftCms\Cms\Update\Enums\UpdateStatus;

test('falls back to eligible when the status is missing or unknown', function (array $data) {
expect(Update::fromArray($data)->status)->toBe(UpdateStatus::ELIGIBLE);
})->with([
'missing' => [[]],
'unknown' => [['status' => 'paused']],
]);

test('keeps a known status', function () {
expect(Update::fromArray(['status' => 'expired'])->status)->toBe(UpdateStatus::EXPIRED);
});
Loading