Skip to content

Commit

Permalink
MDL-46891 Behat: Added support for behat 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajesh Taneja committed Mar 11, 2016
1 parent e8952c5 commit 42ad096
Show file tree
Hide file tree
Showing 48 changed files with 266 additions and 381 deletions.
3 changes: 1 addition & 2 deletions admin/tests/behat/behat_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../lib/behat/behat_field_manager.php');

use Behat\Behat\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;

/**
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/behat/tests/manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,10 @@ public function test_config_file_contents() {
// YAML decides when is is necessary to wrap strings between single quotes, so not controlled
// values like paths should not be asserted including the key name as they would depend on the
// directories values.
$this->assertContains($CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'behat' . DIRECTORY_SEPARATOR . 'features', $contents);
$this->assertContains($CFG->dirroot, $contents);

// Not quoted strings.
$this->assertContains('micarro: /me/lo/robaron', $contents);
$this->assertContains('class: behat_init_context', $contents);

// YAML uses single quotes to wrap URL strings.
$this->assertContains("base_url: '" . $CFG->behat_wwwroot . "'", $contents);
Expand Down
14 changes: 7 additions & 7 deletions admin/tool/langimport/tests/behat/manage_langpacks.feature
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ Feature: Manage language packs
Scenario: Install language pack
Given I log in as "admin"
And I navigate to "Language packs" node in "Site administration > Language"
When I set the field "Available language packs" to "English - Pirate (en_ar)"
When I set the field "Available language packs" to "en_ar"
And I press "Install selected language pack(s)"
Then I should see "Language pack 'en_ar' was successfully installed"
And the "Installed language packs" select box should contain "English - Pirate (en_ar)"
And the "Installed language packs" select box should contain "en_ar"
And I navigate to "Live logs" node in "Site administration > Reports"
And I should see "The language pack 'en_ar' was installed."
And I log out
Expand All @@ -35,14 +35,14 @@ Feature: Manage language packs
Scenario: Try to uninstall language pack
Given I log in as "admin"
And I navigate to "Language packs" node in "Site administration > Language"
And I set the field "Available language packs" to "English - Pirate (en_ar)"
And I set the field "Available language packs" to "en_ar"
And I press "Install selected language pack(s)"
When I set the field "Installed language packs" to "English - Pirate (en_ar)"
When I set the field "Installed language packs" to "en_ar"
And I press "Uninstall selected language pack(s)"
And I press "Continue"
Then I should see "Language pack 'en_ar' was uninstalled"
And the "Installed language packs" select box should not contain "English - Pirate (en_ar)"
And the "Available language packs" select box should contain "English - Pirate (en_ar)"
And the "Installed language packs" select box should not contain "en_ar"
And the "Available language packs" select box should contain "en_ar"
And I navigate to "Live logs" node in "Site administration > Reports"
And I should see "The language pack 'en_ar' was removed."
And I should see "Language pack uninstalled"
Expand All @@ -51,7 +51,7 @@ Feature: Manage language packs
Scenario: Try to uninstall English language pack
Given I log in as "admin"
And I navigate to "Language packs" node in "Site administration > Language"
When I set the field "Installed language packs" to "English (en)"
When I set the field "Installed language packs" to "en"
And I press "Uninstall selected language pack(s)"
Then I should see "The English language pack cannot be uninstalled."
And I navigate to "Live logs" node in "Site administration > Reports"
Expand Down
4 changes: 2 additions & 2 deletions auth/tests/behat/behat_auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given;
use Behat\Behat\Context\Step\When as When;
use Moodle\BehatExtension\Context\Step\Given as Given;
use Moodle\BehatExtension\Context\Step\When as When;

/**
* Log in log out steps definitions.
Expand Down
9 changes: 2 additions & 7 deletions backup/util/ui/tests/behat/behat_backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ public function i_restore_backup_into_course_using_this_options($backupfilename,
"/descendant::div[@class='restore-course-search']" .
"/descendant::tr[contains(., $existingcourse)]" .
"/descendant::input[@type='radio']");
$radionode->check();
$radionode->click();

// Pressing the continue button of the restore into an existing course section.
Expand Down Expand Up @@ -250,7 +249,6 @@ public function i_restore_backup_into_a_new_course_using_this_options($backupfil
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-new-course ')]" .
"/descendant::div[@class='restore-course-search']" .
"/descendant::input[@type='radio']");
$radionode->check();
$radionode->click();

// Pressing the continue button of the restore into an existing course section.
Expand Down Expand Up @@ -280,7 +278,6 @@ public function i_merge_backup_into_the_current_course($backupfilename, $options
// Merge without deleting radio option.
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='1']");
$radionode->check();
$radionode->click();

// Pressing the continue button of the restore merging section.
Expand Down Expand Up @@ -310,7 +307,6 @@ public function i_merge_backup_into_current_course_deleting_its_contents($backup
// Delete contents radio option.
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), 'bcs-current-course')]" .
"/descendant::input[@type='radio'][@name='target'][@value='0']");
$radionode->check();
$radionode->click();

// Pressing the continue button of the restore merging section.
Expand Down Expand Up @@ -419,8 +415,6 @@ protected function get_step_options($options, $step) {
return;
}

$pageoptions = clone $options;

$rows = $options->getRows();
$newrows = array();
foreach ($rows as $k => $data) {
Expand All @@ -433,7 +427,8 @@ protected function get_step_options($options, $step) {
$newrows[] = $data;
}
}
$pageoptions->setRows($newrows);
$pageoptions = new TableNode($newrows);

return $pageoptions;
}

Expand Down
15 changes: 7 additions & 8 deletions behat.yml.dist
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
default:
paths:
features: lib/behat/features
bootstrap: lib/behat/features/bootstrap
context:
class: behat_init_context
suites:
default:
paths: { }
contexts: { }
extensions:
Behat\MinkExtension\Extension:
Behat\MinkExtension:
base_url: 'http://localhost:8000'
goutte: null
selenium2: null
Moodle\BehatExtension\Extension:
features: { }
Moodle\BehatExtension:
moodledirroot: /Should/Change/To/Moodle/www/dir
steps_definitions: { }
2 changes: 1 addition & 1 deletion blocks/tests/behat/behat_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given;
use Moodle\BehatExtension\Context\Step\Given as Given;

/**
* Blocks management steps definitions.
Expand Down
2 changes: 1 addition & 1 deletion calendar/tests/behat/behat_calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
// NOTE: no MOODLE_INTERNAL used, this file may be required by behat before including /config.php.
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given;
use Moodle\BehatExtension\Context\Step\Given as Given;
use Behat\Gherkin\Node\TableNode as TableNode;

/**
Expand Down
2 changes: 1 addition & 1 deletion cohort/tests/behat/behat_cohort.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given;
use Moodle\BehatExtension\Context\Step\Given as Given;

/**
* Steps definitions for cohort actions.
Expand Down
4 changes: 2 additions & 2 deletions completion/tests/behat/behat_completion.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given,
Behat\Behat\Context\Step\Then,
use Moodle\BehatExtension\Context\Step\Given,
Moodle\BehatExtension\Context\Step\Then,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;

/**
Expand Down
11 changes: 9 additions & 2 deletions config-dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,8 +683,15 @@
// )
// ),
// 'Mac-Firefox' => array(
// 'suites' => array (
// 'default' => array(
// 'filters' => array(
// 'tags' => '~@_file_upload'
// ),
// ),
// ),
// 'extensions' => array(
// 'Behat\MinkExtension\Extension' => array(
// 'Behat\MinkExtension' => array(
// 'selenium2' => array(
// 'browser' => 'firefox',
// 'capabilities' => array(
Expand All @@ -697,7 +704,7 @@
// ),
// 'Mac-Safari' => array(
// 'extensions' => array(
// 'Behat\MinkExtension\Extension' => array(
// 'Behat\MinkExtension' => array(
// 'selenium2' => array(
// 'browser' => 'safari',
// 'capabilities' => array(
Expand Down
8 changes: 4 additions & 4 deletions course/tests/behat/behat_course.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given,
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode,
Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\DriverException as DriverException,
Expand Down Expand Up @@ -97,7 +97,7 @@ public function i_create_a_course_with(TableNode $table) {
unset($rows[$key]);
}
}
$table->setRows($rows);
$table = new TableNode($rows);

// Adding a forced wait until editors are loaded as otherwise selenium sometimes tries clicks on the
// format field when the editor is being rendered and the click misses the field coordinates.
Expand Down Expand Up @@ -585,7 +585,7 @@ public function activity_should_be_visible($activityname) {

// The 'Hide' button should be available.
$nohideexception = new ExpectationException('"' . $activityname . '" don\'t have a "' . get_string('hide') . '" icon', $this->getSession());
$this->find('named', array('link', get_string('hide')), $nohideexception, $activitynode);
$this->find('named_partial', array('link', get_string('hide')), $nohideexception, $activitynode);
}
}

Expand All @@ -611,7 +611,7 @@ public function activity_should_be_hidden($activityname) {

// Also 'Show' icon.
$noshowexception = new ExpectationException('"' . $activityname . '" don\'t have a "' . get_string('show') . '" icon', $this->getSession());
$this->find('named', array('link', get_string('show')), $noshowexception, $activitynode);
$this->find('named_partial', array('link', get_string('show')), $noshowexception, $activitynode);

} else {

Expand Down
1 change: 0 additions & 1 deletion course/tests/behat/category_resort.feature
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ Feature: Test we can resort categories in the management interface.
And I should see the "Course categories and courses" management page
And I click on <sortby> action for "Master cat" in management category listing
And a new page should have loaded since I started watching
And I start watching to see if a new page loads
And I should see the "Course categories and courses" management page
And I should see category listing <cat1> before <cat2>
And I should see category listing <cat2> before <cat3>
Expand Down
1 change: 0 additions & 1 deletion course/tests/behat/course_resort.feature
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ Feature: Test we can resort course in the management interface.
And I should see "Sort by Course time created descending" in the ".course-listing-actions" "css_element"
And I click on <sortby> "link" in the ".course-listing-actions" "css_element"
And a new page should have loaded since I started watching
And I start watching to see if a new page loads
And I should see the "Course categories and courses" management page
And I should see course listing <course1> before <course2>
And I should see course listing <course2> before <course3>
Expand Down
2 changes: 1 addition & 1 deletion enrol/tests/behat/behat_enrol.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given,
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');

use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Behat\Context\Step\Given as Given,
Behat\Behat\Context\Step\When as When,
Behat\Behat\Context\Step\Then as Then,
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When,
Moodle\BehatExtension\Context\Step\Then as Then,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\ExpectationException as ExpectationException;

Expand Down
13 changes: 10 additions & 3 deletions grade/grading/form/rubric/tests/behat/behat_gradingform_rubric.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@
require_once(__DIR__ . '/../../../../../../lib/behat/behat_base.php');

use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Behat\Context\Step\Given as Given,
Behat\Behat\Context\Step\When as When,
Behat\Behat\Context\Step\Then as Then,
Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Exception\ExpectationException as ExpectationException;

Expand Down Expand Up @@ -107,6 +105,15 @@ public function i_define_the_following_rubric(TableNode $rubric) {
}
}

// Remove empty criterion, as TableNode might contain them to make table rows equal size.
$newcriterion = array();
foreach ($criterion as $k => $c) {
if (!empty($c)) {
$newcriterion[$k] = $c;
}
}
$criterion = $newcriterion;

// Checking the number of cells.
if (count($criterion) % 2 === 0) {
throw new ExpectationException(
Expand Down
6 changes: 3 additions & 3 deletions grade/grading/tests/behat/behat_grading.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Behat\Context\Step\Given as Given,
Behat\Behat\Context\Step\When as When;
Moodle\BehatExtension\Context\Step\Given as Given,
Moodle\BehatExtension\Context\Step\When as When;

/**
* Generic grading methods step definitions.
Expand Down Expand Up @@ -93,7 +93,7 @@ public function i_go_to_activity_advanced_grading_page($userfullname, $activityn

// Shortcut in case we already are in the grading page.
$usergradetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($usergradetext);
if ($this->getSession()->getPage()->find('named', array('link', $usergradetextliteral))) {
if ($this->getSession()->getPage()->find('named_partial', array('link', $usergradetextliteral))) {
return $gradeuserstep;
}

Expand Down
4 changes: 2 additions & 2 deletions grade/report/grader/tests/behat/behat_gradereport_grader.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

require_once(__DIR__ . '/../../../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given,
Behat\Behat\Context\Step\Then,
use Moodle\BehatExtension\Context\Step\Given,
Moodle\BehatExtension\Context\Step\Then,
Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;

Expand Down
2 changes: 1 addition & 1 deletion grade/tests/behat/behat_grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Given as Given,
use Moodle\BehatExtension\Context\Step\Given as Given,
Behat\Gherkin\Node\TableNode as TableNode;

class behat_grade extends behat_base {
Expand Down
2 changes: 1 addition & 1 deletion group/tests/behat/behat_groups.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

require_once(__DIR__ . '/../../../lib/behat/behat_base.php');

use Behat\Behat\Context\Step\Then;
use Moodle\BehatExtension\Context\Step\Then;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;

/**
Expand Down
Loading

0 comments on commit 42ad096

Please sign in to comment.