|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Stache; |
| 4 | + |
| 5 | +use Facades\Tests\Factories\EntryFactory; |
| 6 | +use PHPUnit\Framework\Attributes\Test; |
| 7 | +use Statamic\Facades\Blink; |
| 8 | +use Statamic\Facades\Collection; |
| 9 | +use Statamic\Facades\Entry; |
| 10 | +use Statamic\Facades\Stache; |
| 11 | +use Tests\PreventSavingStacheItemsToDisk; |
| 12 | +use Tests\TestCase; |
| 13 | + |
| 14 | +class ColdStacheUriTest extends TestCase |
| 15 | +{ |
| 16 | + use PreventSavingStacheItemsToDisk; |
| 17 | + |
| 18 | + private function simulateColdStache(): void |
| 19 | + { |
| 20 | + Stache::clear(); |
| 21 | + Blink::flush(); |
| 22 | + } |
| 23 | + |
| 24 | + #[Test] |
| 25 | + public function entries_have_uris_on_cold_stache_with_single_site_structured_collection() |
| 26 | + { |
| 27 | + $collection = Collection::make('pages') |
| 28 | + ->routes('{parent_uri}/{slug}') |
| 29 | + ->structureContents(['root' => true]); |
| 30 | + $collection->save(); |
| 31 | + |
| 32 | + EntryFactory::id('alfa-id')->collection('pages')->slug('alfa')->data(['title' => 'Alfa'])->create(); |
| 33 | + EntryFactory::id('bravo-id')->collection('pages')->slug('bravo')->data(['title' => 'Bravo'])->create(); |
| 34 | + |
| 35 | + $this->simulateColdStache(); |
| 36 | + |
| 37 | + // Loading a non-URI index first triggers re-entrant URI index loading via getCachedItem(). |
| 38 | + Stache::store('entries')->store('pages')->index('site')->load(); |
| 39 | + |
| 40 | + $entries = Entry::query() |
| 41 | + ->where('collection', 'pages') |
| 42 | + ->whereNotNull('uri') |
| 43 | + ->whereStatus('published') |
| 44 | + ->get(); |
| 45 | + |
| 46 | + $this->assertCount(2, $entries); |
| 47 | + } |
| 48 | + |
| 49 | + #[Test] |
| 50 | + public function entries_have_uris_on_cold_stache_with_multisite_structured_collection() |
| 51 | + { |
| 52 | + $this->setSites([ |
| 53 | + 'en' => ['url' => 'http://localhost/', 'locale' => 'en_US'], |
| 54 | + 'fr' => ['url' => 'http://localhost/fr/', 'locale' => 'fr_FR'], |
| 55 | + ]); |
| 56 | + |
| 57 | + $collection = Collection::make('pages') |
| 58 | + ->routes('{parent_uri}/{slug}') |
| 59 | + ->structureContents(['root' => true]) |
| 60 | + ->sites(['en', 'fr']); |
| 61 | + $collection->save(); |
| 62 | + |
| 63 | + EntryFactory::id('alfa-id')->locale('en')->collection('pages')->slug('alfa')->data(['title' => 'Alfa'])->create(); |
| 64 | + EntryFactory::id('bravo-id')->locale('fr')->collection('pages')->slug('bravo')->origin('alfa-id')->data(['title' => 'Bravo'])->create(); |
| 65 | + |
| 66 | + $this->simulateColdStache(); |
| 67 | + |
| 68 | + Stache::store('entries')->store('pages')->index('site')->load(); |
| 69 | + |
| 70 | + $entries = Entry::query() |
| 71 | + ->where('collection', 'pages') |
| 72 | + ->whereNotNull('uri') |
| 73 | + ->whereStatus('published') |
| 74 | + ->get(); |
| 75 | + |
| 76 | + $this->assertCount(2, $entries); |
| 77 | + } |
| 78 | +} |
0 commit comments