damianlewis/octobertesting-plugin

This package is abandoned and no longer maintained. The author suggests using the damianlewis/oc-octobertesting-plugin package instead.

Enables Laravel's testing frameworks for October CMS

v1.0.1 2019-10-15 12:44 UTC

This package is auto-updated.

Last update: 2019-10-15 13:07:30 UTC


README

Enables the use of the Laravel testing frameworks within October CMS.

Usage

Installation

Install via Composer:

composer require damianlewis/oc-octobertesting-plugin --dev

Plugin Feature & Unit Tests

To test plugins, create a tests folder within the plugin base folder and copy the phpunit.xml file to this location, for example, /plugins/acme/blog/tests/phpunit.xml. Create sub folders for feature and unit tests, for example, /plugins/acme/blog/tests/feature/ and /plugins/acme/blog/tests/unit/. Then in the tests folders, create tests following the principles used for Laravel testing. Test suites have been configured within the phpunit.xml file for feature and unit tests.

When creating tests, use the alternative Tests\PluginTestCase class. This alternative class doesn't make use of an in memory database, allowing you to choose what database you wish to use for testing. See example below.

<?php

namespace Acme\Blog\Tests\Feature;

use Tests\PluginTestCase;

class ExampleTest extends PluginTestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

Laravel Dusk

To make use of Laravel Dusk with OctoberCMS, run the dusk:install Artisan command:

php artisan dusk:install

Then use Dusk as you would with Laravel, see Laravel Dusk. For example, to run tests from the CLI use the dusk Artisan command:

php artisan dusk

Authentication

To make use of the login and loginAs authentication methods, an object containing the login and password for the user is expected. To provide the default/admin user account, you can override the user method in the Tests\DuskTestCase class as follows:

<?php

namespace Tests;

use Laravel\Dusk\TestCase as BaseTestCase;
use Facebook\WebDriver\Chrome\ChromeOptions;
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;

abstract class DuskTestCase extends BaseTestCase
{
    use CreatesApplication;
    
    ...
    
    protected function user()
    {
        return (object)[
            'login' => 'admin',
            'password' => 'admin'
        ];
    }
}

Screenshots

To create browser screenshots add the --window-size argument to the ChromeOptions->addArguments method as shown below:

$options = (new ChromeOptions)->addArguments([
    '--disable-gpu',
    '--window-size=1280,1024',
    '--headless'
]);