|
10 | 10 | use PHPUnit\Framework\Attributes\Test; |
11 | 11 | use Statamic\Contracts\Structures\Nav; |
12 | 12 | use Statamic\Entries\Entry; |
| 13 | +use Statamic\Facades\Collection as Collections; |
13 | 14 | use Statamic\Facades\Entry as EntryAPI; |
14 | 15 | use Statamic\Structures\CollectionStructure; |
15 | 16 | use Statamic\Structures\Page; |
@@ -528,10 +529,37 @@ public function it_is_arrayable() |
528 | 529 | ->each(fn ($value, $key) => $this->assertEquals($value, $page->{$key})) |
529 | 530 | ->each(fn ($value, $key) => $this->assertEquals($value, $page[$key])); |
530 | 531 |
|
531 | | - $this->assertEquals($page->collection()->toArray(), $arr['collection']); |
| 532 | + $this->assertEquals($page->collection->toArray(), $arr['collection']); |
532 | 533 | $this->assertEquals($page->blueprint->toArray(), $arr['blueprint']); |
533 | 534 | } |
534 | 535 |
|
| 536 | + #[Test] |
| 537 | + public function it_gets_collection_and_mounted_collection() |
| 538 | + { |
| 539 | + Collections::make('pages')->save(); |
| 540 | + Collections::make('blog')->mount('blog-page')->save(); |
| 541 | + Collections::make('events')->save(); |
| 542 | + |
| 543 | + $blogPageEntry = EntryFactory::id('blog-page')->collection('pages')->create(); |
| 544 | + $blogPostEntry = EntryFactory::id('blog-post-one')->collection('blog')->create(); |
| 545 | + $eventEntry = EntryFactory::id('event-one')->collection('events')->create(); |
| 546 | + |
| 547 | + $tree = $this->mock(Tree::class); |
| 548 | + $tree->shouldReceive('entry')->with('blog-page')->andReturn($blogPageEntry); |
| 549 | + $tree->shouldReceive('structure')->andReturnNull(); // just make the blueprint method quiet for now. |
| 550 | + |
| 551 | + $page = new Page; |
| 552 | + $page->setTree($tree); |
| 553 | + $page->setEntry($blogPageEntry); |
| 554 | + $page->setId($blogPageEntry->id()); // In reality the tree would set this. |
| 555 | + $this->assertEquals('blog', $page->mountedCollection()->handle()); |
| 556 | + $this->assertEquals('pages', $page->collection->handle()); |
| 557 | + |
| 558 | + // This should be "pages" but cannot be fixed without being a breaking change. |
| 559 | + // This will change in v6. |
| 560 | + $this->assertEquals('blog', $page->collection()->handle()); |
| 561 | + } |
| 562 | + |
535 | 563 | protected function newTree() |
536 | 564 | { |
537 | 565 | return new class extends Tree |
|
0 commit comments