Skip to content

Commit

Permalink
Fix tests, adding main/course_home/redirect.php
Browse files Browse the repository at this point in the history
- That new page converts from "session name" to session id
- Change session tests to try with a private course TEMPPRIVATE
  • Loading branch information
jmontoyaa committed Dec 20, 2017
1 parent 68db5be commit 24b6d51
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 46 deletions.
24 changes: 24 additions & 0 deletions main/course_home/redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/* For licensing terms, see /license.txt */

/**
* Redirects a session name to a correct session id
*/

$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';

$sessionName = isset($_GET['session_name']) ? $_GET['session_name'] : '';
$courseCode = isset($_GET['cidReq']) ? $_GET['cidReq'] : '';

if (!empty($sessionName) && !empty($courseCode)) {
$sessionInfo = SessionManager::get_session_by_name($sessionName);
$courseInfo = api_get_course_info($courseCode);
if (!empty($sessionInfo) && !empty($courseInfo)) {
$url = api_get_path(WEB_COURSE_PATH).$courseInfo['directory'].'/index.php?id_session='.$sessionInfo['id'];
header('Location: '.$url);
exit;
}
}

api_not_allowed(true);
2 changes: 1 addition & 1 deletion tests/behat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@ cd tests/behat
To run an specific feature:

```
../../vendor/behat/behat/bin/behat course.feature
../../vendor/behat/behat/bin/behat features/course.feature
```
File renamed without changes.
33 changes: 4 additions & 29 deletions tests/behat/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ public function iAmAPlatformAdministrator()
$this->getSession()->back();
}

/**
* @Given /^I am a session administrator$/
*/
public function iAmASessionAdministrator()
{
$this->visit('/index.php?logout=logout');
$this->iAmOnHomepage();
$this->fillFields(new \Behat\Gherkin\Node\TableNode([
['login', 'amaurichard'],
['password', 'amaurichard']
]));
$this->pressButton('submitAuth');
}

/**
* @Given /^I am a teacher$/
*/
Expand All @@ -54,17 +40,6 @@ public function iAmATeacher()
$this->pressButton('submitAuth');
}

/**
* @Given /^I am a teacher in course "([^"]*)"$/
* @Todo implement
*/
public function iAmATeacherInCourse($course)
{
//$sql = "SELECT * FROM course_rel_user WHERE c_id = X AND user_id = ";
//$result = ...
//if ($result !== false) { ... }
}

/**
* @Given /^I am a student$/
*/
Expand Down Expand Up @@ -136,18 +111,18 @@ public function courseIsDeleted($argument)
/**
* @Given /^I am on course "([^"]*)" homepage$/
*/
public function iAmOnCourseXHomepage($argument)
public function iAmOnCourseXHomepage($courseCode)
{
$this->visit('/courses/'.$argument.'/index.php');
$this->visit('/courses/'.$courseCode.'/index.php');
$this->assertElementNotOnPage('.alert-danger');
}

/**
* @Given /^I am on course "([^"]*)" homepage in session "([^"]*)"$/
*/
public function iAmOnCourseXHomepageInSessionY($courseArgument, $sessionArgument)
public function iAmOnCourseXHomepageInSessionY($courseCode, $sessionName)
{
$this->visit('/courses/'.$courseArgument.'/index.php?id_session='.$sessionArgument);
$this->visit('/main/course_home/redirect.php?cidReq='.$courseCode.'&session_name='.$sessionName);
}

