damianlewis / oc-octobertesting-plugin
Enables Laravel's testing frameworks for October CMS
Installs: 221
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 1
Open Issues: 0
Type:october-plugin
Requires
- php: >=7.0
- composer/installers: ~1.0
- laravel/dusk: ~2.0
- october/system: >=1.0.420
This package is auto-updated.
Last update: 2025-02-16 01:12:37 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' ]);