|
11 | 11 | use Statamic\Facades\Collection; |
12 | 12 | use Statamic\Facades\Entry; |
13 | 13 | use Statamic\Facades\User; |
| 14 | +use Facades\Tests\Factories\EntryFactory; |
14 | 15 | use Tests\FakesRoles; |
15 | 16 | use Tests\PreventSavingStacheItemsToDisk; |
16 | 17 | use Tests\TestCase; |
@@ -343,6 +344,39 @@ 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 | + |
346 | 380 | private function seedUserAndCollection() |
347 | 381 | { |
348 | 382 | $this->setTestRoles(['test' => ['access cp', 'create test entries']]); |
|
0 commit comments