Test your Drupal site
Testing
- TDD
- BDD
- RAD
- RUP
- other paradigm
Why Codeception?
-
Acceptance Testing
-
Functional Testing
- Support many features
- Selenium WebDriver integration
- Elements matched by name, CSS, XPath
- Symfony2, Laravel4, Yii, Phalcon, Zend Frameworkintegration
- PageObjects and StepObjects included
- BDD-style readable tests
- Powered by PHPUnit
- API testing: REST,SOAP,XML-RPC
- Facebook API testing
- Data Cleanup
- HTML, XML, TAP, JSON reports
- CodeCoverage and Remote CodeCoverage
- Parallel Execution
<?php
use \Codeception\Util\Stub;
class UserTest extends \Codeception\TestCase\Test
{
public function testUserSave() {
$user = Stub::make('User');
$user->setName('davert');
$this->assertEquals('davert', $user->getName());
$user->save();
$this->tester->seeInDatabase('users', array('name' => 'davert'));
}
}
?>
Unit
<?php
$I = new ApiTester($scenario);
$I->wantTo('create a new user by API');
$I->amHttpAuthenticated('davert','123456');
$I->haveHttpHeader('Content-Type','application/x-www-form-urlencoded');
$I->sendPOST('/users', array('name' => 'davert' ));
$I->seeResponseCodeIs(200);
$I->seeResponseIsJson();
$I->seeResponseContainsJson(array('result' => 'ok'));
?>
API testing
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('create wiki page');
$I->amOnPage('/');
$I->click('Pages');
$I->click('New');
$I->see('New Page');
$I->fillField('title', 'Hobbit');
$I->fillField('body', 'By Peter Jackson');
$I->click('Save');
$I->see('page created'); // notice generated
$I->see('Hobbit','h1'); // head of page of is our title
$I->seeInCurrentUrl('pages/hobbit');
$I->seeInDatabase('pages', array('title' => 'Hobbit'));
?>
Acceptance testing
<?php $scenario->group(['profile', 'address']); $I = new AcceptanceTester($scenario); $I->wantTo('Add new post address'); $I->login($I); $I->amOnPage('/user/addressbook'); $uid = $I->grabFromCurrentUrl('@/user/(\d+)/index/useraddress@si'); $I->amOnPage('/user/' . $uid . '/index/useraddress/create'); $I->seeCurrentUrlEquals('/user/' . $uid . '/index/useraddress/create'); $address = $I->get_address_fields_selectors_id(); $I->selectOption($address['region'], 'Архангельская область'); $I->fillField($address['postal_code'], '414009'); $I->fillField($address['city'], 'Астрахань'); $I->fillField($address['street'], 'Таганрогская'); $I->fillField($address['house'], '20'); $I->fillField($address['flat'], '150'); $I->click('Сохранить профиль'); $I->seeCurrentUrlEquals('/user/' . $uid . '/index/useraddress'); $I->see('Профиль сохранен'); $I->see('414009, Россия, Астрахань, Таганрогская, 20, 150');
Real Code
Quickstart for Drupal
composer require "codeception/codeception:*"
drush composer-manager require "codeception/codeception:*"
Install
Check version (2.1+)
vendor/bin/codecept --version
codecept bootstrap
vim codeception.yml
vim tests/selenium.suite.yml #set url
Init
Download & run Selenium
cd vendor/bin
wget http://selenium-release.storage.googleapis.com/2.46/selenium-server-standalone-2.46.0.jar
java -jar selenium-server-standalone-2.46.0.jar
Quickstart for Drupal
Quickstart for Drupal
Edit tests/selenium.suite.yml
Quickstart for Drupal
Run!
codecept run
codecept run --steps
codecept run -g profile
codecept run tests/selenium/ProfileAddressAddCept.php
Other stuff
#instead java -jar selenium-server-standalone-2.46.0.jar #use phantomjs --webdriver=4444
Old docs :(
# 1.x WebGuy, TestGuy, CodeGuy # 2.x AcceptanceTester, FunctionalTester, UnitTester
Useful links
Test your site
By vasilykraev
Test your site
- 1,832