2015-10-07 20:27:38 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use Cms\Classes\Page;
|
2016-03-16 20:58:42 +00:00
|
|
|
use Cms\Classes\Theme;
|
2015-10-07 20:27:38 +00:00
|
|
|
use Cms\Classes\Layout;
|
2016-04-04 14:02:32 +00:00
|
|
|
use October\Rain\Halcyon\Model;
|
2015-10-07 20:27:38 +00:00
|
|
|
|
2020-02-07 08:59:39 +00:00
|
|
|
class CmsObjectQueryTest extends TestCase
|
2015-10-07 20:27:38 +00:00
|
|
|
{
|
2019-06-12 16:22:20 +00:00
|
|
|
public function setUp() : void
|
2016-03-16 20:58:42 +00:00
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2016-04-04 14:02:32 +00:00
|
|
|
Model::clearBootedModels();
|
|
|
|
|
Model::flushEventListeners();
|
2016-03-16 20:58:42 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-07 20:27:38 +00:00
|
|
|
public function testWhere()
|
|
|
|
|
{
|
|
|
|
|
$page = Page::where('layout', 'caramba')->first();
|
|
|
|
|
$this->assertEquals('/no-layout', $page->url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWhereComponent()
|
|
|
|
|
{
|
|
|
|
|
$pages = Page::whereComponent('testArchive', 'posts-per-page', '6');
|
|
|
|
|
$this->assertCount(1, $pages->all());
|
|
|
|
|
|
|
|
|
|
$page = $pages->first();
|
|
|
|
|
$this->assertEquals('/with-components', $page->url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWithComponent()
|
|
|
|
|
{
|
|
|
|
|
$pages = Page::withComponent('testArchive')->all();
|
|
|
|
|
$this->assertCount(2, $pages);
|
|
|
|
|
foreach ($pages as $page) {
|
|
|
|
|
$this->assertTrue(!!$page->hasComponent('testArchive'));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testWithComponentCallback()
|
|
|
|
|
{
|
|
|
|
|
include_once base_path() . '/tests/fixtures/plugins/october/tester/components/Archive.php';
|
|
|
|
|
|
2017-04-24 11:38:19 +00:00
|
|
|
$pages = Page::withComponent('testArchive', function ($component) {
|
2015-10-07 20:27:38 +00:00
|
|
|
return $component->property('posts-per-page') == '69';
|
|
|
|
|
})->all();
|
|
|
|
|
|
|
|
|
|
$this->assertCount(1, $pages);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function testLists()
|
|
|
|
|
{
|
|
|
|
|
// Default theme: test
|
|
|
|
|
$pages = Page::lists('baseFileName');
|
2015-11-18 14:13:10 +00:00
|
|
|
sort($pages);
|
|
|
|
|
|
2015-10-07 20:27:38 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
|
"404",
|
|
|
|
|
"a/a-page",
|
|
|
|
|
"ajax-test",
|
|
|
|
|
"authors",
|
|
|
|
|
"b/b-page",
|
|
|
|
|
"blog-archive",
|
2019-06-11 08:08:08 +00:00
|
|
|
"blog-category",
|
2015-10-07 20:27:38 +00:00
|
|
|
"blog-post",
|
|
|
|
|
"code-namespaces",
|
2016-05-21 14:20:51 +00:00
|
|
|
"code-namespaces-aliases",
|
2015-10-07 20:27:38 +00:00
|
|
|
"component-custom-render",
|
2015-11-18 14:13:10 +00:00
|
|
|
"component-partial",
|
2017-06-29 18:58:51 +00:00
|
|
|
"component-partial-alias-override",
|
2015-10-07 20:27:38 +00:00
|
|
|
"component-partial-nesting",
|
|
|
|
|
"component-partial-override",
|
|
|
|
|
"cycle-test",
|
|
|
|
|
"index",
|
|
|
|
|
"no-component",
|
2015-11-18 14:13:10 +00:00
|
|
|
"no-component-class",
|
2015-10-07 20:27:38 +00:00
|
|
|
"no-layout",
|
|
|
|
|
"no-partial",
|
|
|
|
|
"optional-full-php-tags",
|
|
|
|
|
"optional-short-php-tags",
|
|
|
|
|
"throw-php",
|
|
|
|
|
"with-component",
|
|
|
|
|
"with-components",
|
|
|
|
|
"with-content",
|
|
|
|
|
"with-layout",
|
|
|
|
|
"with-partials",
|
|
|
|
|
"with-placeholder",
|
|
|
|
|
], $pages);
|
|
|
|
|
|
|
|
|
|
$layouts = Layout::lists('baseFileName');
|
2015-11-18 14:13:10 +00:00
|
|
|
sort($layouts);
|
|
|
|
|
|
2015-10-07 20:27:38 +00:00
|
|
|
$this->assertEquals([
|
|
|
|
|
"a/a-layout",
|
|
|
|
|
"ajax-test",
|
|
|
|
|
"content",
|
|
|
|
|
"cycle-test",
|
|
|
|
|
"no-php",
|
|
|
|
|
"partials",
|
|
|
|
|
"php-parser-test",
|
|
|
|
|
"placeholder",
|
|
|
|
|
"sidebar",
|
|
|
|
|
], $layouts);
|
2016-03-16 20:58:42 +00:00
|
|
|
}
|
2015-10-07 20:27:38 +00:00
|
|
|
|
2016-03-16 20:58:42 +00:00
|
|
|
public function testListsNonExistentTheme()
|
|
|
|
|
{
|
2015-10-07 20:27:38 +00:00
|
|
|
$pages = Page::inTheme('NON_EXISTENT_THEME')->lists('baseFileName');
|
|
|
|
|
$this->assertEmpty($pages);
|
|
|
|
|
}
|
|
|
|
|
}
|