Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Nov 18, 2024
1 parent 13fe756 commit 099061a
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/Entries/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
namespace Entries;

use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Queue;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Eloquent\Collections\Collection;
use Statamic\Eloquent\Collections\CollectionModel;
use Statamic\Eloquent\Jobs\UpdateCollectionEntryUris;
use Statamic\Facades\Collection as CollectionFacade;
use Statamic\Facades\Entry as EntryFacade;
use Tests\TestCase;

class CollectionTest extends TestCase
Expand Down Expand Up @@ -40,4 +43,26 @@ public function it_saves_to_collection_model()

$this->assertDatabaseHas('collections', ['handle' => 'test']);
}

#[Test]
public function changing_a_collections_route_updates_entry_uris()
{
Queue::fake();

$collection = (new Collection)->handle('test');
$collection->save();

EntryFacade::make()->collection('test')->slug('one');
EntryFacade::make()->collection('test')->slug('two');
EntryFacade::make()->collection('test')->slug('three');

$collection->routes(['en' => '/blog/{slug}'])->save();
$collection->routes(['en' => '/{slug}'])->save();
$collection->routes(['en' => '/{slug}'])->save();
$collection->routes(['en' => null])->save();

// The job should only be dispatched three times.
// It shouldn't be dispatched when the route is null or hasn't changed since the last save.
Queue::assertPushed(UpdateCollectionEntryUris::class, 3);
}
}

0 comments on commit 099061a

Please sign in to comment.