Skip to content

Commit

Permalink
Rebase master and minor advances on behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardoengelke authored and robertosilvino committed May 18, 2017
1 parent 4e09e81 commit 7e18c9a
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 64 deletions.
96 changes: 92 additions & 4 deletions tests/behat/behat_unasus.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ class behat_unasus extends behat_base
'relationship_members'=> array(
'datagenerator' => 'relationship_members',
'required' => array('user', 'group')
),
'assigns'=> array(
'datagenerator' => 'assign',
'required' => array('course', 'idnumber', 'name')
)

);
Expand Down Expand Up @@ -249,6 +253,74 @@ public function the_Following_Users_Belongs_Relationship_Members($elementname, T

}

/**
* Creates the specified element. More info about available elements in http://docs.moodle.org/dev/Acceptance_testing#Fixtures.
*
* @Given /^the following activity "(?P<element_string>(?:[^"]|\\")*)" exist:$/
*
* @throws Exception
* @throws PendingException
* @param string $elementname The name of the entity to add
* @param TableNode $data
*/
public function the_Following_Assign_Exist($elementname, TableNode $data)
{

$this->datagenerator = new behat_unasus;

$elementdatagenerator = self::$elements[$elementname]['datagenerator'];
$requiredfields = self::$elements[$elementname]['required'];
if (!empty(self::$elements[$elementname]['switchids'])) {
$switchids = self::$elements[$elementname]['switchids'];
}

foreach ($data->getHash() as $elementdata) {

// Check if all the required fields are there.
foreach ($requiredfields as $requiredfield) {
if (!isset($elementdata[$requiredfield])) {
throw new Exception($elementname . ' requires the field ' . $requiredfield . ' to be specified');
}
}

// Switch from human-friendly references to ids.
if (isset($switchids)) {
foreach ($switchids as $element => $field) {
$methodname = 'get_' . $element . '_id';

// Not all the switch fields are required, default vars will be assigned by data generators.
if (isset($elementdata[$element])) {
// Temp $id var to avoid problems when $element == $field.
$id = $this->{$methodname}($elementdata[$element]);
unset($elementdata[$element]);
$elementdata[$field] = $id;
}
}
}

// Preprocess the entities that requires a special treatment.
if (method_exists($this, 'preprocess_' . $elementdatagenerator)) {
$elementdata = $this->{'preprocess_' . $elementdatagenerator}($elementdata);
}

// Creates element.
$methodname = 'create_' . $elementdatagenerator;
// if (method_exists($this->datagenerator, $methodname)) {
if(true){
// Using data generators directly.
$this->datagenerator->{$methodname}($elementdata);

} else if (method_exists($this, 'process_' . $elementdatagenerator)) {
// Using an alternative to the direct data generator call.
$this->{'process_' . $elementdatagenerator}($elementdata);
} else {
throw new PendingException($elementname . ' data generator is not implemented');
}
}
}



/**
* Create a test relationship
* @param array|stdClass $record
Expand Down Expand Up @@ -588,13 +660,29 @@ public function i_add_user_to_cohort_members($user, $cohort) {
}

/**
* Create completeness set for an activity.
* Change complete date of an activity.
*
* @Given /^I set the following completion for the activity "([^"]*)" with$/
* @param string $activity, TableNode $data
* @Given /^I set the submission date of activity "([^"]*)" to "([^"]*)" days after$/
* @param string $idnumber, $days
*/
public function i_set_following_completion_for_activity($activity, TableNode $data) {
public function i_set_submission_date($idnumber, $days) {
global $DB;

$sql = "SELECT instance
FROM {course_modules}
WHERE idnumber = :idnumber";

$assign_assignid = $DB->get_field_sql($sql, array('idnumber' => $idnumber));

$sql_time = "SELECT completionexpected
FROM bethat_course_modules
WHERE instance = :instance";

$unix_timestamp = $DB->get_field_sql($sql_time, array('instance' => $assign_assignid));

//86400 = 1 dia
$new_unix_timestamp = $unix_timestamp + ($days * 86400);

$DB->set_field('assign_submission', 'timemodified', $new_unix_timestamp, array('assignment' => $assign_assignid));
}
}
186 changes: 126 additions & 60 deletions tests/behat/unasus.feature
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,89 @@ Background:
| Cohort student | CHs | Category | CAT1 |

