Skip to content

Commit

Permalink
[5.x] Add collection tests (#385)
Browse files Browse the repository at this point in the history
* Add collection test

* Fix styling

* Revert "Fix styling"

This reverts commit 64910c7.

---------

Co-authored-by: duncanmcclean <[email protected]>
  • Loading branch information
duncanmcclean and duncanmcclean authored Nov 20, 2024
1 parent 3503966 commit f0860f8
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions tests/Collections/CollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Collections;

use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Eloquent\Collections\Collection;
use Statamic\Eloquent\Collections\CollectionModel;
use Statamic\Facades\Collection as CollectionFacade;
use Tests\TestCase;

class CollectionTest extends TestCase
{
use RefreshDatabase;

#[Test]
public function it_finds_collection()
{
$model = CollectionModel::create([
'title' => 'Blog',
'handle' => 'blog',
'settings' => [
'routes' => '/blog/{slug}',
'slugs' => true,
'dated' => true,
'template' => 'blog',
'default_status' => false,
],
]);

$find = CollectionFacade::find('blog');

$this->assertTrue($model->is($find->model()));
$this->assertEquals('blog', $find->handle());
$this->assertEquals('Blog', $find->title());
$this->assertEquals('/blog/{slug}', $find->route('en'));
$this->assertTrue($find->requiresSlugs());
$this->assertTrue($find->dated());
$this->assertEquals('blog', $find->template());
$this->assertFalse($find->defaultPublishState());
}

#[Test]
public function it_saves_to_collection_model()
{
$collection = (new Collection)->handle('test');

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

$collection->save();

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

0 comments on commit f0860f8

Please sign in to comment.