Class luya\testsuite\scopes\PageScope
Inheritance | luya\testsuite\scopes\PageScope » luya\testsuite\scopes\BaseScope |
---|---|
Uses Traits | luya\testsuite\traits\CmsDatabaseTableTrait |
Available since version | 1.0.21 |
Source Code | https://github.com/luyadev/luya-testsuite/blob/master/src/scopes/PageScope.php |
Create a CMS Page Scope.
PageScope::run($this->app, function(PageScope $scope) {
$scope
>createPage('home', '@app/data/cmslayoutviewfile.php', ['content'])
->addBlockAndContent(HtmlBlock::class, 'content', [
'html' => '<p>foobar</p>',
]);
$page = NavItemPage::findOne($scope->pageId);
$content = $page->getContent();
$this->assertSame('<h1>view file</h1>p>foobar</p>', $content);
});
Public Properties
Property | Type | Description | Defined By |
---|---|---|---|
$pageId | integer | The page id which will be created. | luya\testsuite\scopes\PageScope |
$pagePropertyFixtureData | array | An array with fixture data for page properties | luya\testsuite\scopes\PageScope |
Protected Properties
Public Methods
Property Details
An array with fixture data for page properties
Method Details
Defined in: luya\testsuite\scopes\BaseScope::__construct()
Permission Scope contstructor.
public void __construct ( yii\base\Application $app, callable $fn, callable $invoke = null ) | ||
$app | yii\base\Application | |
$fn | callable | |
$invoke | callable |
public function __construct(Application $app, callable $fn, callable $invoke = null)
{
$this->_app = $app;
$this->_invoke = $invoke;
$this->_fn = $fn;
}
Add a cms block to the list of blocks.
public \luya\testsuite\scopes\Block addBlock ( $blockClass ) | ||
$blockClass | string |
public function addBlock($blockClass)
{
$model = $this->blockFixture->newModel;
$model->group_id = 1;
$model->class = $blockClass;
$model->is_disabled = 0;
$model->save();
return $model;
}
Combination of add block and add content.
public self addBlockAndContent ( $blockClass, $layoutPlacholderVar, array $values = [], array $cfgs = [] ) | ||
$blockClass | string | |
$layoutPlacholderVar | string | |
$values | array | |
$cfgs | array |
public function addBlockAndContent($blockClass, $layoutPlacholderVar, array $values = [], array $cfgs = [])
{
$block = $this->addBlock($blockClass);
return $this->addContent($block->id, $layoutPlacholderVar, $values, $cfgs);
}
Add the content for a given block id.
public self addContent ( $blockId, $layoutPlacholderVar, array $values = [], array $cfgs = [] ) | ||
$blockId | integer | |
$layoutPlacholderVar | string | |
$values | array | |
$cfgs | array |
public function addContent($blockId, $layoutPlacholderVar, array $values = [], array $cfgs = [])
{
/** @var \luya\cms\models\NavItemPageBlockItem $model */
$model = $this->navItemPageBlockItemFixture->newModel;
$model->json_config_values = $values;
$model->json_config_cfg_values = $cfgs;
$model->block_id = $blockId;
$model->placeholder_var = $layoutPlacholderVar;
$model->nav_item_page_id = 1;
$model->prev_id = 0;
$model->create_user_id = 0;
$model->update_user_id = 0;
$model->is_dirty = 0;
$model->is_hidden = 0;
$model->save();
return $this;
}
Clean up tables and fixtures.
public void cleanup ( ) |
public function cleanup()
{
$this->blockFixture->cleanup();
$this->navItemPageBlockItemFixture->cleanup();
$this->logFixture->cleanup();
$this->langFixture->cleanup();
$this->cleanupFixture($this->layoutFixture);
$this->cleanupFixture($this->websiteFixture);
$this->cleanupFixture($this->navContainerFixture);
$this->cleanupFixture($this->navFixture);
$this->cleanupFixture($this->navItemFixture);
$this->cleanupFixture($this->navItemPageFixture);
$this->cleanupFixture($this->navItemRedirectFixture);
$this->cleanupFixture($this->navItemModuleFixture);
}
Defined in: luya\testsuite\scopes\BaseScope::cleanupFixture()
A helper method to cleanup fixtures.
If the given fixture property is not an instance of ActiveRecordFixture nothing happens, otherwise the cleanup() will be run.
public void cleanupFixture ( $fixture ) | ||
$fixture | mixed |
public function cleanupFixture($fixture)
{
if ($fixture instanceof ActiveRecordFixture) {
$fixture->cleanup();
}
}
Defined in: luya\testsuite\scopes\BaseScope::configure()
Configured is used before prepare which allows you to configure the current scope.
public void configure ( ) |
public function configure()
{
if ($this->_invoke) {
call_user_func_array($this->_invoke, [$this]);
}
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsBlockFixture()
Create Cms Block Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsBlockFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsBlockFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => Block::class,
'fixtureData' => $fixtureData,
]);
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsBlockGroupFixture()
Create Cms Block Group Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsBlockGroupFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsBlockGroupFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => BlockGroup::class,
'fixtureData' => $fixtureData,
]);
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsLayoutFixture()
Create Cms Layout Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsLayoutFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsLayoutFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => Layout::class,
'fixtureData' => $fixtureData,
]);
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsLog()
Create Cms Log Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsLog ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsLog(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => Log::class,
'fixtureData' => $fixtureData,
]);
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsPropertyFixture()
Create Cms Property Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsPropertyFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsPropertyFixture(array $fixtureData = [])
{
return new ActiveRecordFixture([
'modelClass' => Property::class,
'fixtureData' => $fixtureData,
]);
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsRedirectFixture()
Create Cms Redirect Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsRedirectFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsRedirectFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => Redirect::class,
'fixtureData' => $fixtureData,
]);
}
Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsWebsiteFixture()
Create Cms Website Fixture
public luya\testsuite\fixtures\ActiveRecordFixture createCmsWebsiteFixture ( array $fixtureData = [] ) | ||
$fixtureData | array |
public function createCmsWebsiteFixture(array $fixtureData = [])
{
return new NgRestModelFixture([
'modelClass' => Website::class,
'fixtureData' => $fixtureData,
]);
}
Create a CMS Page with title, path to layout file and layout file placholders.
public self createPage ( $title, $layoutViewFile, array $layoutPlaceholders, array $options = [] ) | ||
$title | string | |
$layoutViewFile | string |
The path to the cmslayout file, for example: |
$layoutPlaceholders | array |
An array only containing the available placeholders like: |
$options |
public function createPage($title, $layoutViewFile, array $layoutPlaceholders, array $options = [])
{
$id = ArrayHelper::getValue($options, 'id', 1);
$parentNavId = ArrayHelper::getValue($options, 'parentNavId', 0);
$isHome = ArrayHelper::getValue($options, 'isHome', true);
$pageId = ArrayHelper::getValue($options, 'pageId', $this->pageId);
$json = [];
foreach ($layoutPlaceholders as $c) {
$json[] = ['label' => $c, 'var' => $c];
}
$this->layoutFixture = $this->createCmsLayoutFixture([
'layout1' => [
'id' => $id,
'name' => 'layout1',
'view_file' => $layoutViewFile,
'json_config' => Json::encode(['placeholders' => [$json]]),
]
]);
$this->websiteFixture = $this->createCmsWebsiteFixture([
'website1' => [
'id' => 1,
'name' => 'default',
'host' => '',
'aliases' => '',
'is_default' => 1,
'is_active' => 1,
'is_deleted' => 0,
],
]);
$this->navContainerFixture = $this->createCmsNavContainerFixture([
'container1' => [
'id' => $id,
'name' => 'container',
'alias' => 'container',
'website_id' => 1,
],
]);
$this->navFixture = $this->createCmsNavFixture([
'nav1' => [
'id' => $id,
'nav_container_id' => 1,
'parent_nav_id' => $parentNavId,
'sort_index' => $id,
'is_deleted' => 0,
'is_hidden' => 0,
'is_offline' => 0,
'is_home' => $isHome,
'is_draft' => 0,
'layout_file' => null,
'publish_from' => null,
'publish_till' => null,
]
]);
$this->navItemFixture = $this->createCmsNavItemFixture([
'navItemPage1' => [
'id' => "{$id}001",
'nav_id' => $id,
'lang_id' => 1,
'nav_item_type' => NavItem::TYPE_PAGE,
'nav_item_type_id' => 1,
'create_user_id' => 0,
'update_user_id' => 0,
'timestamp_create' => 123123,
'timestamp_update' => 1231231,
'title' => $title,
'alias' => Inflector::slug($title),
'description' => $title,
'keywords' => $title,
'title_tag' => $title,
'image_id' => 0,
'is_url_strict_parsing_disabled' => 0,
],
'navItemPage1' => [
'id' => "{$id}002",
'nav_id' => 1,
'lang_id' => 1,
'nav_item_type' => NavItem::TYPE_MODULE,
'nav_item_type_id' => 1,
'create_user_id' => 0,
'update_user_id' => 0,
'timestamp_create' => 123123,
'timestamp_update' => 1231231,
'title' => $title,
'alias' => Inflector::slug($title),
'description' => $title,
'keywords' => $title,
'title_tag' => $title,
'image_id' => 0,
'is_url_strict_parsing_disabled' => 0,
],
'navItemPage1' => [
'id' => "{$id}003",
'nav_id' => 1,
'lang_id' => 1,
'nav_item_type' => NavItem::TYPE_REDIRECT,
'nav_item_type_id' => 1,
'create_user_id' => 0,
'update_user_id' => 0,
'timestamp_create' => 123123,
'timestamp_update' => 1231231,
'title' => $title,
'alias' => Inflector::slug($title),
'description' => $title,
'keywords' => $title,
'title_tag' => $title,
'image_id' => 0,
'is_url_strict_parsing_disabled' => 0,
],
]);
$this->navItemPageFixture = $this->createCmsNavItemPageFixture([
'page1' => [
'id' => $pageId,
'layout_id' => 1,
'nav_item_id' => $id,
'timestamp_create' => 123123,
'create_user_id' => 0,
'version_alias' => $title,
]
]);
$this->navItemRedirectFixture = $this->createCmsNavItemRedirectFixture([
'redirect1' => [
'id' => $id,
'type' => 1,
'value' => 'luya.io',
'target' => '_blank',
]
]);
$this->navItemModuleFixture = $this->createCmsNavItemModuleFixture([
'module1' => [
'id' => $id,
'module_name' => 'test',
'controller_name' => 'test',
'action_name' => 'test',
'action_params' => '',
]
]);
$this->propertyFixture = $this->createCmsPropertyFixture($this->pagePropertyFixtureData);
return $this;
}
Defined in: luya\testsuite\scopes\BaseScope::getApp()
Returns the Application instance.
Getter method to access the private object.
public yii\base\Application getApp ( ) |
public function getApp()
{
return $this->_app;
}
Returns the application database componenet.
public yii\db\Connection getDatabaseComponent ( ) |
public function getDatabaseComponent()
{
return $this->getApp()->db;
}
This method is called before the callback runs in order to prepare and setup the permission scope.
public void prepare ( ) |
public function prepare()
{
$this->updateApplicationConfig();
$this->logFixture = $this->createCmsLog([]);
$this->blockFixture = $this->createCmsBlockFixture([]);
$this->navItemPageBlockItemFixture = $this->createCmsNavItemPageBlockItemFixture([]);
$this->ngRestLogFixture = $this->createAdminNgRestLogFixture();
$this->langFixture = $this->createAdminLangFixture([
1 => [
'id' => 1,
'short_code' => 'en',
'name' => 'English',
'is_default' => 1,
'is_deleted' => 0,
]
]);
}
Defined in: luya\testsuite\scopes\BaseScope::run()
Run a given function inside a permission scope.
public static mixed run ( yii\base\Application $app, callable $fn, callable $invoke = null ) | ||
$app | \luya\testsuite\scopes\yii\base\Application | |
$fn | callable |
The function to run. |
$invoke | callable |
The function to configure the scope. |
public static function run(Application $app, callable $fn, callable $invoke = null)
{
$scope = new static($app, $fn, $invoke);
$scope->configure();
$scope->prepare();
$response = $scope->runCallable($scope);
$scope->cleanup();
return $response;
}
Defined in: luya\testsuite\scopes\BaseScope::runCallable()
Run the provided callable function
public mixed runCallable ( luya\testsuite\scopes\BaseScope $scope ) | ||
$scope | luya\testsuite\scopes\PermissionScope |
public function runCallable(BaseScope $scope)
{
return call_user_func_array($this->_fn, [$scope]);
}
Method to update the application config with requrired componenets.
public void updateApplicationConfig ( ) |
public function updateApplicationConfig()
{
$this->getApp()->set('session',['class' => 'luya\testsuite\components\DummySession']);
$this->getApp()->set('cache', ['class' => 'yii\caching\DummyCache']);
$this->getApp()->set('db', ['class' => 'yii\db\Connection', 'dsn' => 'sqlite::memory:']);
}