Class luya\testsuite\scopes\PageScope

Inheritanceluya\testsuite\scopes\PageScope » luya\testsuite\scopes\BaseScope
Uses Traitsluya\testsuite\traits\CmsDatabaseTableTrait
Available since version1.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

Hide inherited 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

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Permission Scope contstructor. luya\testsuite\scopes\BaseScope
addBlock() Add a cms block to the list of blocks. luya\testsuite\scopes\PageScope
addBlockAndContent() Combination of add block and add content. luya\testsuite\scopes\PageScope
addContent() Add the content for a given block id. luya\testsuite\scopes\PageScope
cleanup() Clean up tables and fixtures. luya\testsuite\scopes\PageScope
cleanupFixture() A helper method to cleanup fixtures. luya\testsuite\scopes\BaseScope
configure() Configured is used before prepare which allows you to configure the current scope. luya\testsuite\scopes\BaseScope
createCmsBlockFixture() Create Cms Block Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsBlockGroupFixture() Create Cms Block Group Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsLayoutFixture() Create Cms Layout Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsLog() Create Cms Log Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavContainerFixture() Create Cms Nav Container Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavFixture() Create Cms Nav Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavItemFixture() Create Cms Nav Item Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavItemModuleFixture() Create Cms Nav Item Module Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavItemPageBlockItemFixture() Create Cms Nav Item Page Block Item Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavItemPageFixture() Create Cms Nav Item Page Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavItemRedirectFixture() Create Cms Nav Item Redirect Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsNavPermissionFixture() Create Cms Nav Permissions Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsPropertyFixture() Create Cms Property Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsRedirectFixture() Create Cms Redirect Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createCmsWebsiteFixture() Create Cms Website Fixture luya\testsuite\traits\CmsDatabaseTableTrait
createPage() Create a CMS Page with title, path to layout file and layout file placholders. luya\testsuite\scopes\PageScope
getApp() Returns the Application instance. luya\testsuite\scopes\BaseScope
getDatabaseComponent() Returns the application database componenet. luya\testsuite\scopes\PageScope
prepare() This method is called before the callback runs in order to prepare and setup the permission scope. luya\testsuite\scopes\PageScope
run() Run a given function inside a permission scope. luya\testsuite\scopes\BaseScope
runCallable() Run the provided callable function luya\testsuite\scopes\BaseScope
updateApplicationConfig() Method to update the application config with requrired componenets. luya\testsuite\scopes\PageScope

Property Details

Hide inherited properties

$blockFixture protected property
protected $blockFixture null
$langFixture protected property
protected $langFixture null
$layoutFixture protected property
protected $layoutFixture null
$logFixture protected property
protected $logFixture null
$navContainerFixture protected property
protected $navContainerFixture null
$navFixture protected property
protected $navFixture null
$navItemFixture protected property
protected $navItemFixture null
$navItemModuleFixture protected property
protected $navItemModuleFixture null
$navItemPageBlockItemFixture protected property
$navItemPageFixture protected property
protected $navItemPageFixture null
$navItemRedirectFixture protected property
protected $navItemRedirectFixture null
$ngRestLogFixture protected property
protected $ngRestLogFixture null
$pageId public property

The page id which will be created.

public integer $pageId 1
$pagePropertyFixtureData public property (available since version 1.0.22)

An array with fixture data for page properties

$propertyFixture protected property
protected $propertyFixture null
$websiteFixture protected property
protected $websiteFixture null

Method Details

Hide inherited methods

__construct() public method

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;    
}

            
addBlock() public method

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;
}

            
addBlockAndContent() public method

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);
}

            
addContent() public method

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;
}

            
cleanup() public method

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);
}

            
cleanupFixture() public method

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();
    }
}

            
configure() public method

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]);
    }
}

            
createCmsBlockFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsBlockFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsBlockFixture(array $fixtureData = [])
{
    return new NgRestModelFixture([
        'modelClass' => Block::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsBlockGroupFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsBlockGroupFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsBlockGroupFixture(array $fixtureData = [])
{
    return new NgRestModelFixture([
        'modelClass' => BlockGroup::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsLayoutFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsLayoutFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsLayoutFixture(array $fixtureData = [])
{
    return new NgRestModelFixture([
        'modelClass' => Layout::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsLog() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsLog ( array $fixtureData = [] )
$fixtureData array

                public function createCmsLog(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => Log::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsNavContainerFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavContainerFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavContainerFixture(array $fixtureData = [])
{
    return new NgRestModelFixture([
        'modelClass' => NavContainer::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsNavFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => Nav::class,
        'fixtureData' => $fixtureData
    ]);
}

            
createCmsNavItemFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavItemFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavItemFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => NavItem::class,
        'fixtureData' => $fixtureData
    ]);
}

            
createCmsNavItemModuleFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavItemModuleFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavItemModuleFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => NavItemModule::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsNavItemPageBlockItemFixture() public method

Defined in: luya\testsuite\traits\CmsDatabaseTableTrait::createCmsNavItemPageBlockItemFixture()

Create Cms Nav Item Page Block Item Fixture

public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavItemPageBlockItemFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavItemPageBlockItemFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => NavItemPageBlockItem::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsNavItemPageFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavItemPageFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavItemPageFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => NavItemPage::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsNavItemRedirectFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavItemRedirectFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavItemRedirectFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => NavItemRedirect::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsNavPermissionFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsNavPermissionFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsNavPermissionFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => NavPermission::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsPropertyFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsPropertyFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsPropertyFixture(array $fixtureData = [])
{
    return new ActiveRecordFixture([
        'modelClass' => Property::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsRedirectFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsRedirectFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsRedirectFixture(array $fixtureData = [])
{
    return new NgRestModelFixture([
        'modelClass' => Redirect::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createCmsWebsiteFixture() public method
public luya\testsuite\fixtures\ActiveRecordFixture createCmsWebsiteFixture ( array $fixtureData = [] )
$fixtureData array

                public function createCmsWebsiteFixture(array $fixtureData = [])
{
    return new NgRestModelFixture([
        'modelClass' => Website::class,
        'fixtureData' => $fixtureData,
    ]);
}

            
createPage() public method

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: @app/views/cmslayouts/main.php.

$layoutPlaceholders array

An array only containing the available placeholders like: ['content', 'sidebar'].

$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;
}

            
getApp() public method

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;
}

            
getDatabaseComponent() public method

Returns the application database componenet.

public yii\db\Connection getDatabaseComponent ( )

                public function getDatabaseComponent()
{
    return $this->getApp()->db;
}

            
prepare() public method

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,
        ]
    ]);
}

            
run() public static method

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;
}

            
runCallable() public method

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]);
}

            
updateApplicationConfig() public method

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:']);
}