|
2 | 2 |
|
3 | 3 | namespace Tests\Feature\Entries; |
4 | 4 |
|
| 5 | +use Facades\Statamic\Fields\BlueprintRepository; |
5 | 6 | use Facades\Tests\Factories\EntryFactory; |
6 | 7 | use PHPUnit\Framework\Attributes\Test; |
7 | 8 | use Statamic\Entries\Collection; |
| 9 | +use Statamic\Facades\Blueprint; |
8 | 10 | use Statamic\Facades\User; |
9 | 11 | use Tests\FakesRoles; |
10 | 12 | use Tests\PreventSavingStacheItemsToDisk; |
@@ -90,4 +92,44 @@ public function it_shows_only_entries_in_index_for_sites_user_can_access() |
90 | 92 |
|
91 | 93 | $this->assertEquals($expected, $entries->pluck('slug')->all()); |
92 | 94 | } |
| 95 | + |
| 96 | + #[Test] |
| 97 | + public function it_only_lists_the_counts_of_replicator_sets_and_grid_rows() |
| 98 | + { |
| 99 | + $collection = tap(Collection::make('test'))->save(); |
| 100 | + |
| 101 | + $blueprint = Blueprint::makeFromFields([ |
| 102 | + 'sets' => ['type' => 'replicator', 'listable' => true, 'sets' => ['main' => ['sets' => [ |
| 103 | + 'text' => ['fields' => [['handle' => 'words', 'field' => ['type' => 'text']]]], |
| 104 | + ]]]], |
| 105 | + 'rows' => ['type' => 'grid', 'listable' => true, 'fields' => [ |
| 106 | + ['handle' => 'words', 'field' => ['type' => 'text']], |
| 107 | + ]], |
| 108 | + ])->setHandle('test'); |
| 109 | + |
| 110 | + BlueprintRepository::partialMock(); |
| 111 | + BlueprintRepository::shouldReceive('in')->with('collections/test')->andReturn(collect([$blueprint])); |
| 112 | + |
| 113 | + EntryFactory::collection($collection)->slug('one')->data([ |
| 114 | + 'sets' => [ |
| 115 | + ['id' => 'set-a', 'type' => 'text', 'words' => 'Lots of words'], |
| 116 | + ['id' => 'set-b', 'type' => 'text', 'words' => 'More words', 'enabled' => false], |
| 117 | + ], |
| 118 | + 'rows' => [ |
| 119 | + ['id' => 'row-a', 'words' => 'Lots of words'], |
| 120 | + ['id' => 'row-b', 'words' => 'More words'], |
| 121 | + ['id' => 'row-c', 'words' => 'Even more words'], |
| 122 | + ], |
| 123 | + ])->create(); |
| 124 | + |
| 125 | + $response = $this |
| 126 | + ->actingAs(tap(User::make()->makeSuper())->save()) |
| 127 | + ->get(cp_route('collections.entries.index', ['collection' => 'test', 'columns' => 'title,sets,rows'])) |
| 128 | + ->assertOk(); |
| 129 | + |
| 130 | + $entry = $response->json('data.0'); |
| 131 | + |
| 132 | + $this->assertSame(2, $entry['sets']); |
| 133 | + $this->assertSame(3, $entry['rows']); |
| 134 | + } |
93 | 135 | } |
0 commit comments