92 lines
3.0 KiB
PHP
92 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\Content;
|
|
|
|
use App\CMS\Contracts\Repositories\Content;
|
|
use App\Models\Content\Content as ContentModel;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Support\Facades\App;
|
|
use Tests\TestCase;
|
|
|
|
class RepositoryTest extends TestCase
|
|
{
|
|
/**
|
|
* @var Content
|
|
*/
|
|
protected $content;
|
|
/**
|
|
* @var User
|
|
*/
|
|
protected $user;
|
|
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
$this->createApplication();
|
|
|
|
// clean tables
|
|
ContentModel::getQuery()
|
|
->delete();
|
|
User::getQuery()
|
|
->delete();
|
|
|
|
$this->content = App::make(Content::class);
|
|
|
|
// create new rows
|
|
$this->user = factory(User::class)->create();
|
|
factory(ContentModel::class, 3)->create(['userId' => $this->user->id, 'status' => Content::STATUS_DRAFT]);
|
|
factory(ContentModel::class, 1)->create(['userId' => $this->user->id, 'status' => Content::STATUS_PROTECTED]);
|
|
factory(ContentModel::class, 5)->create(['userId' => $this->user->id, 'status' => Content::STATUS_PUBLIC]);
|
|
}
|
|
|
|
/**
|
|
* Test for selecting homepage.
|
|
* At first, it tries to select non-existing homepage. On second try, homepage is created.
|
|
*/
|
|
public function testSelectingHomepage()
|
|
{
|
|
$homepage = $this->content->getHomepage();
|
|
$this->assertNull($homepage);
|
|
|
|
$newHomepage = factory(ContentModel::class)->create([
|
|
'userId' => $this->user->id,
|
|
'isHomepage' => 1,
|
|
'status' => Content::STATUS_PUBLIC,
|
|
'publishedFrom' => Carbon::now()
|
|
->subDays(10)
|
|
]);
|
|
|
|
$homepage = $this->content->getHomepage();
|
|
$this->assertNotNull($homepage);
|
|
$this->assertTrue($homepage->id === $newHomepage->id);
|
|
}
|
|
|
|
public function testSelectingAllPages()
|
|
{
|
|
$all = $this->content->all();
|
|
$this->assertCount(6, $all);
|
|
}
|
|
|
|
public function testSelectingByURL()
|
|
{
|
|
$slug = 'testing-slug-for-testing-purposes';
|
|
factory(ContentModel::class, 3)->create([
|
|
'userId' => $this->user->id,
|
|
'status' => Content::STATUS_PUBLIC,
|
|
'url' => $slug
|
|
]);
|
|
|
|
$page = $this->content->getByURL($slug);
|
|
|
|
$this->assertNotNull($page);
|
|
$this->assertTrue($page->exists);
|
|
}
|
|
|
|
public function testSelectingInvalidPageByURL()
|
|
{
|
|
$invalidPage = $this->content->getByURL('non-existing-url');
|
|
|
|
$this->assertNull($invalidPage);
|
|
}
|
|
} |