# -----------------------------ASSIGN SETUP-----------------------------------------------
# Unix timestamp 946684800 = 1 jan 2000 at 00h00m00s
And the following "activities" exist:
| activity | course | idnumber | name | intro | grade | assignsubmission_onlinetext_enabled |
| assign | C1 | a1 | Test assignment one | Submit something! | 300 | 1 |
| activity | course | idnumber | name | intro | grade | assignsubmission_onlinetext_enabled | completionexpected | added |
| assign | C1 | a1 | Test assignment one | Submit something! | 100 | 1 | 978307200 | 946684800 |
| assign | C1 | a2 | Test assignment two | Submit something! | 100 | 1 | 946684800 | 946684800 |
| assign | C1 | a3 | Test assignment three | Submit something! | 100 | 1 | 0 | 946684800 |
| assign | C1 | a4 | Test assignment four | Submit something! | 100 | 1 | 946684800 | 946684800 |
| assign | C1 | a5 | Test assignment five | Submit something! | 100 | 1 | 946684800 | 946684800 |
| assign | C1 | a6 | Test assignment six | Submit something! | 100 | 1 | 946684800 | 946684800 |
| assign | C1 | a7 | Test assignment seven | Submit something! | 100 | 1 | 946684800 | 946684800 |


# And the following activity "assigns" exist:
# | activity | course | idnumber | name | intro | grade | assignsubmission_onlinetext_enabled | completionexpected |
# | assign | C1 | a1 | Test assignment one | Submit something! | 100 | 1 | time() + 31557600 |
# | assign | C1 | a2 | Test assignment two | Submit something! | 100 | 1 | 1524585600 |
# | assign | C1 | a3 | Test assignment three | Submit something! | 100 | 1 | 1524585600 |
# | assign | C1 | a4 | Test assignment four | Submit something! | 100 | 1 | 1524585600 |
# | assign | C1 | a5 | Test assignment five | Submit something! | 100 | 1 | 1524585600 |
# | assign | C1 | a6 | Test assignment six | Submit something! | 100 | 1 | 1524585600 |
# | assign | C1 | a7 | Test assignment seven | Submit something! | 100 | 1 | 1524585600 |

# --------------------------------------------------------------------------------------
# -----------------------------QUIZ SETUP-----------------------------------------------
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |

And the following "activities" exist:
| activity | name | intro | course | idnumber |
| quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |


And the following "questions" exist:
| questioncategory | qtype | name | questiontext |
| Test questions | truefalse | TF1 | First question |
| Test questions | truefalse | TF2 | Second question |

And quiz "Quiz 1" contains the following questions:
| question | page | maxmark |
| TF1 | 1 | |
| TF2 | 1 | 3.0 |
# And the following "question categories" exist:
# | contextlevel | reference | name |
# | Course | C1 | Test questions |
#
# And the following "activities" exist:
# | activity | name | intro | course | idnumber |
# | quiz | Quiz 1 | Quiz 1 description | C1 | quiz1 |
#
#
# And the following "questions" exist:
# | questioncategory | qtype | name | questiontext |
# | Test questions | truefalse | TF1 | First question |
# | Test questions | truefalse | TF2 | Second question |
#
# And quiz "Quiz 1" contains the following questions:
# | question | page | maxmark |
# | TF1 | 1 | |
# | TF2 | 1 | 3.0 |

# --------------------------------------------------------------------------------------
# -----------------------------FORUM SETUP-----------------------------------------------
And I log in as "admin"
And I follow "Courses"
And I follow "Category 1"
And I follow "Course1"
And I turn editing mode on
And I click on "Edit settings" "link" in the "Administration" "block"
And I set the following fields to these values:
| Enable completion tracking | Yes |
And I press "Save and display"

# And the following "activities" exist:
# | activity | name | intro | course | idnumber | groupmode |
# | forum | forum | Test forum | C1 | forum | 0 |

When I add a "forum" to section "1" and I fill the form with:
| Forum name | Test forum name1 |
| Description | Test forum description |
| course | C1 |
| groupmode | 0 |
| Completion tracking | Show activity as complete when conditions are met |
| completionview | 1 |

