|
2 | 2 |
|
3 | 3 | namespace Tests\Feature\Fieldtypes; |
4 | 4 |
|
| 5 | +use Facades\Statamic\Fields\BlueprintRepository; |
5 | 6 | use PHPUnit\Framework\Attributes\Test; |
| 7 | +use Statamic\Facades\Blueprint; |
6 | 8 | use Statamic\Facades\Collection; |
7 | 9 | use Statamic\Facades\Entry; |
8 | 10 | use Statamic\Facades\Taxonomy; |
9 | 11 | use Statamic\Facades\Term; |
10 | 12 | use Statamic\Facades\User; |
| 13 | +use Statamic\Fields\Field; |
| 14 | +use Statamic\Fieldtypes\Entries; |
11 | 15 | use Statamic\Query\Scopes\Scope; |
12 | 16 | use Tests\FakesRoles; |
13 | 17 | use Tests\PreventSavingStacheItemsToDisk; |
@@ -187,6 +191,41 @@ public function it_forbids_access_to_terms_when_the_user_cannot_view_any_of_the_ |
187 | 191 | ->getJson("/cp/fieldtypes/relationship?config={$config}") |
188 | 192 | ->assertForbidden(); |
189 | 193 | } |
| 194 | + |
| 195 | + #[Test] |
| 196 | + public function it_filters_creatable_blueprints_using_create_blueprints_config() |
| 197 | + { |
| 198 | + $article = Blueprint::makeFromFields([])->setHandle('article')->setNamespace('collections.test'); |
| 199 | + $page = Blueprint::makeFromFields([])->setHandle('page')->setNamespace('collections.test'); |
| 200 | + |
| 201 | + BlueprintRepository::partialMock(); |
| 202 | + BlueprintRepository::shouldReceive('in')->with('collections/test')->andReturn(collect([ |
| 203 | + 'article' => $article, |
| 204 | + 'page' => $page, |
| 205 | + ])); |
| 206 | + |
| 207 | + $this->setTestRoles(['test' => ['access cp', 'view test entries', 'create test entries']]); |
| 208 | + $user = User::make()->assignRole('test')->save(); |
| 209 | + |
| 210 | + $this->actingAs($user); |
| 211 | + |
| 212 | + $fieldtype = $this->entriesFieldtype([ |
| 213 | + 'collections' => ['test'], |
| 214 | + 'create_blueprints' => ['article'], |
| 215 | + ]); |
| 216 | + |
| 217 | + $creatables = $fieldtype->preload()['creatables']; |
| 218 | + |
| 219 | + $this->assertCount(1, $creatables); |
| 220 | + $this->assertStringContainsString('blueprint=article', $creatables[0]['url']); |
| 221 | + } |
| 222 | + |
| 223 | + private function entriesFieldtype($config = []) |
| 224 | + { |
| 225 | + $field = new Field('test', array_merge(['type' => 'entries'], $config)); |
| 226 | + |
| 227 | + return (new Entries)->setField($field); |
| 228 | + } |
190 | 229 | } |
191 | 230 |
|
192 | 231 | class StartsWithC extends Scope |
|
0 commit comments