/**
Expand Down
7 changes: 7 additions & 0 deletions tests/behat/features/course.feature
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ Feature: Course tools basic testing
Given I am on "/main/admin/course_add.php"
Then I should not see "not authorized"

Scenario: Create a private course before testing
Given I am on "/main/admin/course_add.php"
When I fill in "title" with "TEMP_PRIVATE"
Then I check the "Private access (access authorized to group members only)" radio button
And I press "submit"
Then I should see "Course TEMP_PRIVATE added"

Scenario: Create a course before testing
Given I am on "/main/admin/course_add.php"
When I fill in "title" with "TEMP"
Expand Down
45 changes: 29 additions & 16 deletions tests/behat/features/sessionAccess.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ Feature: Session access
And I fill in select2 input "#coach_username" with id "1" and value "admin"
And I press "submit"
Then I should see "Add courses to this session (Session1)"
Then I select "TEMP (TEMP)" from "NoSessionCoursesList[]"
Then I select "TEMP_PRIVATE (TEMPPRIVATE)" from "NoSessionCoursesList[]"
And I press "add_course"
And I press "next"
Then I should see "Update successful"
Then I should see "Subscribe users to this session"
Then I press "Multiple registration"
Then I follow "Multiple registration"
Then I select "Warnier Yannick (ywarnier)" from "nosessionUsersList[]"
And I press "add_user"
And I press "next"
Then I should see "Session1"
Then I should see "TEMP"
Then I should see "TEMPPRIVATE"
Then I should see "ywarnier"

@javascript
Expand All @@ -33,42 +33,55 @@ Feature: Session access
And I fill in select2 input "#coach_username" with id "1" and value "admin"
And I press "submit"
Then I should see "Add courses to this session (Session2)"
Then I select "TEMP (TEMP)" from "NoSessionCoursesList[]"
Then I select "TEMP_PRIVATE (TEMPPRIVATE)" from "NoSessionCoursesList[]"
And I press "add_course"
And I press "next"
Then I should see "Update successful"
Then I should see "Subscribe users to this session"
Then I press "Multiple registration"
Then I select "Mosquera Michela (mmosquera)" from "nosessionUsersList[]"
Then I follow "Multiple registration"
Then I select "Mosquera Guardamino Michela (mmosquera)" from "nosessionUsersList[]"
And I press "add_user"
And I press "next"
Then I should see "Session2"
Then I should see "TEMP"
Then I should see "TEMPPRIVATE"
Then I should see "mmosquera"

Scenario: Connect to session 2
Scenario: ywarnier connects to Session1
Given I am logged as "ywarnier"
And I am on course "TEMP" homepage in session "1"
Then I am on course "TEMPPRIVATE" homepage in session "Session1"
Then I should not see "You are not allowed"
And I am on course "TEMP" homepage in session "2"

Scenario: ywarnier connect to Session 2
Given I am logged as "ywarnier"
Then I am on course "TEMPPRIVATE" homepage in session "Session2"
Then I should see "You are not allowed"

Scenario: ywarnier connect to session that doesn't exists
Given I am logged as "ywarnier"
And I am on course "TEMPPRIVATE" homepage in session "Session does not exists"
Then I should see "You are not allowed"

Scenario: Connect to session 2
Scenario: mmosquera connect to Session 1
Given I am logged as "mmosquera"
And I am on course "TEMP" homepage in session "2"
Then I should not see "You are not allowed"
And I am on course "TEMP" homepage in session "1"
Then I am on course "TEMPPRIVATE" homepage in session "Session1"
Then I should see "You are not allowed"

Scenario: mmosquera connect to Session 2
Given I am logged as "mmosquera"
Then I am on course "TEMPPRIVATE" homepage in session "Session2"
Then I should not see "You are not allowed"

Scenario: Delete session "Session2"
Given I am on "/main/session/session_list.php?keyword=Session2"
Given I am a platform administrator
And I am on "/main/session/session_list.php?keyword=Session2"
And wait for the page to be loaded
And I follow "Delete"
And I confirm the popup
Then I should see "Deleted"

Scenario: Delete session "Session1"
Given I am on "/main/session/session_list.php?keyword=Session1"
Given I am a platform administrator
And I am on "/main/session/session_list.php?keyword=Session1"
And wait for the page to be loaded
And I follow "Delete"
And I confirm the popup
Expand Down

1 comment on commit 24b6d51

@ywarnier
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I was wondering how to transform my session name to an ID. I was thinking more about a query to the database, but this here seems like a better idea.

Please sign in to comment.