Fix Behat tests

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent 284ee8af12
commit e278017851
  1. 109
      tests/features/bootstrap/FeatureContext.php
  2. 14
      tests/features/createCourse.feature
  3. 10
      tests/features/createUser.feature

@ -35,6 +35,7 @@ class FeatureContext extends MinkContext
$this->fillField('login', 'admin');
$this->fillField('password', 'admin');
$this->pressButton('submitAuth');
$this->getSession()->back();
}
/**
* @Given /^I am a session administrator$/
@ -119,11 +120,9 @@ class FeatureContext extends MinkContext
*/
public function courseExists($argument)
{
return array(
new Given('I am a platform administrator'),
new Given('I am on "/main/admin/course_list.php?keyword=' . $argument . '"'),
new Given('I should see "' . $argument . '"'),
);
$this->iAmAPlatformAdministrator();
$this->visit('/main/admin/course_list.php?keyword=' . $argument);
$this->assertPageContainsText($argument);
}
/**
* @Given /^course "([^"]*)" is deleted$/
@ -152,20 +151,16 @@ class FeatureContext extends MinkContext
*/
public function iAmOnCourseXHomepage($argument)
{
return array(
new Given('I am on "/main/course_home/course_home.php?cDir=' . $argument . '"'),
new Given('I should not see an ".alert-danger" element')
);
$this->visit('/main/course_home/course_home.php?cDir=' . $argument);
$this->assertElementNotOnPage('.alert-danger');
}
/**
* @Given /^I am a "([^"]*)" user$/
*/
public function iAmAXUser($argument)
{
return array(
new Given('I am on "/main/auth/profile.php"'),
new Given('the "language" field should contain "' . $argument . '"')
);
$this->visit('/main/auth/profile.php');
$this->assertFieldContains('language', $argument);
}
/**
@ -173,13 +168,13 @@ class FeatureContext extends MinkContext
*/
public function iAmLoggedAs($username)
{
return [
new Given('I am on "/index.php?logout=logout"'),
new Given('I am on homepage'),
new Given('I fill in "login" with "' . $username . '"'),
new Given('I fill in "password" with "' . $username . '"'),
new Given('I press "submitAuth"')
];
$this->visit('/index.php?logout=logout');
$this->iAmOnHomepage();
$this->fillFields(new \Behat\Gherkin\Node\TableNode([
['login', $username],
['password', $username]
]));
$this->pressButton('submitAuth');
}
/**
@ -202,13 +197,11 @@ class FeatureContext extends MinkContext
'is_my_friend' => 'friend'
]);
return array(
new Given('I am a platform administrator'),
new Given('I am on "' . $sendInvitationURL . '"'),
new Given('I am logged as "' . $friendUsername . '"'),
new Given('I am on "' . $acceptInvitationURL . '"'),
new Given('I am a platform administrator')
);
$this->iAmAPlatformAdministrator();
$this->visit($sendInvitationURL);
$this->iAmLoggedAs($friendUsername);
$this->visit($acceptInvitationURL);
$this->iAmAPlatformAdministrator();
}
/**
@ -216,18 +209,18 @@ class FeatureContext extends MinkContext
*/
public function iHaveAPublicPasswordProtectedCourse($code, $password)
{
return [
new Given('I am on "/main/admin/course_add.php"'),
new Given('I fill in "title" with "Password Protected"'),
new Given('I fill in "visual_code" with "' . $code . '"'),
new Given('I fill in "visibility" with "3"'),
new Given('I press "submit"'),
new Given('I am on "/main/course_info/infocours.php?cidReq=' . $code . '"'),
new Given('I should see "Course registration password"'),
new Given('I fill in "course_registration_password" with "' . $password . '"'),
new Given('I press "submit_save"'),
new Given('the "course_registration_password" field should contain "' . $password . '"')
];
$this->visit('/main/admin/course_add.php');
$this->fillFields(new \Behat\Gherkin\Node\TableNode([
['title', 'Password Protected'],
['visual_code', $code],
['visibility', 3]
]));
$this->pressButton('submit');
$this->visit('/main/course_info/infocours.php?cidReq=' . $code);
$this->assertPageContainsText('Course registration password');
$this->fillField('department_name', $password);
$this->pressButton('submit_save');
$this->assertFieldContains('department_name', $password);
}
/**
@ -235,10 +228,8 @@ class FeatureContext extends MinkContext
*/
public function iAmNotLogged()
{
return [
new Given('I am on "/index.php?logout=logout"'),
new Given('I am on homepage')
];
$this->visit('/index.php?logout=logout');
$this->visit('I am on homepage');
}
/**
@ -246,11 +237,9 @@ class FeatureContext extends MinkContext
*/
public function iInviteAFrienToASocialGroup($friendId, $groupId)
{
return [
new Step\Given('I am on "/main/social/group_invitation.php?id=' . $groupId . '"'),
new Step\When('I fill in "invitation[]" with "' . $friendId . '"'),
new Step\When('I press "submit"')
];
$this->visit('/main/social/group_invitation.php?id=' . $groupId);
$this->fillField('invitation[]', $friendId);
$this->pressButton('submit');
}
/**
@ -261,14 +250,12 @@ class FeatureContext extends MinkContext
*/
public function adminTopBarIsDisabled()
{
return [
new Step\Given('I am a platform administrator'),
new Step\Given('I am on "/main/admin/settings.php"'),
new Step\When('I fill in "search_field" with "show_admin_toolbar"'),
new Step\When('I press "submit_button"'),
new Step\When('I select "do_not_show" from "show_admin_toolbar"'),
new Step\When('I press "submit"')
];
$this->iAmAPlatformAdministrator();
$this->visit('/main/admin/settings.php');
$this->fillField('search_field', 'show_admin_toolbar');
$this->pressButton('submit_button');
$this->selectOption('show_admin_toolbar', 'do_not_show');
$this->pressButton('submit');
}
/**
* @Given /^Admin top bar is enabled$/
@ -300,10 +287,10 @@ class FeatureContext extends MinkContext
*/
public function iTryDeleteAFriendFromSocialGroup($friendId, $groupId)
{
return [
new Step\When(
'I am on "/main/social/group_members.php?id=' . $groupId . '&u=' . $friendId . '&action=delete"'
)
];
$this->visit('/main/social/group_members.php?' . http_build_query([
'id' => $groupId,
'u' => $friendId,
'action' => 'delete'
]));
}
}

@ -35,10 +35,10 @@ Feature: Courses management as admin
Then I should see "Course list"
And I should not see "not be deleted"
Scenario: Enter to public password-protected course
Given I have a public password-protected course named "PASSWORDPROTECTED" with password "123456"
And I am not logged
And I am on "/courses/PASSWORDPROTECTED/index.php"
When I fill in "course_password" with "123456"
And I press "submit"
Then I should not see "The course password is incorrect"
Scenario: Enter to public password-protected course
Given I have a public password-protected course named "PASSWORDPROTECTED" with password "123456"
And I am not logged
And I am on "/courses/PASSWORDPROTECTED/index.php"
When I fill in "course_password" with "123456"
And I press "submit"
Then I should not see "The course password is incorrect"

@ -17,10 +17,12 @@ Feature: Users management as admin
Scenario: Create a user with only basic info
Given I am a platform administrator
And I am on "/main/admin/user_add.php"
When I fill in "firstname" with "Sammy"
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 fill in the following:
| firstname | Sammy |
| lastname | Marshall |
| email | smarshall@example.com |
| username | smarshall |
| password | smarshall |
And I press "submit"
Then I should see "The user has been added"

Loading…
Cancel
Save