Abstract Class luya\testsuite\cases\CmsBlockGroupTestCase

Inheritanceluya\testsuite\cases\CmsBlockGroupTestCase » luya\testsuite\cases\WebApplicationTestCase » luya\testsuite\cases\BaseTestSuite » Yoast\PHPUnitPolyfills\TestCases\TestCase
Available since version1.0.11

Class CmsBlockGroupTestCase

Testing a cms block group for the admin.

Example usage: `php namespace cmstests\src\frontend\blockgroups;

use luya\testsuite\cases\CmsBlockGroupTestCase

class ProjectGroupTest extends CmsBlockGroupTestCase {

 public $blockGroupClass = 'luya\cms\frontend\blockgroup\ProjectGroup';

 public $blockGroupIdentifier = 'project-group';

} `

Public Methods

Hide inherited methods

Method Description Defined By
afterSetup() Method which is executed after the setUp() method in order to trigger post setup functions. luya\testsuite\cases\CmsBlockGroupTestCase
assertContainsNoSpace() Assert Contains without spaces but with newlines. luya\testsuite\cases\BaseTestSuite
assertContainsTrimmed() Same as assertContains but trims the needle and haystack content in order to compare. luya\testsuite\cases\BaseTestSuite
assertSameNoSpace() This assert Same option allows you to compare two strings but removing spaces and tabes, so its more easy to work with readable contents but better comparing. luya\testsuite\cases\BaseTestSuite
assertSameTrimmed() Assert Same but trim content (remove, double spaces, tabs and newlines. luya\testsuite\cases\BaseTestSuite
beforeSetup() Method which is executed before the setUp() method in order to inject data on before Setup. luya\testsuite\cases\WebApplicationTestCase
beforeTearDown() This method is triggered before the application test case tearDown() method is running. luya\testsuite\cases\BaseTestSuite
bootApplication() luya\testsuite\cases\WebApplicationTestCase
fixture() Get Fixture Object luya\testsuite\cases\BaseTestSuite
fixtures() Defines a list of fixtures classes which can be loaded. luya\testsuite\cases\BaseTestSuite
getConfigArray() Provide configurtion array. luya\testsuite\cases\CmsBlockGroupTestCase
invokeMethod() Call a private or protected method from an object and return the value. luya\testsuite\cases\BaseTestSuite
setupFixtures() Create all fixtures from fixtures() list. luya\testsuite\cases\BaseTestSuite
tearDownFixtures() Run cleanup() on all loaded fixtures. luya\testsuite\cases\BaseTestSuite
testGetPostition() Tests if the position is ok luya\testsuite\cases\CmsBlockGroupTestCase
testIdentifier() Tests if the identifier is correct luya\testsuite\cases\CmsBlockGroupTestCase
testIsBlockGroup() Test if this block group is an instance of \luya\cms\base\BlockGroup luya\testsuite\cases\CmsBlockGroupTestCase
testLabel() Test if there is a label luya\testsuite\cases\CmsBlockGroupTestCase

Protected Methods

Hide inherited methods

Method Description Defined By
set_up() luya\testsuite\cases\BaseTestSuite
tear_down() luya\testsuite\cases\BaseTestSuite
trimContent() No Spaces and No Newline Trims the given text. Remove whitespaces, tabs and other chars in order to compare readable formated texts. luya\testsuite\cases\BaseTestSuite
trimSpaces() No Spaces with Newline luya\testsuite\cases\BaseTestSuite

Property Details

Hide inherited properties

$blockGroup public property
public $blockGroup null
$blockGroupClass public property

The path to the block group tested.

public string $blockGroupClass null
$blockGroupIdentifier public property

The used identifier

Method Details

Hide inherited methods

afterSetup() public method (available since version 1.0.2)

Method which is executed after the setUp() method in order to trigger post setup functions.

Make sure to call the parent afterSetup() method when overwriting this method.

public void afterSetup ( )

                public function afterSetup()
{
    parent::afterSetup();
    if (!$this->blockGroupClass) {
        throw new InvalidConfigException("The 'blockGroupClass' property can not be empty.");
    }
    if (!$this->blockGroupIdentifier) {
        throw new InvalidConfigException("The 'blockGroupIdentifier' property can not be empty.");
    }
    $class = $this->blockGroupClass;
    $this->blockGroup = new $class();
}

            
assertContainsNoSpace() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::assertContainsNoSpace()

Assert Contains without spaces but with newlines.

public boolean assertContainsNoSpace ( $needle, $haystack )
$needle string
$haystack string

                public function assertContainsNoSpace($needle, $haystack)
{
    return $this->assertStringContainsString($this->trimSpaces($needle), $this->trimSpaces($haystack));
}

            
assertContainsTrimmed() public method

Defined in: luya\testsuite\cases\BaseTestSuite::assertContainsTrimmed()

Same as assertContains but trims the needle and haystack content in order to compare.

This will also remove newlines.

public boolean assertContainsTrimmed ( $needle, $haystack )
$needle string
$haystack string

                public function assertContainsTrimmed($needle, $haystack)
{
    return self::assertStringContainsString($this->trimContent($needle), $this->trimContent($haystack));
}

            
assertSameNoSpace() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::assertSameNoSpace()

This assert Same option allows you to compare two strings but removing spaces and tabes, so its more easy to work with readable contents but better comparing.

This wont remove new lines.

public boolean assertSameNoSpace ( $needle, $haystack )
$needle string
$haystack string

                public function assertSameNoSpace($needle, $haystack)
{
    return $this->assertSame($this->trimSpaces($needle), $this->trimSpaces($haystack));
}

            
assertSameTrimmed() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::assertSameTrimmed()

Assert Same but trim content (remove, double spaces, tabs and newlines.

public boolean assertSameTrimmed ( $needle, $haystack )
$needle string
$haystack string

                public function assertSameTrimmed($needle, $haystack)
{
    return $this->assertSame($this->trimContent($needle), $this->trimContent($haystack));
}

            
beforeSetup() public method

Defined in: luya\testsuite\cases\WebApplicationTestCase::beforeSetup()

Method which is executed before the setUp() method in order to inject data on before Setup.

Make sure to call the parent beforeSetup() method when overwriting this method.

See also luya\testsuite\cases\BaseTestSuite::beforeSetup().

public void beforeSetup ( )

                public function beforeSetup()
{
    parent::beforeSetup();
    
    $_SERVER['SCRIPT_FILENAME'] = 'index.php';
    $_SERVER['SCRIPT_NAME'] =  '/index.php';
    $_SERVER['REQUEST_URI'] = '/';
}

            
beforeTearDown() public method (available since version 1.0.2)

Defined in: luya\testsuite\cases\BaseTestSuite::beforeTearDown()

This method is triggered before the application test case tearDown() method is running.

public void beforeTearDown ( )

                public function beforeTearDown()
{
}

            
bootApplication() public method (available since version 1.0.2)
public void bootApplication ( luya\base\Boot $boot )
$boot luya\base\Boot

                public function bootApplication(Boot $boot)
{
    $boot->applicationWeb();
}

            
fixture() public method

Defined in: luya\testsuite\cases\BaseTestSuite::fixture()

Get Fixture Object

public luya\testsuite\fixtures\ActiveRecordFixture fixture ( $fixtureClass )
$fixtureClass string

                public function fixture($fixtureClass)
{
    if (is_array($this->_fixtures)) {
        return array_key_exists($fixtureClass, $this->_fixtures) ? $this->_fixtures[$fixtureClass] : false;
    }
    return false;
}

            
fixtures() public method (available since version 1.1.0)

Defined in: luya\testsuite\cases\BaseTestSuite::fixtures()

Defines a list of fixtures classes which can be loaded.

Example fixtures list:

public function fixtures()
{
   return [
       'app\fixtures\MyTestFixture',
       MySuperFixture::class,
   ];
}
public array fixtures ( )

                public function fixtures()
{
    return [];
}

            
getConfigArray() public method

Provide configurtion array.

This method can be overwritten if adjustments are needed. In most cases this will not be needed, therefore a default config is provided

public void getConfigArray ( )

                public function getConfigArray()
{
    return [
        'id' => 'blockGroupTest',
        'basePath' => dirname(__DIR__),
        'components' => [
            'urlManager' => [
                'cache' => null,
            ]
        ]
    ];
}

            
invokeMethod() public method (available since version 1.0.8)

Defined in: luya\testsuite\cases\BaseTestSuite::invokeMethod()

Call a private or protected method from an object and return the value.

public function testProtectedMethod()
{
    // assuming MyObject has a protected method like:
    // protected function hello($title)
    // {
    //     return $title;
    // }
    $object = new MyObject();

    $this->assertSame('Hello World', $this->invokeMethod($object, 'hello', ['Hello World']));
}
public mixed invokeMethod ( &$object, $methodName, array $parameters = [] )
$object object

The object the method exists from.

$methodName string

The name of the method which should be called.

$parameters array

An array of paremters which should be passed to the method.

                public function invokeMethod(&$object, $methodName, array $parameters = [])
{
    $reflection = new \ReflectionClass(get_class($object));
    $method = $reflection->getMethod($methodName);
    $method->setAccessible(true);
    return $method->invokeArgs($object, $parameters);
}

            
set_up() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::set_up()

See also \PHPUnit\Framework\TestCase::setUp().

protected void set_up ( )

                protected function set_up() {
    parent::set_up();
    $this->beforeSetup();
    
    $boot = new Boot();
    $boot->setConfigArray($this->getConfigArray());
    $boot->mockOnly = true;
    $boot->setBaseYiiFile('vendor/yiisoft/yii2/Yii.php');
    $this->bootApplication($boot);
    $this->boot = $boot;
    $this->app = $boot->app;
    
    $this->afterSetup();
    $this->setupFixtures();
}

            
setupFixtures() public method (available since version 1.1.0)

Defined in: luya\testsuite\cases\BaseTestSuite::setupFixtures()

Create all fixtures from fixtures() list.

public void setupFixtures ( )

                public function setupFixtures()
{
    if ($this->_fixtures === null) {
        $loadedFixtures = [];
        foreach ($this->fixtures() as $fixtureClass) {
            $loadedFixtures[$fixtureClass] = Yii::createObject($fixtureClass);
        }
        $this->_fixtures = $loadedFixtures;
    }
}

            
tearDownFixtures() public method (available since version 1.1.0)

Defined in: luya\testsuite\cases\BaseTestSuite::tearDownFixtures()

Run cleanup() on all loaded fixtures.

public void tearDownFixtures ( )

                public function tearDownFixtures()
{
    if (is_array($this->_fixtures)) {
        /** @var ActiveRecordFixture $object */
        foreach ($this->_fixtures as $object) {
            $object->cleanup();
        }
    }
}

            
tear_down() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::tear_down()

See also \PHPUnit\Framework\TestCase::tearDown().

protected void tear_down ( )

                protected function tear_down() {
    // Any clean up needed related to `set_up()`.
    parent::tear_down();
    $this->beforeTearDown();
    $this->tearDownFixtures();
    unset($this->app, $this->boot);
}

            
testGetPostition() public method

Tests if the position is ok

public void testGetPostition ( )

                public function testGetPostition()
{
    $this->assertTrue(0 <= $this->blockGroup->getPosition());
    $this->assertTrue(100 >= $this->blockGroup->getPosition());
    return true;
}

            
testIdentifier() public method

Tests if the identifier is correct

public void testIdentifier ( )

                public function testIdentifier()
{
    $this->assertNotEmpty($this->blockGroup->identifier());
    $this->assertSame($this->blockGroupIdentifier, $this->blockGroup->identifier());
    return true;
}

            
testIsBlockGroup() public method

Test if this block group is an instance of \luya\cms\base\BlockGroup

public void testIsBlockGroup ( )

                public function testIsBlockGroup()
{
    $this->assertTrue($this->blockGroup instanceof BlockGroup);
    return true;
}

            
testLabel() public method

Test if there is a label

public void testLabel ( )

                public function testLabel()
{
    $this->assertNotEmpty($this->blockGroup->label());
    return true;
}

            
trimContent() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::trimContent()

No Spaces and No Newline Trims the given text. Remove whitespaces, tabs and other chars in order to compare readable formated texts.

protected string trimContent ( $text )
$text string
return string

The trimmed text.

                protected function trimContent($text)
{
    return str_replace(['> ', ' <'], ['>', '<'], trim(preg_replace('/\s+/', ' ', $text)));
}

            
trimSpaces() protected method

Defined in: luya\testsuite\cases\BaseTestSuite::trimSpaces()

No Spaces with Newline

Removes tabs and spaces from a string. But keeps newlines.

protected string trimSpaces ( $text )
$text string

                protected function trimSpaces($text)
{
    $lines = null;
    foreach (preg_split("/((\r?\n)|(\r\n?))/", $text) as $line) {
        if (!empty($line)) {
            $lines .= $this->trimContent($line) . PHP_EOL;
        }
    }
    return $lines;
}