|
3 | 3 | namespace Tests\Feature\Entries; |
4 | 4 |
|
5 | 5 | use Facades\Statamic\Fields\BlueprintRepository; |
| 6 | +use Facades\Tests\Factories\EntryFactory; |
6 | 7 | use Illuminate\Support\Facades\Event; |
7 | 8 | use PHPUnit\Framework\Attributes\DataProvider; |
8 | 9 | use PHPUnit\Framework\Attributes\Test; |
@@ -343,6 +344,70 @@ public function user_without_publish_permission_gets_initial_published_false_eve |
343 | 344 | $this->assertFalse($response->json('values.published'), 'Initial published value should be false when user lacks publish permission, even if collection defaults to published'); |
344 | 345 | } |
345 | 346 |
|
| 347 | + #[Test] |
| 348 | + public function it_prevents_duplicate_uris_for_structured_entries_with_depth_conditional_routes() |
| 349 | + { |
| 350 | + $this->setTestRoles(['test' => ['access cp', 'create test entries']]); |
| 351 | + $user = tap(User::make()->assignRole('test'))->save(); |
| 352 | + |
| 353 | + $collection = tap( |
| 354 | + Collection::make('test') |
| 355 | + ->routes('{{ if depth > 1 }}{{ parent_uri }}/{{ slug }}{{ else }}base/{{ slug }}{{ /if }}') |
| 356 | + ->structureContents(['max_depth' => 10]) |
| 357 | + )->save(); |
| 358 | + |
| 359 | + EntryFactory::id('root-id')->slug('root')->collection('test')->create(); |
| 360 | + EntryFactory::id('child-id')->slug('child')->collection('test')->create(); |
| 361 | + |
| 362 | + $tree = $collection->structure()->in('en'); |
| 363 | + $tree->tree([ |
| 364 | + ['entry' => 'root-id', 'children' => [ |
| 365 | + ['entry' => 'child-id'], |
| 366 | + ]], |
| 367 | + ])->save(); |
| 368 | + |
| 369 | + $this |
| 370 | + ->actingAs($user) |
| 371 | + ->submit($collection, [ |
| 372 | + 'title' => 'Duplicate Child', |
| 373 | + 'slug' => 'child', |
| 374 | + '_parent' => 'root-id', |
| 375 | + ]) |
| 376 | + ->assertStatus(422) |
| 377 | + ->assertJsonValidationErrors(['slug']); |
| 378 | + } |
| 379 | + |
| 380 | + #[Test] |
| 381 | + public function it_prevents_duplicate_uris_when_parent_is_the_explicit_root() |
| 382 | + { |
| 383 | + $this->setTestRoles(['test' => ['access cp', 'create test entries']]); |
| 384 | + $user = tap(User::make()->assignRole('test'))->save(); |
| 385 | + |
| 386 | + $collection = tap( |
| 387 | + Collection::make('test') |
| 388 | + ->routes('{{ if depth > 1 }}{{ parent_uri }}/{{ slug }}{{ else }}base/{{ slug }}{{ /if }}') |
| 389 | + ->structureContents(['root' => true, 'max_depth' => 10]) |
| 390 | + )->save(); |
| 391 | + |
| 392 | + EntryFactory::id('root-id')->slug('root')->collection('test')->create(); |
| 393 | + EntryFactory::id('sibling-id')->slug('sibling')->collection('test')->create(); |
| 394 | + |
| 395 | + $collection->structure()->in('en')->tree([ |
| 396 | + ['entry' => 'root-id'], |
| 397 | + ['entry' => 'sibling-id'], |
| 398 | + ])->save(); |
| 399 | + |
| 400 | + $this |
| 401 | + ->actingAs($user) |
| 402 | + ->submit($collection, [ |
| 403 | + 'title' => 'Duplicate Sibling', |
| 404 | + 'slug' => 'sibling', |
| 405 | + '_parent' => 'root-id', |
| 406 | + ]) |
| 407 | + ->assertStatus(422) |
| 408 | + ->assertJsonValidationErrors(['slug']); |
| 409 | + } |
| 410 | + |
346 | 411 | private function seedUserAndCollection() |
347 | 412 | { |
348 | 413 | $this->setTestRoles(['test' => ['access cp', 'create test entries']]); |
|
0 commit comments