Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reordering entries in a collection named literally collection #6371

Merged
merged 2 commits into from
Jul 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions src/Stache/Stores/CollectionTreeStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Statamic\Facades\Collection;
use Statamic\Facades\Path;
use Statamic\Structures\CollectionTree;
use Statamic\Support\Str;
use Symfony\Component\Finder\SplFileInfo;

class CollectionTreeStore extends NavTreeStore
Expand Down Expand Up @@ -39,15 +38,4 @@ protected function newTreeClassByPath($path)
->locale($site)
->handle($handle);
}

public function getItemKey($item)
{
$key = parent::getItemKey($item);

if (Str::startsWith($key, 'collection::')) {
$key = Str::after($key, 'collection::');
}

return $key;
}
}
20 changes: 17 additions & 3 deletions tests/Feature/Collections/UpdateCollectionTreeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ class UpdateCollectionTreeTest extends TestCase
use PreventSavingStacheItemsToDisk;
use FakesRoles;

/** @test */
public function it_updates_the_tree()
/**
* @test
* @dataProvider collectionTreeDataProvider
*/
public function it_updates_the_tree($collectionHandle)
{
$this->withoutExceptionHandling();
$user = tap(User::make()->makeSuper())->save();
$collection = tap(Collection::make('test')->routes('{parent_uri}/{slug}'))->save();
$collection = tap(Collection::make($collectionHandle)->routes('{parent_uri}/{slug}'))->save();
EntryFactory::id('e1')->collection($collection)->slug('a')->create();
EntryFactory::id('e2')->collection($collection)->slug('b')->create();
EntryFactory::id('e3')->collection($collection)->slug('c')->create();
Expand Down Expand Up @@ -59,6 +62,17 @@ public function it_updates_the_tree()
], $collection->structure()->in('en')->tree());
}

public function collectionTreeDataProvider()
{
return [
'arbitrary handle' => ['pages'],
'handle of collection' => ['collection'],
'handle ending with collection' => ['foo_collection'],
'handle starting with collection' => ['collection_foo'],
'handle with collection inside' => ['foo_collection_foo'],
];
}

/** @test */
public function it_doesnt_update_the_tree_if_theres_a_duplicate_uri_when_expecting_root()
{
Expand Down