Skip to content

Commit e8695c4

Browse files
committed
add failing test
1 parent 8a48cc5 commit e8695c4

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

tests/Feature/Entries/StoreEntryTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Statamic\Facades\Collection;
1212
use Statamic\Facades\Entry;
1313
use Statamic\Facades\User;
14+
use Facades\Tests\Factories\EntryFactory;
1415
use Tests\FakesRoles;
1516
use Tests\PreventSavingStacheItemsToDisk;
1617
use Tests\TestCase;
@@ -343,6 +344,39 @@ public function user_without_publish_permission_gets_initial_published_false_eve
343344
$this->assertFalse($response->json('values.published'), 'Initial published value should be false when user lacks publish permission, even if collection defaults to published');
344345
}
345346

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+
346380
private function seedUserAndCollection()
347381
{
348382
$this->setTestRoles(['test' => ['access cp', 'create test entries']]);

0 commit comments

Comments
 (0)