Enable first working behat tests

1.10.x
Yannick Warnier 11 years ago
parent 5a007ea747
commit 62eeb30c2e
  1. 8
      composer.json
  2. 9
      tests/behat.yml
  3. 91
      tests/features/bootstrap/FeatureContext.php
  4. 24
      tests/features/createUser.feature
  5. 14
      tests/features/login.feature

@ -66,8 +66,12 @@
"bower-asset/jqueryui-timepicker-addon": "1.5.*" "bower-asset/jqueryui-timepicker-addon": "1.5.*"
}, },
"require-dev": { "require-dev": {
"behat/behat": "2.4.*@stable", "behat/behat": "2.5.*@stable",
"behat/mink-extension": "*@stable" "behat/mink": "1.4.*@stable",
"behat/mink-extension": "*",
"behat/mink-goutte-driver": "*",
"behat/mink-selenium2-driver": "*"
}, },
"extra": { "extra": {
"branch-alias": { "branch-alias": {

@ -0,0 +1,9 @@
default:
extensions:
Behat\MinkExtension\Extension:
base_url: http://localhost
goutte: ~
selenium2: ~
paths:
features: features
bootstrap: %behat.paths.features%/bootstrap

@ -1,81 +1,48 @@
<?php <?php
use Behat\Behat\Context\Context; use Behat\Behat\Context\ClosuredContextInterface,
use Behat\Behat\Context\SnippetAcceptingContext; Behat\Behat\Context\TranslatedContextInterface,
use Behat\Gherkin\Node\PyStringNode; Behat\Behat\Context\BehatContext,
use Behat\Gherkin\Node\TableNode; Behat\Behat\Exception\PendingException;
/** use Behat\Gherkin\Node\PyStringNode,
* Defines application features from the specific context. Behat\Gherkin\Node\TableNode;
*/
class FeatureContext implements Context, SnippetAcceptingContext
{
/**
* Initializes context.
*
* Every scenario gets its own context instance.
* You can also pass arbitrary arguments to the
* context constructor through behat.yml.
*/
public function __construct()
{
}
/** use Behat\MinkExtension\Context\MinkContext;
* Check Chamilo is installed - otherwise try to install it
* @param BeforeSuiteScope $scope The context scope
* @BeforeSuite
*/
public static function prepare($scope)
{
// prepare system for test suite
// before it runs
require __DIR__.'/../../../main/inc/lib/api.lib.php';
$installed = apiIsSystemInstalled();
if ($installed['installed'] == 0) {
// Try to install Chamilo
//apiInstallChamilo();
} else {
// show version
}
require __DIR__.'/../../../main/inc/global.inc.php';
}
/** //
* @Given I am logged in // Require 3rd-party libraries here:
*/ //
public function iAmLoggedIn() // require_once 'PHPUnit/Autoload.php';
{ // require_once 'PHPUnit/Framework/Assert/Functions.php';
if (api_get_user_id() == 0) { //
throw new Exception('I am not connected as a user yet');
}
}
/** /**
* @Given I am an administrator * Features context.
*/ */
public function iAmAnAdministrator() class FeatureContext extends MinkContext
{ {
if (!api_is_platform_admin()) {
throw new Exception('I am not connected as an admin');
}
}
/** /**
* @When I create a user with e-mail :arg1 * Initializes context.
* Every scenario gets its own context object.
*
* @param array $parameters context parameters (set them up through behat.yml)
*/ */
public function iCreateAUserWithEMail($email) public function __construct(array $parameters)
{ {
throw new PendingException(); // Initialize your context here
} }
/** /**
* @Then the user should be added * @Given /^I am a platform administrator$/
*/ */
public function theUserShouldBeAdded() public function iAmAPlatformAdministrator()
{ {
throw new PendingException(); return array(
new \Behat\Behat\Context\Step\Given('I am on homepage'),
new \Behat\Behat\Context\Step\Given('I fill in "login" with "admin"'),
new \Behat\Behat\Context\Step\Given('I fill in "password" with "admin"'),
new \Behat\Behat\Context\Step\Given('I press "submitAuth"')
);
} }
} }

@ -1,11 +1,23 @@
@administration @administration
Feature: User creation as admin Feature: Users management as admin
In order to add users In order to add users
As an administrator As an administrator
I need to be able to create new users I need to be able to create new users
Scenario: Create a user with only user's e-mail Scenario: Create a user with only basic info
Given I am logged in Given I am a platform administrator
And I am an administrator And I am on "/main/admin/user_add.php"
When I create a user with e-mail "sam@example.com" When I fill in "firstname" with "Sammy"
Then the user should be added And I fill in "lastname" with "Marshall"
And I fill in "username" with "smarshall"
And I fill in "email" with "smarshall@example.com"
And I press "submit"
Then I should see "The user has been added"
Scenario: Search and delete a user
Given I am a platform administrator
And I am on "/main/admin/user_list.php"
And I fill in "keyword" with "smarshall"
And I press "submit"
When I follow "Delete"
Then I should see "The user has been deleted"

@ -0,0 +1,14 @@
# features/createUser.feature
@common
Feature: User login
In order to log in
As a registered user
I need to be able to enter my details in the form and get in
Scenario: Login as admin user successfully
Given I am on "/index.php"
When I fill in "login" with "admin"
And I fill in "password" with "admin"
And I press "submitAuth"
Then I should see "John Doe"
And I should see "Administration"
Loading…
Cancel
Save