|
4 | 4 |
|
5 | 5 | use Facades\Statamic\Fields\BlueprintRepository;
|
6 | 6 | use Illuminate\Foundation\Testing\RefreshDatabase;
|
| 7 | +use Illuminate\Support\Facades\Facade; |
7 | 8 | use PHPUnit\Framework\Attributes\Test;
|
| 9 | +use Statamic\Contracts\Taxonomies\TaxonomyRepository as TaxonomyRepositoryContract; |
8 | 10 | use Statamic\Eloquent\Collections\Collection;
|
9 | 11 | use Statamic\Eloquent\Entries\Entry;
|
10 | 12 | use Statamic\Eloquent\Entries\EntryModel;
|
| 13 | +use Statamic\Eloquent\Taxonomies\Taxonomy; |
11 | 14 | use Statamic\Facades;
|
12 | 15 | use Statamic\Facades\Collection as CollectionFacade;
|
13 | 16 | use Statamic\Facades\Entry as EntryFacade;
|
| 17 | +use Statamic\Facades\Stache; |
| 18 | +use Statamic\Facades\Term as TermFacade; |
| 19 | +use Statamic\Statamic; |
| 20 | +use Statamic\Testing\Concerns\PreventsSavingStacheItemsToDisk; |
14 | 21 | use Tests\TestCase;
|
15 | 22 |
|
16 | 23 | class EntryTest extends TestCase
|
17 | 24 | {
|
| 25 | + use PreventsSavingStacheItemsToDisk; |
18 | 26 | use RefreshDatabase;
|
19 | 27 |
|
20 | 28 | #[Test]
|
@@ -346,4 +354,47 @@ public function null_values_are_removed_from_data()
|
346 | 354 |
|
347 | 355 | $this->assertArrayNotHasKey('null_value', $entry->model()->data);
|
348 | 356 | }
|
| 357 | + |
| 358 | + #[Test] |
| 359 | + public function it_doesnt_build_stache_associations_when_taxonomy_driver_is_eloquent() |
| 360 | + { |
| 361 | + Taxonomy::make('test')->title('test')->save(); |
| 362 | + |
| 363 | + TermFacade::make('test-term')->taxonomy('test')->data([])->save(); |
| 364 | + |
| 365 | + $taxonomyStore = Stache::stores()->get('terms'); |
| 366 | + $this->assertCount(0, $taxonomyStore->store('test')->index('associations')->items()); |
| 367 | + |
| 368 | + $collection = \Statamic\Facades\Collection::make('blog')->routes('blog/{slug}')->taxonomies(['test'])->save(); |
| 369 | + |
| 370 | + (new Entry)->id(1)->collection($collection)->data(['title' => 'Post 1', 'test' => ['test-term']])->slug('alfa')->save(); |
| 371 | + (new Entry)->id(2)->collection($collection)->data(['title' => 'Post 2', 'test' => ['test-term']])->slug('bravo')->save(); |
| 372 | + (new Entry)->id(3)->collection($collection)->data(['title' => 'Post 3'])->slug('charlie')->save(); |
| 373 | + |
| 374 | + $this->assertCount(0, $taxonomyStore->store('test')->index('associations')->items()); |
| 375 | + } |
| 376 | + |
| 377 | + #[Test] |
| 378 | + public function it_build_stache_associations_when_taxonomy_driver_is_not_eloquent() |
| 379 | + { |
| 380 | + config()->set('statamic.eloquent-driver.taxonomies.driver', 'file'); |
| 381 | + |
| 382 | + Facade::clearResolvedInstance(TaxonomyRepositoryContract::class); |
| 383 | + Statamic::repository(TaxonomyRepositoryContract::class, \Statamic\Stache\Repositories\TaxonomyRepository::class); |
| 384 | + |
| 385 | + Taxonomy::make('test')->title('test')->save(); |
| 386 | + |
| 387 | + TermFacade::make('test-term')->taxonomy('test')->data([])->save(); |
| 388 | + |
| 389 | + $taxonomyStore = Stache::stores()->get('terms'); |
| 390 | + $this->assertCount(0, $taxonomyStore->store('test')->index('associations')->items()); |
| 391 | + |
| 392 | + $collection = \Statamic\Facades\Collection::make('blog')->routes('blog/{slug}')->taxonomies(['test'])->save(); |
| 393 | + |
| 394 | + (new Entry)->id(1)->collection($collection)->data(['title' => 'Post 1', 'test' => ['test-term']])->slug('alfa')->save(); |
| 395 | + (new Entry)->id(2)->collection($collection)->data(['title' => 'Post 2', 'test' => ['test-term']])->slug('bravo')->save(); |
| 396 | + (new Entry)->id(3)->collection($collection)->data(['title' => 'Post 3'])->slug('charlie')->save(); |
| 397 | + |
| 398 | + $this->assertCount(2, $taxonomyStore->store('test')->index('associations')->items()); |
| 399 | + } |
349 | 400 | }
|
0 commit comments