1. Go to this page and download the library: Download lostkobrakai/pw-test-helper library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
lostkobrakai / pw-test-helper example snippets
use LostKobrakai\TestHelpers\Kahlan\SetupInclude;
// Create a unique db name for the testruns
$dbName = 'pw_' . md5(__DIR__ . time());
// Path to the ProcessWire root folder
$path = __DIR__;
// Browsertest settings
$browserSettings = [
// Send db name as request header
'database' => $dbName,
// Allow for relative urls in tests
'rootUrl' => 'http://db_tests.valet/'
];
// Add DB integration
/** @noinspection PhpIncludeInspection */
it('should find the processwire homepage', function() {
expect($this->processwire->pages->get('/')->id)->toBe(1);
});
it('should be able to load the page for inspection', function() {
$this->browser->visit('/');
// Check the page for specific text or elements
expect($this->browser->element('h1')->getText())->toBe('Home');
// Kahlan does have support for async expectations
// It waits until an optional timeout to see the text
waitsFor(function() {
return $this->browser->page();
})->toContain('Home');
});
/**
* Change db for browser testings
*/
if(isset($_SERVER['HTTP_X_TEST_WITH_DB']) && $_SERVER['HTTP_X_TEST_WITH_DB']){
$config->dbName = $_SERVER['HTTP_X_TEST_WITH_DB'];
}