When I add a "forum" to section "1" and I fill the form with:
| Forum name | Test forum name2 |
| Description | Test forum description |
| course | C1 |
| groupmode | 0 |
| Completion tracking | Show activity as complete when conditions are met |
| completionview | 1 |

When I add a "forum" to section "1" and I fill the form with:
| Forum name | Test forum name3 |
| Description | Test forum description |
| course | C1 |
| groupmode | 0 |
| Completion tracking | Show activity as complete when conditions are met |
| completionview | 1 |
And I log out
# And I log in as "admin"
# And I follow "Courses"
# And I follow "Category 1"
# And I follow "Course1"
# And I turn editing mode on
# And I click on "Edit settings" "link" in the "Administration" "block"
# And I set the following fields to these values:
# | Enable completion tracking | Yes |
# And I press "Save and display"
#
## And the following "activities" exist:
## | activity | name | intro | course | idnumber | groupmode |
## | forum | forum | Test forum | C1 | forum | 0 |
#
# When I add a "forum" to section "1" and I fill the form with:
# | Forum name | Test forum name1 |
# | Description | Test forum description |
# | course | C1 |
# | groupmode | 0 |
# | Completion tracking | Show activity as complete when conditions are met |
# | completionview | 1 |
#
# When I add a "forum" to section "1" and I fill the form with:
# | Forum name | Test forum name2 |
# | Description | Test forum description |
# | course | C1 |
# | groupmode | 0 |
# | Completion tracking | Show activity as complete when conditions are met |
# | completionview | 1 |
#
# When I add a "forum" to section "1" and I fill the form with:
# | Forum name | Test forum name3 |
# | Description | Test forum description |
# | course | C1 |
# | groupmode | 0 |
# | Completion tracking | Show activity as complete when conditions are met |
# | completionview | 1 |
# And I log out

# --------------------------------------------------------------------------------------

Expand Down Expand Up @@ -227,7 +245,7 @@ Background:
#
# And I log in as "student2"
# And I follow "Course1"
# And I follow "Test assignment one"
# And I follow "Test assignment two"
# And I press "Add submission"
# And I set the following fields to these values:
# | Online text | I'm the student2 submission |
Expand All @@ -238,13 +256,61 @@ Background:
#
# And I log in as "student3"
# And I follow "Course1"
# And I follow "Test assignment one"
# And I follow "Test assignment three"
# And I press "Add submission"
# And I set the following fields to these values:
# | Online text | I'm the student3 submission |
# And I press "Save changes"
# And I press "Submit assignment"
# And I press "Continue"
# And I log out

# And I log in as "student1"
# And I follow "Course1"
# And I follow "Test assignment four"
# And I press "Add submission"
# And I set the following fields to these values:
# | Online text | I'm the student1 submission |
# And I press "Save changes"
# And I press "Submit assignment"
# And I press "Continue"
# And I set the submission date of activity "a4" to "0" days after
# And I log out
#
# And I log in as "student1"
# And I follow "Course1"
# And I follow "Test assignment five"
# And I press "Add submission"
# And I set the following fields to these values:
# | Online text | I'm the student3 submission |
# And I press "Save changes"
# And I press "Submit assignment"
# And I press "Continue"
# And I set the submission date of activity "a5" to "10" days after
# And I log out
#
# And I log in as "student1"
# And I follow "Course1"
# And I follow "Test assignment six"
# And I press "Add submission"
# And I set the following fields to these values:
# | Online text | I'm the student3 submission |
# And I press "Save changes"
# And I press "Submit assignment"
# And I press "Continue"
# And I set the submission date of activity "a6" to "11" days after
# And I log out

# And I log in as "student1"
# And I follow "Course1"
# And I follow "Test assignment seven"
# And I press "Add submission"
# And I set the following fields to these values:
# | Online text | I'm the student3 submission |
# And I press "Save changes"
# And I press "Submit assignment"
# And I press "Continue"
# And I set the submission date of activity "a7" to "11" days after
# And I log out

# Atribuição de nota em assignment (Avaliação da atividade por parte do professor)
Expand Down

0 comments on commit 7e18c9a

Please sign in to comment.