From 1184d3c20fb6877b193e98edea731bed88d54a29 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 3 Aug 2023 11:22:39 +0200 Subject: [PATCH 1/8] MDL-77581 behat: Support finish_generate_ in generators --- lib/behat/classes/behat_generator_base.php | 11 +++++++++++ lib/upgrade.txt | 1 + 2 files changed, 12 insertions(+) diff --git a/lib/behat/classes/behat_generator_base.php b/lib/behat/classes/behat_generator_base.php index 9b9661f7895..262b6f415a6 100644 --- a/lib/behat/classes/behat_generator_base.php +++ b/lib/behat/classes/behat_generator_base.php @@ -279,6 +279,17 @@ abstract class behat_generator_base { ' data generator is not implemented'); } } + + // Notify that the all the elements have been generated. + if (method_exists($this->componentdatagenerator, 'finish_generate_' . $generatortype)) { + // Using the component's own data generator if it exists. + $this->componentdatagenerator->{'finish_generate_' . $generatortype}(); + + } else if (method_exists($this->datagenerator, 'finish_generate_' . $generatortype)) { + // Use a method on the core data geneator, if there is one. + $this->datagenerator->{'finish_generate_' . $generatortype}(); + + } } /** diff --git a/lib/upgrade.txt b/lib/upgrade.txt index d868f1ceb82..15ee252d542 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -6,6 +6,7 @@ information provided here is intended especially for developers. (via options.pending). This is a backport of patch MDL-78779. * Add a new parameter to the debounce (core/utils) function to allow for cancellation. * Add a new method core_user::get_initials to get the initials of a user in a way compatible with internationalisation. +* Behat generators can now implement the function finish_generate_ to detect when the whole list of elements have been generated. === 4.1.6 === * \moodle_page::set_title() has been updated to append the site name depending on the value of $CFG->sitenameintitle and whether From 40b918348ca400c2c0ef89fe2e448163ac5c4b5a Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 2 Jun 2023 12:36:39 +0200 Subject: [PATCH 2/8] MDL-77581 behat: Create generators for lesson pages and answers --- .../generator/behat_mod_lesson_generator.php | 65 +++ mod/lesson/tests/generator/lib.php | 267 ++++++++++- mod/lesson/tests/generator_test.php | 451 ++++++++++++++++++ 3 files changed, 776 insertions(+), 7 deletions(-) create mode 100644 mod/lesson/tests/generator/behat_mod_lesson_generator.php diff --git a/mod/lesson/tests/generator/behat_mod_lesson_generator.php b/mod/lesson/tests/generator/behat_mod_lesson_generator.php new file mode 100644 index 00000000000..4e023113fa0 --- /dev/null +++ b/mod/lesson/tests/generator/behat_mod_lesson_generator.php @@ -0,0 +1,65 @@ +. + +/** + * Behat data generator for mod_lesson. + * + * @package mod_lesson + * @category test + * @copyright 2023 Dani Palou + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Behat data generator for mod_lesson. + * + * @copyright 2023 Dani Palou + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_mod_lesson_generator extends behat_generator_base { + + /** + * Get a list of the entities that can be created. + * + * @return array entity name => information about how to generate. + */ + protected function get_creatable_entities(): array { + return [ + 'pages' => [ + 'singular' => 'page', + 'datagenerator' => 'page', + 'required' => ['lesson', 'qtype'], + 'switchids' => ['lesson' => 'lessonid'], + ], + 'answers' => [ + 'singular' => 'answer', + 'datagenerator' => 'answer', + 'required' => ['page'], + ], + ]; + } + + /** + * Look up the id of a lesson from its name. + * + * @param string $idnumberorname the lesson idnumber or name, for example 'Test lesson'. + * @return int corresponding id. + */ + protected function get_lesson_id(string $idnumberorname): int { + return $this->get_cm_by_activity_name('lesson', $idnumberorname)->instance; + } + +} diff --git a/mod/lesson/tests/generator/lib.php b/mod/lesson/tests/generator/lib.php index 53fcfa6a251..9290f88f280 100644 --- a/mod/lesson/tests/generator/lib.php +++ b/mod/lesson/tests/generator/lib.php @@ -25,6 +25,8 @@ defined('MOODLE_INTERNAL') || die(); +require_once($CFG->dirroot.'/mod/lesson/locallib.php'); + /** * mod_lesson data generator class. * @@ -40,6 +42,24 @@ class mod_lesson_generator extends testing_module_generator { */ protected $pagecount = 0; + /** + * @var array list of candidate pages to be created when all answers have been added. + */ + protected $candidatepages = []; + + /** + * @var array map of readable jumpto to integer value. + */ + protected $jumptomap = [ + 'This page' => LESSON_THISPAGE, + 'Next page' => LESSON_NEXTPAGE, + 'Previous page' => LESSON_PREVIOUSPAGE, + 'End of lesson' => LESSON_EOL, + 'Unseen question within a content page' => LESSON_UNSEENBRANCHPAGE, + 'Random question within a content page' => LESSON_RANDOMPAGE, + 'Random content page' => LESSON_RANDOMBRANCH, + ]; + /** * To be called from data reset code only, * do not use in tests. @@ -47,9 +67,17 @@ class mod_lesson_generator extends testing_module_generator { */ public function reset() { $this->pagecount = 0; + $this->candidatepages = []; parent::reset(); } + /** + * Creates a lesson instance for testing purposes. + * + * @param null|array|stdClass $record data for module being generated. + * @param null|array $options general options for course module. + * @return stdClass record from module-defined table with additional field cmid (corresponding id in course_modules table) + */ public function create_instance($record = null, array $options = null) { global $CFG; @@ -92,9 +120,84 @@ class mod_lesson_generator extends testing_module_generator { return parent::create_instance($record, (array)$options); } + /** + * Creates a page for testing purposes. The page will be created when answers are added. + * + * @param null|array|stdClass $record data for page being generated. + * @param null|array $options general options. + */ + public function create_page($record = null, array $options = null) { + $record = (array) $record; + + // Pages require answers to work. Add it as a candidate page to be created once answers have been added. + $record['answer_editor'] = []; + $record['response_editor'] = []; + $record['jumpto'] = []; + $record['score'] = []; + + if (!isset($record['previouspage']) || $record['previouspage'] === '') { + // Previous page not set, set it to the last candidate page (if any). + $record['previouspage'] = empty($this->candidatepages) ? '0' : end($this->candidatepages)['title']; + } + + $this->candidatepages[] = $record; + } + + /** + * Creates a page and its answers for testing purposes. + * + * @param array $record data for page being generated. + * @return stdClass created page, null if couldn't be created because it has a jump to a page that doesn't exist. + * @throws coding_exception + */ + private function perform_create_page(array $record): ?stdClass { + global $DB; + + $lesson = $DB->get_record('lesson', ['id' => $record['lessonid']], '*', MUST_EXIST); + $cm = get_coursemodule_from_instance('lesson', $lesson->id); + $lesson->cmid = $cm->id; + $qtype = $record['qtype']; + + unset($record['qtype']); + unset($record['lessonid']); + + if (isset($record['content'])) { + $record['contents_editor'] = [ + 'text' => $record['content'], + 'format' => FORMAT_MOODLE, + 'itemid' => 0, + ]; + unset($record['content']); + } + + $record['pageid'] = $this->get_previouspage_id($lesson->id, $record['previouspage']); + unset($record['previouspage']); + + try { + $record['jumpto'] = $this->convert_page_jumpto($lesson->id, $record['jumpto']); + } catch (coding_exception $e) { + // This page has a jump to a page that hasn't been created yet. + return null; + } + + $funcname = $qtype === 'content' ? 'create_content' : "create_question_{$qtype}"; + + if (!method_exists($this, $funcname)) { + throw new coding_exception('The page '.$record['title']." has an invalid qtype: $qtype"); + } + + return $this->{$funcname}($lesson, $record); + } + + /** + * Creates a content page for testing purposes. + * + * @param stdClass $lesson instance where to create the page. + * @param array|stdClass $record data for page being generated. + * @return int Page ID. + */ public function create_content($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -124,7 +227,6 @@ class mod_lesson_generator extends testing_module_generator { */ public function create_question_truefalse($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -177,7 +279,6 @@ class mod_lesson_generator extends testing_module_generator { */ public function create_question_multichoice($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -230,7 +331,6 @@ class mod_lesson_generator extends testing_module_generator { */ public function create_question_essay($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -272,7 +372,6 @@ class mod_lesson_generator extends testing_module_generator { */ public function create_question_matching($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -351,7 +450,6 @@ class mod_lesson_generator extends testing_module_generator { */ public function create_question_shortanswer($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -393,7 +491,6 @@ class mod_lesson_generator extends testing_module_generator { */ public function create_question_numeric($lesson, $record = array()) { global $DB, $CFG; - require_once($CFG->dirroot.'/mod/lesson/locallib.php'); $now = time(); $this->pagecount++; $record = (array)$record + array( @@ -431,6 +528,7 @@ class mod_lesson_generator extends testing_module_generator { * Create a lesson override (either user or group). * * @param array $data must specify lessonid, and one of userid or groupid. + * @throws coding_exception */ public function create_override(array $data): void { global $DB; @@ -449,4 +547,159 @@ class mod_lesson_generator extends testing_module_generator { $DB->insert_record('lesson_overrides', (object) $data); } + + /** + * Creates an answer in a page for testing purposes. + * + * @param null|array|stdClass $record data for module being generated. + * @param null|array $options general options. + * @throws coding_exception + */ + public function create_answer($record = null, array $options = null) { + $record = (array) $record; + + $candidatepage = null; + $pagetitle = $record['page']; + $found = false; + foreach ($this->candidatepages as &$candidatepage) { + if ($candidatepage['title'] === $pagetitle) { + $found = true; + break; + } + } + + if (!$found) { + throw new coding_exception("Page '$pagetitle' not found in candidate pages. Please make sure the page exists " + . 'and all answers are in the same table.'); + } + + if (isset($record['answer'])) { + $candidatepage['answer_editor'][] = [ + 'text' => $record['answer'], + 'format' => FORMAT_HTML, + ]; + } else { + $candidatepage['answer_editor'][] = null; + } + + if (isset($record['response'])) { + $candidatepage['response_editor'][] = [ + 'text' => $record['response'], + 'format' => FORMAT_HTML, + ]; + } else { + $candidatepage['response_editor'][] = null; + } + + $candidatepage['jumpto'][] = $record['jumpto'] ?? LESSON_THISPAGE; + $candidatepage['score'][] = $record['score'] ?? 0; + } + + /** + * All answers in a table have been generated, create the pages. + */ + public function finish_generate_answer() { + $this->create_candidate_pages(); + } + + /** + * Create candidate pages. + * + * @throws coding_exception + */ + protected function create_candidate_pages(): void { + // For performance reasons it would be better to use a topological sort algorithm. But since test cases shouldn't have + // a lot of paged and complex jumps it was implemented using a simpler approach. + $consecutiveblocked = 0; + + while (count($this->candidatepages) > 0) { + $page = array_shift($this->candidatepages); + $id = $this->perform_create_page($page); + + if ($id === null) { + // Page cannot be created yet because of jumpto. Move it to the end of list. + $consecutiveblocked++; + $this->candidatepages[] = $page; + + if ($consecutiveblocked === count($this->candidatepages)) { + throw new coding_exception('There is a circular dependency in pages jumps.'); + } + } else { + $consecutiveblocked = 0; + } + } + } + + /** + * Calculate the previous page id. + * If no page title is supplied, use the last page created in the lesson (0 if no pages). + * If page title is supplied, search it in DB and the list of candidate pages. + * + * @param int $lessonid the lesson id. + * @param string $pagetitle the page title, for example 'Test page'. '0' if no previous page. + * @return int corresponding id. 0 if no previous page. + * @throws coding_exception + */ + protected function get_previouspage_id(int $lessonid, string $pagetitle): int { + global $DB; + + if (is_numeric($pagetitle) && intval($pagetitle) === 0) { + return 0; + } + + $pages = $DB->get_records('lesson_pages', ['lessonid' => $lessonid, 'title' => $pagetitle], 'id ASC', 'id, title'); + + if (count($pages) > 1) { + throw new coding_exception("More than one page with '$pagetitle' found"); + } else if (!empty($pages)) { + return current($pages)->id; + } + + // Page doesn't exist, search if it's a candidate page. If it is, use its previous page instead. + foreach ($this->candidatepages as $candidatepage) { + if ($candidatepage['title'] === $pagetitle) { + return $this->get_previouspage_id($lessonid, $candidatepage['previouspage']); + } + } + + throw new coding_exception("Page '$pagetitle' not found"); + } + + /** + * Convert the jumpto using a string to an integer value. + * The jumpto can contain a page name or one of our predefined values. + * + * @param int $lessonid the lesson id. + * @param array|null $jumptolist list of jumpto to treat. + * @return array|null list of jumpto already treated. + * @throws coding_exception + */ + protected function convert_page_jumpto(int $lessonid, ?array $jumptolist): ?array { + global $DB; + + if (empty($jumptolist)) { + return $jumptolist; + } + + foreach ($jumptolist as $i => $jumpto) { + if (empty($jumpto) || is_numeric($jumpto)) { + continue; + } + + if (isset($this->jumptomap[$jumpto])) { + $jumptolist[$i] = $this->jumptomap[$jumpto]; + + continue; + } + + $page = $DB->get_record('lesson_pages', ['lessonid' => $lessonid, 'title' => $jumpto], 'id'); + if ($page === false) { + throw new coding_exception("Jump '$jumpto' not found in pages."); + } + + $jumptolist[$i] = $page->id; + } + + return $jumptolist; + } } diff --git a/mod/lesson/tests/generator_test.php b/mod/lesson/tests/generator_test.php index 18d039d3a8e..b2a0eeb5ef7 100644 --- a/mod/lesson/tests/generator_test.php +++ b/mod/lesson/tests/generator_test.php @@ -23,6 +23,7 @@ namespace mod_lesson; * @category test * @copyright 2013 Marina Glancy * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @covers \mod_lesson_generator */ class generator_test extends \advanced_testcase { @@ -213,4 +214,454 @@ class generator_test extends \advanced_testcase { $this->assertEquals($page2->id, $records[$page2->id]->id); $this->assertEquals($page2->title, $records[$page2->id]->title); } + + /** + * Test create some pages and their answers. + * + * @covers ::create_page + * @covers ::create_answer + * @covers ::finish_generate_answer + */ + public function test_create_page_and_answers(): void { + global $DB; + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + // Define the pages. Only a couple pages will be created since each page type has their own unit tests. + $contentpage = [ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $multichoicepage = [ + 'title' => 'Multichoice question', + 'content' => 'What animal is an amphibian?', + 'qtype' => 'multichoice', + 'lessonid' => $lesson->id, + ]; + + $lessongenerator->create_page($contentpage); + $lessongenerator->create_page($multichoicepage); + + // Check that pages haven't been generated yet because no answers were added. + $pages = $DB->get_records('lesson_pages', ['lessonid' => $lesson->id], 'id'); + $this->assertEquals(0, count($pages)); + + // Now add answers to the pages. + $contentpagecontinueanswer = [ + 'page' => $contentpage['title'], + 'answer' => 'Continue', + 'jumpto' => 'Next page', + 'score' => 1, + ]; + $contentpagestayanswer = [ + 'page' => $contentpage['title'], + 'answer' => 'Stay', + 'jumpto' => 'This page', + 'score' => 0, + ]; + $multichoicepagefroganswer = [ + 'page' => $multichoicepage['title'], + 'answer' => 'Frog', + 'response' => 'Correct answer', + 'jumpto' => 'Next page', + 'score' => 1, + ]; + $multichoicepagecatanswer = [ + 'page' => $multichoicepage['title'], + 'answer' => 'Cat', + 'response' => 'Incorrect answer', + 'jumpto' => 'This page', + 'score' => 0, + ]; + $multichoicepagedoganswer = [ + 'page' => $multichoicepage['title'], + 'answer' => 'Dog', + 'response' => 'Incorrect answer', + 'jumpto' => 'This page', + 'score' => 0, + ]; + + $lessongenerator->create_answer($contentpagecontinueanswer); + $lessongenerator->create_answer($contentpagestayanswer); + $lessongenerator->create_answer($multichoicepagefroganswer); + $lessongenerator->create_answer($multichoicepagecatanswer); + $lessongenerator->create_answer($multichoicepagedoganswer); + + // Check that pages and answers haven't been generated yet because maybe not all answers have been added yet. + $pages = $DB->get_records('lesson_pages', ['lessonid' => $lesson->id], 'id'); + $answers = $DB->get_records('lesson_answers', ['lessonid' => $lesson->id], 'id'); + $this->assertEquals(0, count($pages)); + $this->assertEquals(0, count($answers)); + + // Notify that all answers have been added, so pages can be created. + $lessongenerator->finish_generate_answer(); + + // Check that pages and answers have been created. + $pages = $DB->get_records('lesson_pages', ['lessonid' => $lesson->id], 'title DESC'); + $this->assertEquals(2, count($pages)); + + $contentpagedb = array_pop($pages); + $multichoicepagedb = array_pop($pages); + $this->assertEquals($contentpage['title'], $contentpagedb->title); + $this->assertEquals($contentpage['content'], $contentpagedb->contents); + $this->assertEquals(LESSON_PAGE_BRANCHTABLE, $contentpagedb->qtype); + $this->assertEquals($multichoicepage['title'], $multichoicepagedb->title); + $this->assertEquals($multichoicepage['content'], $multichoicepagedb->contents); + $this->assertEquals(LESSON_PAGE_MULTICHOICE, $multichoicepagedb->qtype); + + $answers = $DB->get_records('lesson_answers', ['lessonid' => $lesson->id], 'answer DESC'); + $this->assertEquals(5, count($answers)); + + $multichoicepagecatanswerdb = array_pop($answers); + $contentpagecontinueanswerdb = array_pop($answers); + $multichoicepagedoganswerdb = array_pop($answers); + $multichoicepagefroganswerdb = array_pop($answers); + $contentpagestayanswerdb = array_pop($answers); + $this->assertEquals($contentpagedb->id, $contentpagecontinueanswerdb->pageid); + $this->assertEquals($contentpagecontinueanswer['answer'], $contentpagecontinueanswerdb->answer); + $this->assertEquals(LESSON_NEXTPAGE, $contentpagecontinueanswerdb->jumpto); + $this->assertEquals($contentpagecontinueanswer['score'], $contentpagecontinueanswerdb->score); + $this->assertEquals($contentpagedb->id, $contentpagestayanswerdb->pageid); + $this->assertEquals($contentpagestayanswer['answer'], $contentpagestayanswerdb->answer); + $this->assertEquals(LESSON_THISPAGE, $contentpagestayanswerdb->jumpto); + $this->assertEquals($contentpagestayanswer['score'], $contentpagestayanswerdb->score); + $this->assertEquals($multichoicepagedb->id, $multichoicepagefroganswerdb->pageid); + $this->assertEquals($multichoicepagefroganswer['answer'], $multichoicepagefroganswerdb->answer); + $this->assertEquals($multichoicepagefroganswer['response'], $multichoicepagefroganswerdb->response); + $this->assertEquals(LESSON_NEXTPAGE, $multichoicepagefroganswerdb->jumpto); + $this->assertEquals($multichoicepagefroganswer['score'], $multichoicepagefroganswerdb->score); + $this->assertEquals($multichoicepagedb->id, $multichoicepagedoganswerdb->pageid); + $this->assertEquals($multichoicepagedoganswer['answer'], $multichoicepagedoganswerdb->answer); + $this->assertEquals($multichoicepagedoganswer['response'], $multichoicepagedoganswerdb->response); + $this->assertEquals(LESSON_THISPAGE, $multichoicepagedoganswerdb->jumpto); + $this->assertEquals($multichoicepagedoganswer['score'], $multichoicepagedoganswerdb->score); + $this->assertEquals($multichoicepagedb->id, $multichoicepagecatanswerdb->pageid); + $this->assertEquals($multichoicepagecatanswer['answer'], $multichoicepagecatanswerdb->answer); + $this->assertEquals($multichoicepagecatanswer['response'], $multichoicepagecatanswerdb->response); + $this->assertEquals(LESSON_THISPAGE, $multichoicepagecatanswerdb->jumpto); + $this->assertEquals($multichoicepagecatanswer['score'], $multichoicepagecatanswerdb->score); + } + + /** + * Test creating pages defining the previous pages. + * + * @covers ::create_page + */ + public function test_create_page_with_previouspage(): void { + global $DB; + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $firstpage = [ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + 'previouspage' => 0, // No previous page, this will be the first page. + ]; + $secondpage = [ + 'title' => 'Second page name', + 'content' => 'Second page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + 'previouspage' => 'First page name', + ]; + $thirdpage = [ + 'title' => 'Third page name', + 'content' => 'Third page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + 'previouspage' => 'Second page name', + ]; + + // Create the third page first to check that the added order is not important, the order will still be calculated right. + $lessongenerator->create_page($thirdpage); + $lessongenerator->create_page($firstpage); + $lessongenerator->create_page($secondpage); + + // Don't define any answers, the default answers will be added. + $lessongenerator->finish_generate_answer(); + + $pages = $DB->get_records('lesson_pages', ['lessonid' => $lesson->id], 'title DESC'); + $this->assertEquals(3, count($pages)); + + $firstpagedb = array_pop($pages); + $secondpagedb = array_pop($pages); + $thirdpagedb = array_pop($pages); + $this->assertEquals($firstpage['title'], $firstpagedb->title); + $this->assertEquals(0, $firstpagedb->prevpageid); + $this->assertEquals($secondpagedb->id, $firstpagedb->nextpageid); + $this->assertEquals($secondpage['title'], $secondpagedb->title); + $this->assertEquals($firstpagedb->id, $secondpagedb->prevpageid); + $this->assertEquals($thirdpagedb->id, $secondpagedb->nextpageid); + $this->assertEquals($thirdpage['title'], $thirdpagedb->title); + $this->assertEquals($secondpagedb->id, $thirdpagedb->prevpageid); + $this->assertEquals(0, $thirdpagedb->nextpageid); + } + + /** + * Test creating a page with a previous page that doesn't exist. + * + * @covers ::create_page + */ + public function test_create_page_invalid_previouspage(): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $this->expectException('coding_exception'); + $lessongenerator->create_page([ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + 'previouspage' => 'Invalid page', + ]); + $lessongenerator->finish_generate_answer(); + } + + /** + * Test that circular dependencies are not allowed in previous pages. + * + * @covers ::create_page + */ + public function test_create_page_previouspage_circular_dependency(): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $this->expectException('coding_exception'); + $lessongenerator->create_page([ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + 'previouspage' => 'Second page name', + ]); + $lessongenerator->create_page([ + 'title' => 'Second page name', + 'content' => 'Second page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + 'previouspage' => 'First page name', + ]); + $lessongenerator->finish_generate_answer(); + } + + /** + * Test creating an answer in a page that doesn't exist. + * + * @covers ::create_answer + */ + public function test_create_answer_invalid_page(): void { + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $this->expectException('coding_exception'); + $lessongenerator->create_answer([ + 'page' => 'Invalid page', + ]); + } + + /** + * Test that all the possible values of jumpto work as expected when creating an answer. + * + * @covers ::create_answer + */ + public function test_create_answer_jumpto(): void { + global $DB; + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $contentpage = [ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $secondcontentpage = [ + 'title' => 'Second page name', + 'content' => 'Second page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $thirdcontentpage = [ + 'title' => 'Third page name', + 'content' => 'Third page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $lessongenerator->create_page($contentpage); + $lessongenerator->create_page($secondcontentpage); + $lessongenerator->create_page($thirdcontentpage); + + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'A', + 'jumpto' => 'This page', + ]); + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'B', + 'jumpto' => 'Next page', + ]); + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'C', + 'jumpto' => 'Previous page', + ]); + $lessongenerator->create_answer([ + 'page' => $secondcontentpage['title'], + 'answer' => 'D', + 'jumpto' => 'End of lesson', + ]); + $lessongenerator->create_answer([ + 'page' => $secondcontentpage['title'], + 'answer' => 'E', + 'jumpto' => 'Unseen question within a content page', + ]); + $lessongenerator->create_answer([ + 'page' => $secondcontentpage['title'], + 'answer' => 'F', + 'jumpto' => 'Random question within a content page', + ]); + $lessongenerator->create_answer([ + 'page' => $thirdcontentpage['title'], + 'answer' => 'G', + 'jumpto' => 'Random content page', + ]); + $lessongenerator->create_answer([ + 'page' => $thirdcontentpage['title'], + 'answer' => 'H', + 'jumpto' => 'Unseen question within a cluster', + ]); + $lessongenerator->create_answer([ + 'page' => $thirdcontentpage['title'], + 'answer' => 'I', + 'jumpto' => 1234, // A page ID, it doesn't matter that it doesn't exist. + ]); + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'J', + 'jumpto' => 'Third page name', + ]); + $lessongenerator->create_answer([ + 'page' => $thirdcontentpage['title'], + 'answer' => 'K', + 'jumpto' => 'Second page name', + ]); + + $lessongenerator->finish_generate_answer(); + + $secondcontentpagedb = $DB->get_record('lesson_pages', ['lessonid' => $lesson->id, 'title' => $secondcontentpage['title']]); + $thirdcontentpagedb = $DB->get_record('lesson_pages', ['lessonid' => $lesson->id, 'title' => $thirdcontentpage['title']]); + $answers = $DB->get_records('lesson_answers', ['lessonid' => $lesson->id], 'answer DESC'); + $this->assertEquals(11, count($answers)); + + $this->assertEquals(LESSON_THISPAGE, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_NEXTPAGE, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_PREVIOUSPAGE, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_EOL, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_UNSEENBRANCHPAGE, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_RANDOMPAGE, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_RANDOMBRANCH, array_pop($answers)->jumpto); + $this->assertEquals(LESSON_CLUSTERJUMP, array_pop($answers)->jumpto); + $this->assertEquals(1234, array_pop($answers)->jumpto); + $this->assertEquals($thirdcontentpagedb->id, array_pop($answers)->jumpto); + $this->assertEquals($secondcontentpagedb->id, array_pop($answers)->jumpto); + } + + /** + * Test invalid jumpto when creating answers. + * + * @covers ::create_answer + */ + public function test_create_answer_invalid_jumpto(): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $contentpage = [ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $lessongenerator->create_page($contentpage); + + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'Next', + 'jumpto' => 'Invalid page', + ]); + + $this->expectException('coding_exception'); + $lessongenerator->finish_generate_answer(); + } + + /** + * Test that circular dependencies are not allowed when creating answers. + * + * @covers ::create_answer + */ + public function test_create_answer_jumpto_circular_dependency(): void { + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $contentpage = [ + 'title' => 'First page name', + 'content' => 'First page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $secondcontentpage = [ + 'title' => 'Second page name', + 'content' => 'Second page contents', + 'qtype' => 'content', + 'lessonid' => $lesson->id, + ]; + $lessongenerator->create_page($contentpage); + $lessongenerator->create_page($secondcontentpage); + + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'Next', + 'jumpto' => 'Second page name', + ]); + $lessongenerator->create_answer([ + 'page' => $contentpage['title'], + 'answer' => 'Back', + 'jumpto' => 'First page name', + ]); + + $this->expectException('coding_exception'); + $lessongenerator->finish_generate_answer(); + } + } From cad097a605b26f25211b0b53d59c0862850e9578 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 2 Jun 2023 12:37:34 +0200 Subject: [PATCH 3/8] MDL-77581 behat: Apply new lesson generators to existing tests --- ...graderescale_for_lesson_pointscale.feature | 19 +- .../completion_condition_end_reached.feature | 49 +-- .../completion_condition_time_spent.feature | 63 ++-- .../tests/behat/date_availability.feature | 24 +- .../behat/display_lesson_description.feature | 28 +- .../behat/lesson_activity_completion.feature | 24 +- .../behat/lesson_complete_report.feature | 154 +++------ .../lesson_completion_pass_grade.feature | 30 +- .../tests/behat/lesson_course_reset.feature | 26 +- .../tests/behat/lesson_delete_answers.feature | 35 +- .../tests/behat/lesson_edit_pages.feature | 44 +-- .../tests/behat/lesson_essay_question.feature | 14 +- .../tests/behat/lesson_group_override.feature | 21 +- .../behat/lesson_informations_at_end.feature | 29 +- .../tests/behat/lesson_navigation.feature | 121 +++---- .../lesson_number_of_student_attempts.feature | 57 +--- ...son_numerical_question_with_locale.feature | 27 +- .../tests/behat/lesson_outline_report.feature | 139 +++----- .../tests/behat/lesson_practice.feature | 19 +- .../tests/behat/lesson_progress_bar.feature | 44 +-- .../behat/lesson_question_attempts.feature | 86 ++--- mod/lesson/tests/behat/lesson_report.feature | 119 ++----- .../lesson_report_detailed_statistics.feature | 15 +- mod/lesson/tests/behat/lesson_review.feature | 38 +-- .../tests/behat/lesson_student_resume.feature | 311 +++++------------- .../tests/behat/lesson_user_override.feature | 21 +- .../tests/behat/link_to_gradebook.feature | 33 +- .../tests/behat/password_protection.feature | 13 +- .../tests/behat/teacher_grade_essays.feature | 13 +- mod/lesson/tests/behat/time_limit.feature | 12 +- .../tests/behat/wrong_answer_continue.feature | 51 +-- 31 files changed, 525 insertions(+), 1154 deletions(-) diff --git a/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature b/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature index f000b747894..f3c0a9a2675 100644 --- a/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature +++ b/lib/form/tests/behat/graderescale_for_lesson_pointscale.feature @@ -24,18 +24,13 @@ Feature: Using the lesson activities which support point scale @javascript Scenario: Lesson rescale grade should not be possible when users are graded - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Numerical question | - | Page contents | What is 1 + 2? | - | id_answer_editor_0 | 3 | - | id_jumpto_0 | End of lesson | - | id_enableotheranswers | 1 | - | id_jumpto_6 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | numeric | Numerical question | What is 1 + 2? | + And the following "mod_lesson > answers" exist: + | page | answer | jumpto | score | + | Numerical question | 3 | End of lesson | 1 | + | Numerical question | @#wronganswer#@ | Next page | 0 | And I am on the "Test lesson name" "lesson activity" page logged in as student1 And I set the field "Your answer" to "5" And I press "Submit" diff --git a/mod/lesson/tests/behat/completion_condition_end_reached.feature b/mod/lesson/tests/behat/completion_condition_end_reached.feature index 8e03ff3cfca..e8e6ca9e0a4 100644 --- a/mod/lesson/tests/behat/completion_condition_end_reached.feature +++ b/mod/lesson/tests/behat/completion_condition_end_reached.feature @@ -10,45 +10,24 @@ Feature: Set end of lesson reached as a completion condition for a lesson | student1 | Student | 1 | student1@example.com | | teacher1 | Teacher | 1 | teacher1@example.com | And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | + | fullname | shortname | category | enablecompletion | + | Course 1 | C1 | 0 | 1 | And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | - Given the following "activity" exists: - | activity | lesson | - | course | C1 | - | idnumber | 0001 | - | name | Test lesson | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on - And I navigate to "Settings" in current page administration - And I set the following fields to these values: - | Enable completion tracking | Yes | - And I press "Save and display" - And I am on the "Test lesson" "lesson activity editing" page - And I set the following fields to these values: - | Completion tracking | Show activity as complete when conditions are met | - | completionview | 0 | - | completionendreached | 1 | - And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + And the following "activity" exist: + | activity | name | course | idnumber | completion | completionview | completionendreached | + | lesson | Test lesson | C1 | 0001 | 2 | 0 | 1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson | content | First page name | First page contents | + | Test lesson | content | Second page name | Second page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | + | Second page name | Previous page | Previous page | + | Second page name | Next page | Next page | When I am on the "Course 1" course page logged in as student1 Then the "Go through the activity to the end" completion condition of "Test lesson" is displayed as "todo" And I follow "Test lesson" diff --git a/mod/lesson/tests/behat/completion_condition_time_spent.feature b/mod/lesson/tests/behat/completion_condition_time_spent.feature index 54d50c61e6f..4b2fc8ed547 100644 --- a/mod/lesson/tests/behat/completion_condition_time_spent.feature +++ b/mod/lesson/tests/behat/completion_condition_time_spent.feature @@ -6,50 +6,29 @@ Feature: Set time spent as a completion condition for a lesson Scenario: Set time spent as a condition Given the following "users" exist: - | username | firstname | lastname | email | - | student1 | Student | 1 | student1@example.com | - | teacher1 | Teacher | 1 | teacher1@example.com | + | username | firstname | lastname | email | + | student1 | Student | 1 | student1@example.com | + | teacher1 | Teacher | 1 | teacher1@example.com | And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | + | fullname | shortname | category | enablecompletion | + | Course 1 | C1 | 0 | 1 | And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And the following "activity" exists: - | activity | lesson | - | course | C1 | - | idnumber | 0001 | - | name | Test lesson | - And I am on the "Course 1" course page logged in as teacher1 - And I navigate to "Settings" in current page administration - And I set the following fields to these values: - | Enable completion tracking | Yes | - And I press "Save and display" - And I am on the "Test lesson" "lesson activity editing" page - And I set the following fields to these values: - | Completion tracking | Show activity as complete when conditions are met | - | completionview | 0 | - | completiontimespentenabled | 1 | - | completiontimespent[timeunit] | 1 | - | completiontimespent[number] | 5 | - And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activity" exist: + | activity | name | course | idnumber | completion | completionview | completiontimespentenabled | completiontimespent | + | lesson | Test lesson | C1 | 0001 | 2 | 0 | 1 | 5 | + And the following "mod_lesson > pages" exist: + | lesson | qtype | title | content | + | Test lesson | content | First page name | First page contents | + | Test lesson | content | Second page name | Second page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | + | Second page name | Previous page | Previous page | + | Second page name | Next page | Next page | + When I am on the "Course 1" course page logged in as student1 Then the "Spend at least 5 secs on this activity" completion condition of "Test lesson" is displayed as "todo" And I follow "Test lesson" diff --git a/mod/lesson/tests/behat/date_availability.feature b/mod/lesson/tests/behat/date_availability.feature index b9d6627a23c..775c7c0abf1 100644 --- a/mod/lesson/tests/behat/date_availability.feature +++ b/mod/lesson/tests/behat/date_availability.feature @@ -19,11 +19,15 @@ Feature: A teacher can set available from and deadline dates to access a lesson And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson | C1 | lesson1 | - And I log in as "teacher1" - And I am on "Course 1" course homepage with editing mode on + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson | content | First page name | First page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | Scenario: Forbidding lesson accesses until a specified date - Given I am on the "Test lesson" "lesson activity editing" page + Given I am on the "Test lesson" "lesson activity editing" page logged in as teacher1 And I set the field "id_available_enabled" to "1" And I set the following fields to these values: | available[day] | 1 | @@ -32,18 +36,12 @@ Feature: A teacher can set available from and deadline dates to access a lesson | available[hour] | 08 | | available[minute] | 00 | And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | Description | The first one | - And I press "Save page" When I am on the "Test lesson" "lesson activity" page logged in as student1 Then the activity date in "Test lesson" should contain "Opens: Tuesday, 1 January 2030, 8:00" And I should not see "First page contents" Scenario: Forbidding lesson accesses after a specified date - Given I am on the "Test lesson" "lesson activity editing" page + Given I am on the "Test lesson" "lesson activity editing" page logged in as teacher1 And I set the field "id_deadline_enabled" to "1" And I set the following fields to these values: | deadline[day] | 1 | @@ -52,12 +50,6 @@ Feature: A teacher can set available from and deadline dates to access a lesson | deadline[hour] | 08 | | deadline[minute] | 00 | And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | Description | The first one | - And I press "Save page" When I am on the "Test lesson" "lesson activity" page logged in as student1 Then the activity date in "Test lesson" should contain "Closed: Saturday, 1 January 2000, 8:00" And I should not see "First page contents" diff --git a/mod/lesson/tests/behat/display_lesson_description.feature b/mod/lesson/tests/behat/display_lesson_description.feature index 10b4254c3be..34f210da7ca 100644 --- a/mod/lesson/tests/behat/display_lesson_description.feature +++ b/mod/lesson/tests/behat/display_lesson_description.feature @@ -14,26 +14,22 @@ Feature: Display the lesson description in the lesson and optionally in the cour And the following "course enrolments" exist: | user | course | role | | teacher1 | C1 | editingteacher | - Given the following "activity" exists: - | activity | lesson | - | course | C1 | - | idnumber | 0001 | - | name | Test lesson name | - | intro | Test lesson description | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | Test lesson part 1 | - | Description | Lesson part 1 description | - | Jump | Next page | - And I click on "Save page" "button" + And the following "activity" exist: + | activity | name | intro | course | idnumber | + | lesson | Test lesson name | Test lesson description | C1 | 0001 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | Test lesson part 1 | Test lesson part 1 | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | Test lesson part 1 | Next page | Next page | Scenario: Description is displayed in the Lesson - When I am on the "Test lesson name" "lesson activity" page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Then I should see "Test lesson description" Scenario: Show lesson description in the course homepage - Given I am on the "Test lesson name" "lesson activity editing" page + Given I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And the following fields match these values: | Display description on course page | | And I set the following fields to these values: @@ -43,7 +39,7 @@ Feature: Display the lesson description in the lesson and optionally in the cour Then I should see "Test lesson description" Scenario: Hide lesson description in the course homepage - Given I am on the "Test lesson name" "lesson activity editing" page + Given I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And the following fields match these values: | Display description on course page | | And I press "Save and return to course" diff --git a/mod/lesson/tests/behat/lesson_activity_completion.feature b/mod/lesson/tests/behat/lesson_activity_completion.feature index e1d594b3687..495c65d2065 100644 --- a/mod/lesson/tests/behat/lesson_activity_completion.feature +++ b/mod/lesson/tests/behat/lesson_activity_completion.feature @@ -28,22 +28,14 @@ Feature: View activity completion in the lesson activity | completionendreached | 1 | | completiontimespentenabled | 1 | | completiontimespent | 3 | - And I am on the "Music history" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | Music history part 1 | - | Description | The history of music part 1 | - | Jump | Next page | - And I click on "Save page" "button" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "Essay" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Music essay | - | Page contents | Write a really interesting music essay | - | Jump | End of lesson | - | Score | 1 | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Music history | content | Music history part 1 | | + | Music history | essay | Music essay | Write a really interesting music essay | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Music history part 1 | The history of music part 1 | Next page | 0 | + | Music essay | | Next page | 1 | Scenario: View automatic completion items as a teacher When I am on the "Music history" "lesson activity" page logged in as teacher1 diff --git a/mod/lesson/tests/behat/lesson_complete_report.feature b/mod/lesson/tests/behat/lesson_complete_report.feature index 76d1a37b9a6..32907236bbe 100644 --- a/mod/lesson/tests/behat/lesson_complete_report.feature +++ b/mod/lesson/tests/behat/lesson_complete_report.feature @@ -18,29 +18,18 @@ Feature: Teachers can review student progress on all lessons in a course by view And the following "activities" exist: | activity | name | course | idnumber | retake | | lesson | Test lesson name | C1 | lesson1 | 1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Scenario: View student progress for lesson that was never attempted - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | + And I log in as "teacher1" When I am on "Course 1" course homepage And I navigate to course participants And I follow "Student 1" @@ -48,36 +37,17 @@ Feature: Teachers can review student progress on all lessons in a course by view Then I should see "No attempts have been made on this lesson" Scenario: View student progress for an incomplete lesson containing both content and question pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I log out + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -90,48 +60,21 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "0" in the ".cell.c2" "css_element" Scenario: View student progress for a lesson containing both content and question pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | The sky is Pink. | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + | Test lesson name | truefalse | True/false question 2 | The sky is Pink. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | + | True/false question 2 | False | Correct | Next page | 1 | + | True/false question 2 | True | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -158,22 +101,15 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "1" in the ".cell.c3" "css_element" Scenario: View student attempts in a lesson containing only content pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | + | Second page name | Previous page | Previous page | + | Second page name | End of lesson | End of lesson | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" diff --git a/mod/lesson/tests/behat/lesson_completion_pass_grade.feature b/mod/lesson/tests/behat/lesson_completion_pass_grade.feature index b631bfa3a9d..649467ebe02 100644 --- a/mod/lesson/tests/behat/lesson_completion_pass_grade.feature +++ b/mod/lesson/tests/behat/lesson_completion_pass_grade.feature @@ -9,21 +9,14 @@ Feature: Pass grade activity completion in the lesson activity | student3 | Vinnie | Student3 | student3@example.com | | teacher1 | Darrell | Teacher1 | teacher1@example.com | And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | + | fullname | shortname | category | enablecompletion | showcompletionconditions | + | Course 1 | C1 | 0 | 1 | 1 | And the following "course enrolments" exist: | user | course | role | | student1 | C1 | student | | student2 | C1 | student | | student3 | C1 | student | | teacher1 | C1 | editingteacher | - And I am on the "Course 1" course page logged in as teacher1 - And I navigate to "Settings" in current page administration - And I expand all fieldsets - And I set the following fields to these values: - | Enable completion tracking | Yes | - | Show activity completion conditions | Yes | - And I press "Save and display" And the following "activity" exists: | activity | lesson | | course | C1 | @@ -33,18 +26,13 @@ Feature: Pass grade activity completion in the lesson activity | completion | 2 | | completionusegrade | 1 | | completionpassgrade | 1 | - And I am on the "Music history" "lesson activity" page - And I follow "Add a question page" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Numerical question | - | Page contents | What is 1 + 2? | - | id_answer_editor_0 | 3 | - | id_jumpto_0 | End of lesson | - | id_enableotheranswers | 1 | - | id_jumpto_6 | Next page | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Music history | numeric | Numerical question | What is 1 + 2? | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Numerical question | 3 | End of lesson | 1 | + | Numerical question | @#wronganswer#@ | Next page | 0 | Scenario: View automatic completion items as a teacher When I am on the "Music history" "lesson activity" page logged in as teacher1 diff --git a/mod/lesson/tests/behat/lesson_course_reset.feature b/mod/lesson/tests/behat/lesson_course_reset.feature index 5b647e54fb3..c6b2ca9e8af 100644 --- a/mod/lesson/tests/behat/lesson_course_reset.feature +++ b/mod/lesson/tests/behat/lesson_course_reset.feature @@ -25,20 +25,13 @@ Feature: Lesson reset And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | True/false question 1 | False | Correct | Next page | 1 | + | True/false question 1 | True | Wrong | This page | 0 | Scenario: Use course reset to clear all attempt data When I am on the "Test lesson name" "lesson activity" page logged in as student1 @@ -62,7 +55,7 @@ Feature: Lesson reset @javascript Scenario: Use course reset to remove user overrides. - When I am on the "Test lesson name" "lesson activity" page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 And I navigate to "Overrides" in current page administration And I follow "Add user override" And I set the following fields to these values: @@ -80,7 +73,8 @@ Feature: Lesson reset Then I should not see "Sam1 Student1" Scenario: Use course reset to remove group overrides. - When I navigate to "Overrides" in current page administration + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I navigate to "Overrides" in current page administration And I select "Group overrides" from the "jump" singleselect And I follow "Add group override" And I set the following fields to these values: diff --git a/mod/lesson/tests/behat/lesson_delete_answers.feature b/mod/lesson/tests/behat/lesson_delete_answers.feature index 571d4fca3cc..b836daf07c8 100644 --- a/mod/lesson/tests/behat/lesson_delete_answers.feature +++ b/mod/lesson/tests/behat/lesson_delete_answers.feature @@ -20,31 +20,18 @@ branch table contents And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | First page name | Previous page | | Previous page | 0 | + | Hardest question ever | 2 | Correct answer | End of lesson | 1 | + | Hardest question ever | 1 | Incorrect answer | First page name | 0 | And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | Previous page | - | id_jumpto_1 | Previous page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2 | - | id_response_editor_0 | Correct answer | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | 1 | - | id_response_editor_1 | Incorrect answer | - | id_jumpto_1 | First page name | - | id_score_1 | 0 | - And I press "Save page" + And I press "Edit lesson" And I select edit type "Expanded" Scenario: Edit lesson content page diff --git a/mod/lesson/tests/behat/lesson_edit_pages.feature b/mod/lesson/tests/behat/lesson_edit_pages.feature index 26a957c4ba8..d6fa377e384 100644 --- a/mod/lesson/tests/behat/lesson_edit_pages.feature +++ b/mod/lesson/tests/behat/lesson_edit_pages.feature @@ -19,39 +19,21 @@ Feature: In a lesson activity, teacher can edit lesson's pages And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | Hardest question ever | 2 | Correct answer | End of lesson | 1 | + | Hardest question ever | 1 | Incorrect answer | Second page name | 0 | And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + And I press "Edit lesson" And I select edit type "Expanded" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2 | - | id_response_editor_0 | Correct answer | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | 1 | - | id_response_editor_1 | Incorrect answer | - | id_jumpto_1 | Second page name | - | id_score_1 | 0 | - And I press "Save page" Scenario: Edit lesson content page Given I click on "//th[normalize-space(.)='Second page name']/descendant::a[3]" "xpath_element" diff --git a/mod/lesson/tests/behat/lesson_essay_question.feature b/mod/lesson/tests/behat/lesson_essay_question.feature index 3175432d23f..5d8d54404ae 100644 --- a/mod/lesson/tests/behat/lesson_essay_question.feature +++ b/mod/lesson/tests/behat/lesson_essay_question.feature @@ -18,14 +18,12 @@ Feature: In a lesson activity, teacher can add an essay question And the following "activities" exist: | activity | name | course | idnumber | feedback | | lesson | Test lesson name | C1 | lesson1 | 1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "Essay" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Essay question | - | Page contents |

Please write a story about a frog.

| - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | essay | Essay question |

Please write a story about a frog.

| + And the following "mod_lesson > answer" exist: + | page | jumpto | score | + | Essay question | Next page | 1 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 Then I should see "Please write a story about a frog." And I set the field "Your answer" to "

Once upon a time there was a little green frog." diff --git a/mod/lesson/tests/behat/lesson_group_override.feature b/mod/lesson/tests/behat/lesson_group_override.feature index 8b574db9ae4..74bce42e7f8 100644 --- a/mod/lesson/tests/behat/lesson_group_override.feature +++ b/mod/lesson/tests/behat/lesson_group_override.feature @@ -32,20 +32,13 @@ Feature: Lesson group override And the following "activities" exist: | activity | name | groupmode | course | idnumber | | lesson | Test lesson name | 1 | C1 | lesson1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | True/false question 1 | False | Correct | Next page | 1 | + | True/false question 1 | True | Wrong | This page | 0 | Scenario: Add, modify then delete a group override Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 diff --git a/mod/lesson/tests/behat/lesson_informations_at_end.feature b/mod/lesson/tests/behat/lesson_informations_at_end.feature index 22c499f2ac1..a62842457e6 100644 --- a/mod/lesson/tests/behat/lesson_informations_at_end.feature +++ b/mod/lesson/tests/behat/lesson_informations_at_end.feature @@ -20,31 +20,20 @@ Feature: In a lesson activity, if custom scoring is not enabled, student should And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Hardest question ever | 2 | Correct answer | Next page | 1 | + | Hardest question ever | 1 | Incorrect answer | This page | 0 | And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | Maximum grade | 75 | | Custom scoring | No | And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2 | - | id_response_editor_0 | Correct answer | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | 1 | - | id_response_editor_1 | Incorrect answer | - | id_jumpto_1 | This page | - And I press "Save page" And I am on "Course 1" course homepage with editing mode on And I duplicate "Test lesson name" activity And I wait until section "1" is available diff --git a/mod/lesson/tests/behat/lesson_navigation.feature b/mod/lesson/tests/behat/lesson_navigation.feature index 0f197c55ebf..37514f01d45 100644 --- a/mod/lesson/tests/behat/lesson_navigation.feature +++ b/mod/lesson/tests/behat/lesson_navigation.feature @@ -19,42 +19,20 @@ Feature: In a lesson activity, students can navigate through a series of pages i And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And I log in as "teacher1" Scenario: Student navigation with pages and questions - Given I am on the "Test lesson name" "lesson activity" page - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2 | - | id_response_editor_0 | Correct answer | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | 1 | - | id_response_editor_1 | Incorrect answer | - | id_jumpto_1 | Second page name | - | id_score_1 | 0 | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | Hardest question ever | 2 | Correct answer | End of lesson | 1 | + | Hardest question ever | 1 | Incorrect answer | Second page name | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 Then I should see "First page contents" And I press "Next page" @@ -84,21 +62,18 @@ Feature: In a lesson activity, students can navigate through a series of pages i And I should see "Your score is 0 (out of 1)." Scenario: Student reattempts a question until out of attempts - Given I am on the "Test lesson name" "lesson activity editing" page + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | Test question | Test content | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Test question | right | Next page | 1 | + | Test question | wrong | This page | 0 | + And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | id_review | Yes | | id_maxattempts | 3 | And I press "Save and display" - And I follow "Add a question page" - And I set the following fields to these values: - | id_qtype | True/false | - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Test question | - | Page contents | Test content | - | id_answer_editor_0 | right | - | id_answer_editor_1 | wrong | - And I press "Save page" When I am on the "Test lesson name" "lesson activity" page logged in as student1 Then I should see "Test content" And I set the following fields to these values: @@ -121,32 +96,21 @@ Feature: In a lesson activity, students can navigate through a series of pages i And I should see "Congratulations - end of lesson reached" Scenario: Student reattempts a question until out of attempts with specific jumps - Given I am on the "Test lesson name" "lesson activity editing" page + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | Test question | Test content 1 | + | Test lesson name | truefalse | Test question 2 | Test content 2 | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Test question | right | Next page | 1 | + | Test question | wrong | This page | 0 | + | Test question 2 | right | Test question | 1 | + | Test question 2 | wrong | Test question | 0 | + And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: - | id_review | Yes | - | id_maxattempts | 3 | + | id_review | Yes | + | id_maxattempts | 3 | And I press "Save and display" - And I follow "Add a question page" - And I set the following fields to these values: - | id_qtype | True/false | - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Test question | - | Page contents | Test content 1 | - | id_answer_editor_0 | right | - | id_answer_editor_1 | wrong | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Test question 2 | - | Page contents | Test content 2 | - | id_answer_editor_0 | right | - | id_jumpto_0 | Test question | - | id_answer_editor_1 | wrong | - | id_jumpto_1 | Test question | - And I press "Save page" When I am on the "Test lesson name" "lesson activity" page logged in as student1 Then I should see "Test content 1" And I set the following fields to these values: @@ -173,21 +137,18 @@ Feature: In a lesson activity, students can navigate through a series of pages i And I should see "Test content 1" Scenario: Student should not see remaining attempts notification if maximum number of attempts is set to unlimited - Given I am on the "Test lesson name" "lesson activity editing" page + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | Test question | Test content | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Test question | right | Next page | 1 | + | Test question | wrong | This page | 0 | + And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | id_review | Yes | | id_maxattempts | 0 | And I press "Save and display" - And I follow "Add a question page" - And I set the following fields to these values: - | id_qtype | True/false | - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Test question | - | Page contents | Test content | - | id_answer_editor_0 | right | - | id_answer_editor_1 | wrong | - And I press "Save page" When I am on the "Test lesson name" "lesson activity" page logged in as student1 Then I should see "Test content" And I set the following fields to these values: diff --git a/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature b/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature index 310052d1d0a..b8bc847f77a 100644 --- a/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature +++ b/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature @@ -27,7 +27,20 @@ Feature: In Dashboard, teacher can see the number of student attempts to lessons | idnumber | 0001 | | name | Test lesson name | | retake | 1 | - When I am on the "Test lesson name" "lesson activity editing" page + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | + | Test lesson name | truefalse | True/false question 2 | Paper is made from trees. | + | Test lesson name | truefalse | True/false question 3 | 1+1=2 | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | True/false question 1 | False | Correct | Next page | 1 | + | True/false question 1 | True | Wrong | This page | 0 | + | True/false question 2 | True | Correct | Next page | 1 | + | True/false question 2 | False | Wrong | This page | 0 | + | True/false question 3 | True | Correct | Next page | 1 | + | True/false question 3 | False | Wrong | This page | 0 | + And I am on the "Test lesson name" "lesson activity editing" page And I expand all fieldsets And I set the following fields to these values: | id_deadline_enabled | 1 | @@ -37,47 +50,7 @@ Feature: In Dashboard, teacher can see the number of student attempts to lessons | deadline[hour] | 08 | | deadline[minute] | 00 | And I press "Save and display" - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 3 | - | Page contents | 1+1=2 | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 + When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "Cat is an amphibian" And I set the following fields to these values: | False | 1 | diff --git a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature index 1be05ec5fab..7a7b39dc356 100644 --- a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature +++ b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature @@ -19,22 +19,37 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac And the following "activities" exist: | activity | name | course | idnumber | modattempts | | lesson | Test lesson name | C1 | lesson1 | 1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | Hardest question ever | 2.87 | Correct answer | End of lesson | 1 | + | Hardest question ever | 2.1:2.8 | Incorrect answer | This page | 0 | + + Scenario: Create a numerical question with the locale specific variables + Given the following "activities" exist: + | activity | name | course | idnumber | modattempts | + | lesson | Empty lesson name | C1 | lesson2 | 1 | + And I am on the "Empty lesson name" "lesson activity" page logged in as teacher1 + When I follow "Add a question page" And I set the field "Select a question type" to "Numerical" And I press "Add a question page" And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2#87 | + | Page title | Second question | + | Page contents | 2 + 2? | + | id_answer_editor_0 | 4#87 | | id_response_editor_0 | Correct answer | | id_jumpto_0 | End of lesson | | id_score_0 | 1 | - | id_answer_editor_1 | 2#1:2#8 | + | id_answer_editor_1 | 4#1:4#8 | | id_response_editor_1 | Incorrect answer | | id_jumpto_1 | This page | | id_score_1 | 0 | And I press "Save page" + And I follow "Second question" + Then I should see "4#87" + And I should see "4#1:4#8" Scenario: Edit a numerical question with the locale specific variables Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 diff --git a/mod/lesson/tests/behat/lesson_outline_report.feature b/mod/lesson/tests/behat/lesson_outline_report.feature index d31470bb6b9..183de7a733b 100644 --- a/mod/lesson/tests/behat/lesson_outline_report.feature +++ b/mod/lesson/tests/behat/lesson_outline_report.feature @@ -24,62 +24,35 @@ Feature: Teachers can review student progress on all lessons in a course by view And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Scenario: View student progress for lesson that was never attempted - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - When I am on "Course 1" course homepage + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | + When I log in as "teacher1" + And I am on "Course 1" course homepage And I navigate to course participants And I follow "Student 1" And I follow "Outline report" Then I should see "No attempts have been made on this lesson" Scenario: View student progress for an incomplete lesson containing both content and question pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -90,35 +63,18 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "Lesson has been started, but not yet completed" Scenario: View student progress for a lesson containing both content and question pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -137,22 +93,15 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "Grade: 100.00 / 100.00" Scenario: View student attempts in a lesson containing only content pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | First page name | Next page | Next page | 0 | + | Second page name | Previous page | Previous page | 0 | + | Second page name | End of lesson | End of lesson | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" diff --git a/mod/lesson/tests/behat/lesson_practice.feature b/mod/lesson/tests/behat/lesson_practice.feature index 38beffc38d7..35214daf307 100644 --- a/mod/lesson/tests/behat/lesson_practice.feature +++ b/mod/lesson/tests/behat/lesson_practice.feature @@ -21,17 +21,14 @@ Feature: Practice mode in a lesson activity | course | C1 | | idnumber | 0001 | | name | Test lesson name | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True or False | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_answer_editor_1 | False | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity editing" page + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True or False | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | True or False | True | Next page | 1 | + | True or False | False | This page | 0 | + And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 Scenario: Non-practice lesson records grades in the gradebook Given I set the following fields to these values: diff --git a/mod/lesson/tests/behat/lesson_progress_bar.feature b/mod/lesson/tests/behat/lesson_progress_bar.feature index 8fba00a7219..b65adc13f04 100644 --- a/mod/lesson/tests/behat/lesson_progress_bar.feature +++ b/mod/lesson/tests/behat/lesson_progress_bar.feature @@ -19,42 +19,22 @@ Feature: In a lesson activity, students can see their progress viewing a progres And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | Hardest question ever | 2 | Correct answer | End of lesson | 1 | + | Hardest question ever | 1 | Incorrect answer | First page name | 0 | And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | Progress bar | Yes | And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2 | - | id_response_editor_0 | Correct answer | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | 1 | - | id_response_editor_1 | Incorrect answer | - | id_jumpto_1 | Second page name | - | id_score_1 | 0 | - And I press "Save page" When I am on the "Test lesson name" "lesson activity" page logged in as student1 Then I should see "First page contents" And I should see "You have completed 0% of the lesson" diff --git a/mod/lesson/tests/behat/lesson_question_attempts.feature b/mod/lesson/tests/behat/lesson_question_attempts.feature index 48721426b5c..7f0c32b5a1c 100644 --- a/mod/lesson/tests/behat/lesson_question_attempts.feature +++ b/mod/lesson/tests/behat/lesson_question_attempts.feature @@ -22,71 +22,27 @@ Feature: In a lesson activity, students can not re-attempt a question more than | name | Test lesson name | | retake | 1 | | minquestions | 3 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Third page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 3 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Kermit is a frog | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | The earth is round. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | truefalse | True/false question 1 | The earth is round. | + | Test lesson name | truefalse | True/false question 2 | Kermit is a frog | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | truefalse | True/false question 3 | Paper is made from trees. | + | Test lesson name | content | Third page name | Third page contents | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | + | True/false question 2 | True | Correct | Next page | 1 | + | True/false question 2 | False | Wrong | This page | 0 | + | True/false question 3 | True | Correct | Next page | 1 | + | True/false question 3 | False | Wrong | This page | 0 | + | Third page name | Previous page | | Previous page | 0 | + | Third page name | Next page | | Next page | 0 | Scenario: Check that we can leave a quiz and when we re-enter we can not re-attempt the question again Given I am on the "Test lesson name" "lesson activity" page logged in as student1 diff --git a/mod/lesson/tests/behat/lesson_report.feature b/mod/lesson/tests/behat/lesson_report.feature index ee2b9074bc9..3d7f4ff9bbf 100644 --- a/mod/lesson/tests/behat/lesson_report.feature +++ b/mod/lesson/tests/behat/lesson_report.feature @@ -19,60 +19,26 @@ Feature: In a lesson activity, teachers can review student attempts And the following "activities" exist: | activity | name | course | idnumber | retake | | lesson | Test lesson name | C1 | lesson1 | 1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Scenario: View student attempts in a lesson containing both content and question pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Kermit is a frog | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Third page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | content | Third page name | Third page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + | Test lesson name | truefalse | True/false question 2 | Kermit is a frog | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | Third page name | Previous page | | Previous page | 0 | + | Third page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | + | True/false question 2 | True | Correct | Next page | 1 | + | True/false question 2 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -100,40 +66,21 @@ Feature: In a lesson activity, teachers can review student attempts And I should see "Low score" Scenario: View student attempts in a lesson containing only content pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Fourth page name | - | Page contents | Fourth page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Third page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | content | Third page name | Third page contents | + | Test lesson name | content | Fourth page name | Fourth page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | + | Second page name | Previous page | Previous page | + | Second page name | Next page | Next page | + | Third page name | Previous page | Previous page | + | Third page name | Next page | Next page | + | Fourth page name | Previous page | Previous page | + | Fourth page name | End of lesson | End of lesson | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" diff --git a/mod/lesson/tests/behat/lesson_report_detailed_statistics.feature b/mod/lesson/tests/behat/lesson_report_detailed_statistics.feature index 16f275ce328..f741b275a26 100644 --- a/mod/lesson/tests/behat/lesson_report_detailed_statistics.feature +++ b/mod/lesson/tests/behat/lesson_report_detailed_statistics.feature @@ -24,15 +24,12 @@ Feature: In a lesson activity, teachers can view detailed statistics report And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Scenario: View detailed statistics in a lesson when empty string is given as answer - Given I follow "Add a question page" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Numerical question | - | Page contents | What is 1 + 0.5? | - | id_answer_editor_0 | 1.5 | - | id_jumpto_0 | End of lesson | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | numeric | Numerical question | What is 1 + 0.5? | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Numerical question | 1.5 | End of lesson | 1 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I press "Submit" And I log out diff --git a/mod/lesson/tests/behat/lesson_review.feature b/mod/lesson/tests/behat/lesson_review.feature index 5fe06a81309..58012ab6603 100644 --- a/mod/lesson/tests/behat/lesson_review.feature +++ b/mod/lesson/tests/behat/lesson_review.feature @@ -16,9 +16,19 @@ Feature: In a lesson activity, students can review the answers they gave to ques | user | course | role | | teacher1 | C1 | editingteacher | | student1 | C1 | student | - Given the following "activities" exist: + And the following "activity" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | numeric | Hardest question ever | 1 + 1? | + | Test lesson name | truefalse | Next question | Paper is made from trees. | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | Hardest question ever | 2 | Correct answer | Next page | 1 | + | Hardest question ever | 1 | Incorrect answer | This page | 0 | + | Next question | True | Correct | Next page | 1 | + | Next question | False | Wrong | This page | 0 | And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | Display ongoing score | Yes | @@ -29,32 +39,6 @@ Feature: In a lesson activity, students can review the answers they gave to ques | Custom scoring | No | | Re-takes allowed | Yes | And I press "Save and display" - And I follow "Add a question page" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Hardest question ever | - | Page contents | 1 + 1? | - | id_answer_editor_0 | 2 | - | id_response_editor_0 | Correct answer | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | 1 | - | id_response_editor_1 | Incorrect answer | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Next question | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" And I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "You have answered 0 correctly out of 0 attempts." And I set the following fields to these values: diff --git a/mod/lesson/tests/behat/lesson_student_resume.feature b/mod/lesson/tests/behat/lesson_student_resume.feature index 73be4605071..6a7f7f0b97d 100644 --- a/mod/lesson/tests/behat/lesson_student_resume.feature +++ b/mod/lesson/tests/behat/lesson_student_resume.feature @@ -20,60 +20,26 @@ Feature: In a lesson activity a student should | course | C1 | | idnumber | 0001 | | retake | 1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Scenario: resume a lesson with both content then question pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Kermit is a frog | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Third page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | content | Third page name | Third page contents | + | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | + | Test lesson name | truefalse | True/false question 2 | Kermit is a frog | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | Third page name | Previous page | | Previous page | 0 | + | Third page name | Next page | | Next page | 0 | + | True/false question 1 | True | Correct | Next page | 1 | + | True/false question 1 | False | Wrong | This page | 0 | + | True/false question 2 | True | Correct | Next page | 1 | + | True/false question 2 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -116,40 +82,21 @@ Feature: In a lesson activity a student should And I should see "Congratulations - end of lesson reached" Scenario: resume a lesson with only content pages - Given I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Fourth page name | - | Page contents | Fourth page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Third page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | content | Third page name | Third page contents | + | Test lesson name | content | Fourth page name | Fourth page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | + | Second page name | Previous page | Previous page | + | Second page name | Next page | Next page | + | Third page name | Previous page | Previous page | + | Third page name | Next page | Next page | + | Fourth page name | Previous page | Previous page | + | Fourth page name | End of lesson | End of lesson | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "First page contents" And I press "Next page" @@ -173,92 +120,36 @@ Feature: In a lesson activity a student should And I should see "First page contents" Scenario: resume a lesson with both question then content pages - Given I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 5 | - | Page contents | Kermit is a frog | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Content page 2 | - | Page contents | Second content page | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 4 | - | Page contents | 2+2=4 | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 3 | - | Page contents | 1+1=2 | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Content page 1 | - | Page contents | First content page | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | + | Test lesson name | content | First page name | First page contents | + | Test lesson name | truefalse | True/false question 2 | Paper is made from trees. | + | Test lesson name | truefalse | True/false question 3 | 1+1=2 | + | Test lesson name | truefalse | True/false question 4 | 2+2=4 | + | Test lesson name | content | Second page name | Second page contents | + | Test lesson name | truefalse | True/false question 5 | Kermit is a frog | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | True/false question 1 | False | Correct | Next page | 1 | + | True/false question 1 | True | Wrong | This page | 0 | + | First page name | Next page | | Next page | 0 | + | True/false question 2 | True | Correct | Next page | 1 | + | True/false question 2 | False | Wrong | This page | 0 | + | True/false question 3 | True | Correct | Next page | 1 | + | True/false question 3 | False | Wrong | This page | 0 | + | True/false question 4 | True | Correct | Next page | 1 | + | True/false question 4 | False | Wrong | This page | 0 | + | Second page name | Next page | | Next page | 0 | + | True/false question 5 | True | Correct | Next page | 1 | + | True/false question 5 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "Cat is an amphibian" And I set the following fields to these values: | False | 1 | And I press "Submit" And I press "Continue" - And I should see "First content page" + And I should see "First page contents" And I press "Next page" And I should see "Paper is made from trees." And I set the following fields to these values: @@ -285,13 +176,13 @@ Feature: In a lesson activity a student should And I wait "1" seconds And I press "Submit" And I press "Continue" - And I should see "Second content page" + And I should see "Second page contents" And I am on "Course 1" course homepage And I follow "Test lesson name" And I should see "You have seen more than one page of this lesson already." And I should see "Do you want to start at the last page you saw?" And I follow "Yes" - And I should see "Second content page" + And I should see "Second page contents" And I press "Next page" And I should see "Kermit is a frog" And I set the following fields to these values: @@ -301,71 +192,25 @@ Feature: In a lesson activity a student should And I should see "Congratulations - end of lesson reached" Scenario: resume a lesson with only question pages - Given I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 5 | - | Page contents | Kermit is a frog | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 4 | - | Page contents | 2+2=4 | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 3 | - | Page contents | 1+1=2 | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | + | Test lesson name | truefalse | True/false question 2 | Paper is made from trees. | + | Test lesson name | truefalse | True/false question 3 | 1+1=2 | + | Test lesson name | truefalse | True/false question 4 | 2+2=4 | + | Test lesson name | truefalse | True/false question 5 | Kermit is a frog | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | True/false question 1 | False | Correct | Next page | 1 | + | True/false question 1 | True | Wrong | This page | 0 | + | True/false question 2 | True | Correct | Next page | 1 | + | True/false question 2 | False | Wrong | This page | 0 | + | True/false question 3 | True | Correct | Next page | 1 | + | True/false question 3 | False | Wrong | This page | 0 | + | True/false question 4 | True | Correct | Next page | 1 | + | True/false question 4 | False | Wrong | This page | 0 | + | True/false question 5 | True | Correct | Next page | 1 | + | True/false question 5 | False | Wrong | This page | 0 | When I am on the "Test lesson name" "lesson activity" page logged in as student1 And I should see "Cat is an amphibian" And I set the following fields to these values: diff --git a/mod/lesson/tests/behat/lesson_user_override.feature b/mod/lesson/tests/behat/lesson_user_override.feature index 47a33997384..6acdb3e9136 100644 --- a/mod/lesson/tests/behat/lesson_user_override.feature +++ b/mod/lesson/tests/behat/lesson_user_override.feature @@ -21,20 +21,13 @@ Feature: Lesson user override And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | + And the following "mod_lesson > answer" exist: + | page | answer | response | jumpto | score | + | True/false question 1 | False | Correct | Next page | 1 | + | True/false question 1 | True | Wrong | This page | 0 | @javascript Scenario: Add, modify then delete a user override diff --git a/mod/lesson/tests/behat/link_to_gradebook.feature b/mod/lesson/tests/behat/link_to_gradebook.feature index f9c33f6940e..024a014544d 100644 --- a/mod/lesson/tests/behat/link_to_gradebook.feature +++ b/mod/lesson/tests/behat/link_to_gradebook.feature @@ -19,23 +19,15 @@ Feature: link to gradebook on the end of lesson page And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson | C1 | lesson1 | - And I am on the "Test lesson" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson | content | First page name | First page contents | + | Test lesson | content | Second page name | Second page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | Next page | Next page | + | Second page name | Previous page | Previous page | + | Second page name | Next page | Next page | Scenario: Link to gradebook for non practice lesson When I am on the "Test lesson" "lesson activity" page logged in as student1 @@ -49,7 +41,7 @@ Feature: link to gradebook on the end of lesson page And I should see "Test lesson" Scenario: No link to gradebook for non graded lesson - Given I am on the "Test lesson" "lesson activity editing" page + Given I am on the "Test lesson" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | Type | None | And I press "Save and display" @@ -60,7 +52,7 @@ Feature: link to gradebook on the end of lesson page And I should not see "View grades" Scenario: No link to gradebook for practice lesson - Given I am on the "Test lesson" "lesson activity editing" page + Given I am on the "Test lesson" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | Practice lesson | Yes | And I press "Save and display" @@ -71,7 +63,8 @@ Feature: link to gradebook on the end of lesson page And I should not see "View grades" Scenario: No link if Show gradebook to student disabled - Given I am on "Course 1" course homepage + Given I log in as "teacher1" + And I am on "Course 1" course homepage And I navigate to "Settings" in current page administration And I set the following fields to these values: | Show gradebook to students | No | diff --git a/mod/lesson/tests/behat/password_protection.feature b/mod/lesson/tests/behat/password_protection.feature index 7e348eeaddf..63ffd65404f 100644 --- a/mod/lesson/tests/behat/password_protection.feature +++ b/mod/lesson/tests/behat/password_protection.feature @@ -23,13 +23,12 @@ Feature: A teacher can password protect a lesson | name | Test lesson | | usepassword | 1 | | password | moodle_rules | - And I am on the "Test lesson" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | Description | The first one | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson | content | First page name | First page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | First page name | The first one | Next page | When I am on the "Test lesson" "lesson activity" page logged in as student1 Then I should see "Test lesson is a password protected lesson" And I should not see "First page contents" diff --git a/mod/lesson/tests/behat/teacher_grade_essays.feature b/mod/lesson/tests/behat/teacher_grade_essays.feature index 896488a0e27..f3f3d4c34b6 100644 --- a/mod/lesson/tests/behat/teacher_grade_essays.feature +++ b/mod/lesson/tests/behat/teacher_grade_essays.feature @@ -36,17 +36,16 @@ Feature: In a lesson activity, a non editing teacher can grade essay questions And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | essay | Essay question |

Please write a story about a frog.

| + And the following "mod_lesson > answer" exist: + | page | jumpto | score | + | Essay question | Next page | 1 | And I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 And I set the following fields to these values: | Group mode | Separate groups | And I press "Save and display" - And I follow "Add a question page" - And I set the field "Select a question type" to "Essay" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Essay question | - | Page contents |

Please write a story about a frog.

| - And I press "Save page" And I am on the "Test lesson name" "lesson activity" page logged in as student1 And I set the field "Your answer" to "

Once upon a time there was a little green frog." And I press "Submit" diff --git a/mod/lesson/tests/behat/time_limit.feature b/mod/lesson/tests/behat/time_limit.feature index 420e91922b5..8024910d9be 100644 --- a/mod/lesson/tests/behat/time_limit.feature +++ b/mod/lesson/tests/behat/time_limit.feature @@ -20,6 +20,12 @@ Feature: A teacher can set a time limit for a lesson And the following "activities" exist: | activity | course | name | | lesson | C1 | Test lesson | + And the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson | content | Lesson page name | Single lesson page contents | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | + | Lesson page name | Single button | This page | And I am on the "Test lesson" "lesson activity editing" page logged in as teacher1 And I expand all fieldsets And I set the following fields to these values: @@ -27,12 +33,6 @@ Feature: A teacher can set a time limit for a lesson | timelimit[timeunit] | 1 | | timelimit[number] | 10 | And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | Lesson page name | - | Page contents | Single lesson page contents | - | Description | Single button | - And I press "Save page" When I am on the "Test lesson" "lesson activity" page logged in as student1 Then I should see "You have 10 secs to finish the lesson." And I wait "3" seconds diff --git a/mod/lesson/tests/behat/wrong_answer_continue.feature b/mod/lesson/tests/behat/wrong_answer_continue.feature index b9095b4e27c..c31c9b18517 100644 --- a/mod/lesson/tests/behat/wrong_answer_continue.feature +++ b/mod/lesson/tests/behat/wrong_answer_continue.feature @@ -26,24 +26,15 @@ Feature: An incorrect response to an answer with multiple attempts show appropri And I press "Save and display" Scenario: A student answering incorrectly to a question will see an option to move to the next question if set up. - Given I follow "Add a question page" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Numerical question | - | Page contents | What is 1 + 2? | - | id_answer_editor_0 | 3 | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | 2 | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Just move on page | - | Page contents | You are here to move on | - | id_answer_editor_0 | End this lesson | - | id_jumpto_0 | End of lesson | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | numeric | Numerical question | What is 1 + 2? | + | Test lesson name | content | Just move on page | You are here to move on | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Numerical question | 3 | Next page | 1 | + | Numerical question | 2 | Next page | 0 | + | Just move on page | End this lesson | End of lesson | 0 | And I am on the "Test lesson name" "lesson activity" page logged in as student1 When I set the field "Your answer" to "2" And I press "Submit" @@ -53,22 +44,14 @@ Feature: An incorrect response to an answer with multiple attempts show appropri Then I should see "You are here to move on" Scenario: A student answering incorrectly to a question will only see an option to try again if there is no matching wrong response. - Given I follow "Add a question page" - And I set the field "Select a question type" to "Numerical" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Numerical question | - | Page contents | What is 1 + 2? | - | id_answer_editor_0 | 3 | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Just move on page | - | Page contents | You are here to move on | - | id_answer_editor_0 | End this lesson | - | id_jumpto_0 | End of lesson | - And I press "Save page" + Given the following "mod_lesson > page" exist: + | lesson | qtype | title | content | + | Test lesson name | numeric | Numerical question | What is 1 + 2? | + | Test lesson name | content | Just move on page | You are here to move on | + And the following "mod_lesson > answer" exist: + | page | answer | jumpto | score | + | Numerical question | 3 | Next page | 1 | + | Just move on page | End this lesson | End of lesson | 0 | And I am on the "Test lesson name" "lesson activity" page logged in as student1 When I set the field "Your answer" to "2" And I press "Submit" From a979e0ce97a819d8251380513f68a8dfb8673819 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Fri, 2 Jun 2023 12:45:11 +0200 Subject: [PATCH 4/8] MDL-77581 behat: Remove lesson_student_dashboard test file After f7c476bac56b2e1bbcebb94ef6af6248bd2bdc20 was integrated, these tests didn't assert anything specific and similar steps are already tested in lesson_navigation --- .../behat/lesson_student_dashboard.feature | 325 ------------------ 1 file changed, 325 deletions(-) delete mode 100644 mod/lesson/tests/behat/lesson_student_dashboard.feature diff --git a/mod/lesson/tests/behat/lesson_student_dashboard.feature b/mod/lesson/tests/behat/lesson_student_dashboard.feature deleted file mode 100644 index 1ca18de2304..00000000000 --- a/mod/lesson/tests/behat/lesson_student_dashboard.feature +++ /dev/null @@ -1,325 +0,0 @@ -@mod @mod_lesson -Feature: In Dashboard, a student can see their current status on all lessons with an upcoming due date - In order to know my status on a lesson - As a student - I need to see it in Dashboard - - Background: - Given the following "users" exist: - | username | firstname | lastname | email | - | teacher1 | Teacher | 1 | teacher1@example.com | - | student1 | Student | 1 | student1@example.com | - And the following "courses" exist: - | fullname | shortname | category | - | Course 1 | C1 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C1 | editingteacher | - | student1 | C1 | student | - And the following "activities" exist: - | activity | name | deadline | retake | course | idnumber | - | lesson | Test lesson name | 1893481200 | 1 | C1 | lesson1 | - - Scenario: A completed lesson with only questions that allows multiple attempts - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "Cat is an amphibian" - And I set the following fields to these values: - | False | 1 | - And I press "Submit" - And I press "Continue" - And I should see "Paper is made from trees." - And I set the following fields to these values: - | False | 1 | - And I press "Submit" - And I press "Continue" - And I should see "Congratulations - end of lesson reached" - - Scenario: A completed lesson with only questions that does not allow multiple attempts - Given I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 - And I set the following fields to these values: - | Re-takes allowed | 0 | - And I press "Save and display" - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "Cat is an amphibian" - And I set the following fields to these values: - | False | 1 | - And I press "Submit" - And I press "Continue" - And I should see "Paper is made from trees." - And I set the following fields to these values: - | False | 1 | - And I press "Submit" - And I press "Continue" - And I should see "Congratulations - end of lesson reached" - - Scenario: A completed lesson with only content pages that allows multiple attempts - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "First page contents" - And I press "Next page" - And I should see "Second page contents" - And I press "End of lesson" - - Scenario: A completed lesson with only content pages that does not allow multiple attempts - Given I am on the "Test lesson name" "lesson activity editing" page logged in as teacher1 - And I set the following fields to these values: - | Re-takes allowed | 0 | - And I press "Save and display" - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "First page contents" - And I press "Next page" - And I should see "Second page contents" - And I press "End of lesson" - - Scenario: An incomplete lesson with only questions. - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "Cat is an amphibian" - And I set the following fields to these values: - | False | 1 | - And I press "Submit" - And I press "Continue" - - Scenario: An incomplete lesson with only content pages. - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "First page contents" - And I press "Next page" - And I should see "Second page contents" - - Scenario: A lesson with only questions that has not been started. - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | Cat is an amphibian | - | id_answer_editor_0 | False | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | True | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | Paper is made from trees. | - | id_answer_editor_0 | True | - | id_response_editor_0 | Correct | - | id_jumpto_0 | Next page | - | id_answer_editor_1 | False | - | id_response_editor_1 | Wrong | - | id_jumpto_1 | This page | - And I press "Save page" - - Scenario: A lesson with only content pages that has not been started. - Given I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | End of lesson | - | id_jumpto_1 | End of lesson | - And I press "Save page" - - Scenario: Viewing the status for multiple lessons in multiple courses - Given the following "courses" exist: - | fullname | shortname | category | - | Course 2 | C2 | 0 | - And the following "course enrolments" exist: - | user | course | role | - | teacher1 | C2 | editingteacher | - | student1 | C2 | student | - And the following "activities" exist: - | activity | name | deadline | retake | course | idnumber | - | lesson | Test lesson name 2 | 1893481200 | 1 | C1 | lesson1 | - | lesson | Test lesson name 3 | 1893481200 | 1 | C2 | lesson1 | - And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question | - | Page contents | D035 M00d13 r0x0rz j00 b0x0rs? | - | id_answer_editor_0 | True | - | id_answer_editor_1 | False | - And I press "Save page" - And I am on the "Test lesson name 2" "lesson activity" page - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question | - | Page contents | D035 M00d13 r0x0rz j00 b0x0rs? | - | id_answer_editor_0 | True | - | id_answer_editor_1 | False | - And I press "Save page" - And I am on the "Test lesson name 3" "lesson activity" page - And I follow "Add a question page" - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 1 | - | Page contents | D035 M00d13 r0x0rz j00 b0x0rs? | - | id_answer_editor_0 | True | - | id_answer_editor_1 | False | - And I press "Save page" - And I select "Add a question page" from the "qtype" singleselect - And I set the field "Select a question type" to "True/false" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | True/false question 2 | - | Page contents | D035 M00d13 r0x0rz j00 b0x0rs? | - | id_answer_editor_0 | True | - | id_answer_editor_1 | False | - And I press "Save page" - And I am on the "Test lesson name" "lesson activity" page logged in as student1 - And I should see "D035 M00d13 r0x0rz j00 b0x0rs?" - And I set the following fields to these values: - | True | 1 | - And I press "Submit" - And I am on the "Test lesson name 3" "lesson activity" page - And I should see "D035 M00d13 r0x0rz j00 b0x0rs?" - And I set the following fields to these values: - | True | 1 | - And I press "Submit" From cac02a15b6de2dba2094ed698cef00b91b0a3534 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 6 Jun 2023 10:32:15 +0200 Subject: [PATCH 5/8] MDL-77581 lesson: Fix wrong PHPDoc in some generator functions While creating the new perform_create_page function I noticed that the PHPDoc return type of the existing functions was wrong --- mod/lesson/tests/generator/lib.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mod/lesson/tests/generator/lib.php b/mod/lesson/tests/generator/lib.php index 9290f88f280..2e04056b5aa 100644 --- a/mod/lesson/tests/generator/lib.php +++ b/mod/lesson/tests/generator/lib.php @@ -194,7 +194,7 @@ class mod_lesson_generator extends testing_module_generator { * * @param stdClass $lesson instance where to create the page. * @param array|stdClass $record data for page being generated. - * @return int Page ID. + * @return stdClass page record. */ public function create_content($lesson, $record = array()) { global $DB, $CFG; @@ -223,7 +223,7 @@ class mod_lesson_generator extends testing_module_generator { * Create True/false question pages. * @param object $lesson * @param array $record - * @return int + * @return stdClass page record. */ public function create_question_truefalse($lesson, $record = array()) { global $DB, $CFG; @@ -275,7 +275,7 @@ class mod_lesson_generator extends testing_module_generator { * Create multichoice question pages. * @param object $lesson * @param array $record - * @return int + * @return stdClass page record. */ public function create_question_multichoice($lesson, $record = array()) { global $DB, $CFG; @@ -327,7 +327,7 @@ class mod_lesson_generator extends testing_module_generator { * Create essay question pages. * @param object $lesson * @param array $record - * @return int + * @return stdClass page record. */ public function create_question_essay($lesson, $record = array()) { global $DB, $CFG; @@ -368,7 +368,7 @@ class mod_lesson_generator extends testing_module_generator { * Create matching question pages. * @param object $lesson * @param array $record - * @return int + * @return stdClass page record. */ public function create_question_matching($lesson, $record = array()) { global $DB, $CFG; @@ -446,7 +446,7 @@ class mod_lesson_generator extends testing_module_generator { * Create shortanswer question pages. * @param object $lesson * @param array $record - * @return int + * @return stdClass page record. */ public function create_question_shortanswer($lesson, $record = array()) { global $DB, $CFG; @@ -487,7 +487,7 @@ class mod_lesson_generator extends testing_module_generator { * Create shortanswer question pages. * @param object $lesson * @param array $record - * @return int + * @return stdClass page record. */ public function create_question_numeric($lesson, $record = array()) { global $DB, $CFG; From 0577c54bc0bd1aa7573dead039b79a4cecdd47f6 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 6 Jun 2023 12:26:30 +0200 Subject: [PATCH 6/8] MDL-77581 behat: Create generators for lesson clusters --- mod/lesson/pagetypes/cluster.php | 25 ++++++- mod/lesson/pagetypes/endofbranch.php | 23 ++++++ mod/lesson/pagetypes/endofcluster.php | 23 ++++++ mod/lesson/tests/generator/lib.php | 102 +++++++++++++++++++++++++- mod/lesson/tests/generator_test.php | 83 +++++++++++++++++++++ 5 files changed, 254 insertions(+), 2 deletions(-) diff --git a/mod/lesson/pagetypes/cluster.php b/mod/lesson/pagetypes/cluster.php index 164a1ad1af2..74948d04730 100644 --- a/mod/lesson/pagetypes/cluster.php +++ b/mod/lesson/pagetypes/cluster.php @@ -87,6 +87,29 @@ class lesson_page_type_cluster extends lesson_page { } return $this->properties->nextpageid; } + + /** + * Creates answers within the database for this cluster page. Usually only ever + * called when creating a new page instance. + * @param object $properties + * @return array + */ + public function create_answers($properties) { + global $DB; + + $newanswer = new stdClass; + $newanswer->lessonid = $this->lesson->id; + $newanswer->pageid = $this->properties->id; + $newanswer->timecreated = $this->properties->timecreated; + + if (isset($properties->jumpto[0])) { + $newanswer->jumpto = $properties->jumpto[0]; + } + $newanswer->id = $DB->insert_record('lesson_answers', $newanswer); + $answers = [$newanswer->id => new lesson_page_answer($newanswer)]; + $this->answers = $answers; + return $answers; + } } class lesson_add_page_form_cluster extends lesson_add_page_form_base { @@ -179,4 +202,4 @@ class lesson_add_page_form_cluster extends lesson_add_page_form_base { $lesson->add_message(get_string('addedcluster', 'lesson'), 'notifysuccess'); redirect($CFG->wwwroot.'/mod/lesson/edit.php?id='.$PAGE->cm->id); } -} \ No newline at end of file +} diff --git a/mod/lesson/pagetypes/endofbranch.php b/mod/lesson/pagetypes/endofbranch.php index fa172450175..dc5409cee79 100644 --- a/mod/lesson/pagetypes/endofbranch.php +++ b/mod/lesson/pagetypes/endofbranch.php @@ -115,6 +115,29 @@ class lesson_page_type_endofbranch extends lesson_page { public function valid_page_and_view(&$validpages, &$pageviews) { return $this->properties->nextpageid; } + + /** + * Creates answers within the database for this end of cluster page. Usually only ever + * called when creating a new page instance. + * @param object $properties + * @return array + */ + public function create_answers($properties) { + global $DB; + + $newanswer = new stdClass; + $newanswer->lessonid = $this->lesson->id; + $newanswer->pageid = $this->properties->id; + $newanswer->timecreated = $this->properties->timecreated; + + if (isset($properties->jumpto[0])) { + $newanswer->jumpto = $properties->jumpto[0]; + } + $newanswer->id = $DB->insert_record('lesson_answers', $newanswer); + $answers = [$newanswer->id => new lesson_page_answer($newanswer)]; + $this->answers = $answers; + return $answers; + } } class lesson_add_page_form_endofbranch extends lesson_add_page_form_base { diff --git a/mod/lesson/pagetypes/endofcluster.php b/mod/lesson/pagetypes/endofcluster.php index 4b756df61ed..05050139565 100644 --- a/mod/lesson/pagetypes/endofcluster.php +++ b/mod/lesson/pagetypes/endofcluster.php @@ -95,6 +95,29 @@ class lesson_page_type_endofcluster extends lesson_page { public function valid_page_and_view(&$validpages, &$pageviews) { return $this->properties->nextpageid; } + + /** + * Creates answers within the database for this end of cluster page. Usually only ever + * called when creating a new page instance. + * @param object $properties + * @return array + */ + public function create_answers($properties) { + global $DB; + + $newanswer = new stdClass; + $newanswer->lessonid = $this->lesson->id; + $newanswer->pageid = $this->properties->id; + $newanswer->timecreated = $this->properties->timecreated; + + if (isset($properties->jumpto[0])) { + $newanswer->jumpto = $properties->jumpto[0]; + } + $newanswer->id = $DB->insert_record('lesson_answers', $newanswer); + $answers = [$newanswer->id => new lesson_page_answer($newanswer)]; + $this->answers = $answers; + return $answers; + } } class lesson_add_page_form_endofcluster extends lesson_add_page_form_base { diff --git a/mod/lesson/tests/generator/lib.php b/mod/lesson/tests/generator/lib.php index 2e04056b5aa..6f76c14c0e8 100644 --- a/mod/lesson/tests/generator/lib.php +++ b/mod/lesson/tests/generator/lib.php @@ -58,6 +58,7 @@ class mod_lesson_generator extends testing_module_generator { 'Unseen question within a content page' => LESSON_UNSEENBRANCHPAGE, 'Random question within a content page' => LESSON_RANDOMPAGE, 'Random content page' => LESSON_RANDOMBRANCH, + 'Unseen question within a cluster' => LESSON_CLUSTERJUMP, ]; /** @@ -180,7 +181,16 @@ class mod_lesson_generator extends testing_module_generator { return null; } - $funcname = $qtype === 'content' ? 'create_content' : "create_question_{$qtype}"; + switch ($qtype) { + case 'content': + case 'cluster': + case 'endofcluster': + case 'endofbranch': + $funcname = "create_{$qtype}"; + break; + default: + $funcname = "create_question_{$qtype}"; + } if (!method_exists($this, $funcname)) { throw new coding_exception('The page '.$record['title']." has an invalid qtype: $qtype"); @@ -524,6 +534,96 @@ class mod_lesson_generator extends testing_module_generator { return $DB->get_record('lesson_pages', array('id' => $page->id), '*', MUST_EXIST); } + /** + * Creates a cluster page for testing purposes. + * + * @param stdClass $lesson instance where to create the page. + * @param array $record data for page being generated. + * @return stdClass page record. + */ + public function create_cluster(stdClass $lesson, array $record = []): stdClass { + global $DB, $CFG; + $now = time(); + $this->pagecount++; + $record = $record + [ + 'lessonid' => $lesson->id, + 'title' => 'Cluster '.$this->pagecount, + 'timecreated' => $now, + 'qtype' => 30, // LESSON_PAGE_CLUSTER. + 'pageid' => 0, // By default insert in the beginning. + ]; + if (!isset($record['contents_editor'])) { + $record['contents_editor'] = [ + 'text' => 'Cluster '.$this->pagecount, + 'format' => FORMAT_MOODLE, + 'itemid' => 0, + ]; + } + $context = context_module::instance($lesson->cmid); + $page = lesson_page::create((object)$record, new lesson($lesson), $context, $CFG->maxbytes); + return $DB->get_record('lesson_pages', ['id' => $page->id], '*', MUST_EXIST); + } + + /** + * Creates a end of cluster page for testing purposes. + * + * @param stdClass $lesson instance where to create the page. + * @param array $record data for page being generated. + * @return stdClass page record. + */ + public function create_endofcluster(stdClass $lesson, array $record = []): stdClass { + global $DB, $CFG; + $now = time(); + $this->pagecount++; + $record = $record + [ + 'lessonid' => $lesson->id, + 'title' => 'End of cluster '.$this->pagecount, + 'timecreated' => $now, + 'qtype' => 31, // LESSON_PAGE_ENDOFCLUSTER. + 'pageid' => 0, // By default insert in the beginning. + ]; + if (!isset($record['contents_editor'])) { + $record['contents_editor'] = [ + 'text' => 'End of cluster '.$this->pagecount, + 'format' => FORMAT_MOODLE, + 'itemid' => 0, + ]; + } + $context = context_module::instance($lesson->cmid); + $page = lesson_page::create((object)$record, new lesson($lesson), $context, $CFG->maxbytes); + return $DB->get_record('lesson_pages', ['id' => $page->id], '*', MUST_EXIST); + } + + /** + * Creates a end of branch page for testing purposes. + * + * @param stdClass $lesson instance where to create the page. + * @param array $record data for page being generated. + * @return stdClass page record. + */ + public function create_endofbranch(stdClass $lesson, array $record = []): stdClass { + global $DB, $CFG; + $now = time(); + $this->pagecount++; + $record = $record + [ + 'lessonid' => $lesson->id, + 'title' => 'End of branch '.$this->pagecount, + 'timecreated' => $now, + 'qtype' => 21, // LESSON_PAGE_ENDOFBRANCH. + 'pageid' => 0, // By default insert in the beginning. + ]; + if (!isset($record['contents_editor'])) { + $record['contents_editor'] = [ + 'text' => 'End of branch '.$this->pagecount, + 'format' => FORMAT_MOODLE, + 'itemid' => 0, + ]; + } + $context = context_module::instance($lesson->cmid); + $page = lesson_page::create((object)$record, new lesson($lesson), $context, $CFG->maxbytes); + return $DB->get_record('lesson_pages', ['id' => $page->id], '*', MUST_EXIST); + } + /** * Create a lesson override (either user or group). * diff --git a/mod/lesson/tests/generator_test.php b/mod/lesson/tests/generator_test.php index b2a0eeb5ef7..1f417e68b20 100644 --- a/mod/lesson/tests/generator_test.php +++ b/mod/lesson/tests/generator_test.php @@ -215,6 +215,89 @@ class generator_test extends \advanced_testcase { $this->assertEquals($page2->title, $records[$page2->id]->title); } + /** + * This tests the generators for cluster, endofcluster and endofbranch pages. + * + * @covers ::create_cluster + * @covers ::create_endofcluster + * @covers ::create_endofbranch + * @dataProvider create_cluster_pages_provider + * + * @param string $type Type of page to test: LESSON_PAGE_CLUSTER, LESSON_PAGE_ENDOFCLUSTER or LESSON_PAGE_ENDOFBRANCH. + */ + public function test_create_cluster_pages(string $type): void { + global $DB; + $this->resetAfterTest(); + $this->setAdminUser(); + + $course = $this->getDataGenerator()->create_course(); + $lesson = $this->getDataGenerator()->create_module('lesson', ['course' => $course]); + $lessongenerator = $this->getDataGenerator()->get_plugin_generator('mod_lesson'); + + $page2data = [ + 'title' => 'Custom title', + 'contents_editor' => [ + 'text' => 'Custom content', + 'format' => FORMAT_MOODLE, + 'itemid' => 0, + ], + 'jumpto' => [LESSON_EOL], + ]; + + switch ($type) { + case LESSON_PAGE_CLUSTER: + $page1 = $lessongenerator->create_cluster($lesson); + $page2 = $lessongenerator->create_cluster($lesson, $page2data); + break; + case LESSON_PAGE_ENDOFCLUSTER: + $page1 = $lessongenerator->create_endofcluster($lesson); + $page2 = $lessongenerator->create_endofcluster($lesson, $page2data); + break; + case LESSON_PAGE_ENDOFBRANCH: + $page1 = $lessongenerator->create_endofbranch($lesson); + $page2 = $lessongenerator->create_endofbranch($lesson, $page2data); + break; + default: + throw new coding_exception('Cluster page type not valid: ' . $type); + } + + $records = $DB->get_records('lesson_pages', ['lessonid' => $lesson->id], 'id'); + $p1answers = $DB->get_records('lesson_answers', ['lessonid' => $lesson->id, 'pageid' => $page1->id], 'id'); + $p2answers = $DB->get_records('lesson_answers', ['lessonid' => $lesson->id, 'pageid' => $page2->id], 'id'); + + $this->assertCount(2, $records); + $this->assertEquals($page1->id, $records[$page1->id]->id); + $this->assertEquals($type, $records[$page1->id]->qtype); + $this->assertEquals($page2->id, $records[$page2->id]->id); + $this->assertEquals($type, $records[$page2->id]->qtype); + $this->assertEquals($page2->title, $records[$page2->id]->title); + $this->assertEquals($page2data['contents_editor']['text'], $records[$page2->id]->contents); + $this->assertCount(1, $p1answers); + $this->assertCount(1, $p2answers); + $this->assertEquals(LESSON_THISPAGE, array_pop($p1answers)->jumpto); + $this->assertEquals(LESSON_EOL, array_pop($p2answers)->jumpto); + } + + /** + * Data provider for test_create_cluster_pages(). + * + * @return array + */ + public static function create_cluster_pages_provider(): array { + // Using the page constants here throws an error: Undefined constant "mod_lesson\LESSON_PAGE_CLUSTER". + return [ + 'Cluster' => [ + 'type' => '30', + ], + 'End of cluster' => [ + 'type' => '31', + ], + 'End of branch' => [ + 'type' => '21', + ], + ]; + } + /** * Test create some pages and their answers. * From 13ef3072536f937a5810069e43797716140150ae Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Tue, 6 Jun 2023 12:27:05 +0200 Subject: [PATCH 7/8] MDL-77581 behat: Apply new lesson cluster generators to existing tests --- .../completion_condition_end_reached.feature | 4 +- .../completion_condition_time_spent.feature | 2 +- .../tests/behat/date_availability.feature | 4 +- .../behat/lesson_activity_completion.feature | 4 +- .../behat/lesson_complete_report.feature | 16 +- .../lesson_completion_pass_grade.feature | 2 +- .../tests/behat/lesson_course_reset.feature | 2 +- .../tests/behat/lesson_delete_answers.feature | 4 +- .../tests/behat/lesson_edit_cluster.feature | 71 ++---- .../tests/behat/lesson_edit_pages.feature | 4 +- .../behat/lesson_exit_enter_clusters.feature | 210 ++++-------------- .../tests/behat/lesson_group_override.feature | 2 +- .../behat/lesson_informations_at_end.feature | 4 +- .../tests/behat/lesson_navigation.feature | 12 +- .../lesson_number_of_student_attempts.feature | 4 +- ...son_numerical_question_with_locale.feature | 2 +- .../tests/behat/lesson_outline_report.feature | 16 +- .../tests/behat/lesson_practice.feature | 2 +- .../tests/behat/lesson_progress_bar.feature | 4 +- .../behat/lesson_question_attempts.feature | 4 +- mod/lesson/tests/behat/lesson_report.feature | 8 +- mod/lesson/tests/behat/lesson_review.feature | 4 +- .../tests/behat/lesson_student_resume.feature | 16 +- .../tests/behat/lesson_user_override.feature | 2 +- .../tests/behat/lesson_with_clusters.feature | 129 +++-------- .../behat/lesson_with_subcluster.feature | 150 +++---------- .../tests/behat/link_to_gradebook.feature | 4 +- .../tests/behat/wrong_answer_continue.feature | 8 +- 28 files changed, 201 insertions(+), 493 deletions(-) diff --git a/mod/lesson/tests/behat/completion_condition_end_reached.feature b/mod/lesson/tests/behat/completion_condition_end_reached.feature index e8e6ca9e0a4..044e2395a6c 100644 --- a/mod/lesson/tests/behat/completion_condition_end_reached.feature +++ b/mod/lesson/tests/behat/completion_condition_end_reached.feature @@ -19,11 +19,11 @@ Feature: Set end of lesson reached as a completion condition for a lesson And the following "activity" exist: | activity | name | course | idnumber | completion | completionview | completionendreached | | lesson | Test lesson | C1 | 0001 | 2 | 0 | 1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson | content | First page name | First page contents | | Test lesson | content | Second page name | Second page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | | Second page name | Previous page | Previous page | diff --git a/mod/lesson/tests/behat/completion_condition_time_spent.feature b/mod/lesson/tests/behat/completion_condition_time_spent.feature index 4b2fc8ed547..2fbdde01ab1 100644 --- a/mod/lesson/tests/behat/completion_condition_time_spent.feature +++ b/mod/lesson/tests/behat/completion_condition_time_spent.feature @@ -23,7 +23,7 @@ Feature: Set time spent as a completion condition for a lesson | lesson | qtype | title | content | | Test lesson | content | First page name | First page contents | | Test lesson | content | Second page name | Second page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | | Second page name | Previous page | Previous page | diff --git a/mod/lesson/tests/behat/date_availability.feature b/mod/lesson/tests/behat/date_availability.feature index 775c7c0abf1..4cfae904ee9 100644 --- a/mod/lesson/tests/behat/date_availability.feature +++ b/mod/lesson/tests/behat/date_availability.feature @@ -19,10 +19,10 @@ Feature: A teacher can set available from and deadline dates to access a lesson And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson | content | First page name | First page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | diff --git a/mod/lesson/tests/behat/lesson_activity_completion.feature b/mod/lesson/tests/behat/lesson_activity_completion.feature index 495c65d2065..360a2c8b8bd 100644 --- a/mod/lesson/tests/behat/lesson_activity_completion.feature +++ b/mod/lesson/tests/behat/lesson_activity_completion.feature @@ -28,11 +28,11 @@ Feature: View activity completion in the lesson activity | completionendreached | 1 | | completiontimespentenabled | 1 | | completiontimespent | 3 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Music history | content | Music history part 1 | | | Music history | essay | Music essay | Write a really interesting music essay | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Music history part 1 | The history of music part 1 | Next page | 0 | | Music essay | | Next page | 1 | diff --git a/mod/lesson/tests/behat/lesson_complete_report.feature b/mod/lesson/tests/behat/lesson_complete_report.feature index 32907236bbe..e9b7d81cff5 100644 --- a/mod/lesson/tests/behat/lesson_complete_report.feature +++ b/mod/lesson/tests/behat/lesson_complete_report.feature @@ -20,11 +20,11 @@ Feature: Teachers can review student progress on all lessons in a course by view | lesson | Test lesson name | C1 | lesson1 | 1 | Scenario: View student progress for lesson that was never attempted - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | True/false question 1 | True | Correct | Next page | 1 | @@ -37,12 +37,12 @@ Feature: Teachers can review student progress on all lessons in a course by view Then I should see "No attempts have been made on this lesson" Scenario: View student progress for an incomplete lesson containing both content and question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Next page | | Next page | 0 | @@ -60,13 +60,13 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "0" in the ".cell.c2" "css_element" Scenario: View student progress for a lesson containing both content and question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | | Test lesson name | truefalse | True/false question 2 | The sky is Pink. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | @@ -101,11 +101,11 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "1" in the ".cell.c3" "css_element" Scenario: View student attempts in a lesson containing only content pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | | Second page name | Previous page | Previous page | diff --git a/mod/lesson/tests/behat/lesson_completion_pass_grade.feature b/mod/lesson/tests/behat/lesson_completion_pass_grade.feature index 649467ebe02..00da02e453a 100644 --- a/mod/lesson/tests/behat/lesson_completion_pass_grade.feature +++ b/mod/lesson/tests/behat/lesson_completion_pass_grade.feature @@ -29,7 +29,7 @@ Feature: Pass grade activity completion in the lesson activity And the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Music history | numeric | Numerical question | What is 1 + 2? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Numerical question | 3 | End of lesson | 1 | | Numerical question | @#wronganswer#@ | Next page | 0 | diff --git a/mod/lesson/tests/behat/lesson_course_reset.feature b/mod/lesson/tests/behat/lesson_course_reset.feature index c6b2ca9e8af..2fe0cb47f51 100644 --- a/mod/lesson/tests/behat/lesson_course_reset.feature +++ b/mod/lesson/tests/behat/lesson_course_reset.feature @@ -28,7 +28,7 @@ Feature: Lesson reset And the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | True/false question 1 | False | Correct | Next page | 1 | | True/false question 1 | True | Wrong | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_delete_answers.feature b/mod/lesson/tests/behat/lesson_delete_answers.feature index b836daf07c8..5d28dc3da40 100644 --- a/mod/lesson/tests/behat/lesson_delete_answers.feature +++ b/mod/lesson/tests/behat/lesson_delete_answers.feature @@ -20,11 +20,11 @@ branch table contents And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | numeric | Hardest question ever | 1 + 1? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | First page name | Previous page | | Previous page | 0 | diff --git a/mod/lesson/tests/behat/lesson_edit_cluster.feature b/mod/lesson/tests/behat/lesson_edit_cluster.feature index 49c55542d0f..1abacebd354 100644 --- a/mod/lesson/tests/behat/lesson_edit_cluster.feature +++ b/mod/lesson/tests/behat/lesson_edit_cluster.feature @@ -19,57 +19,30 @@ Feature: In a lesson activity, teacher can edit a cluster page And the following "activities" exist: | activity | name | course | idnumber | | lesson | Lesson with cluster | C1 | lesson1 | - And I am on the "Lesson with cluster" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 1 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][4]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 2 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][5]" "xpath_element" - And I click on "Add a content page" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][6]" "xpath_element" - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Content page after cluster | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" + And the following "mod_lesson > pages" exist: + | lesson | qtype | title | content | + | Lesson with cluster | content | First page name | First page contents | + | Lesson with cluster | cluster | Cluster | Cluster | + | Lesson with cluster | multichoice | Question 1 | Question from cluster | + | Lesson with cluster | multichoice | Question 2 | Question from cluster | + | Lesson with cluster | endofcluster | End of cluster | End of cluster | + | Lesson with cluster | content | Second page name | Content page after cluster | + And the following "mod_lesson > answers" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Cluster | | | Unseen question within a cluster | 0 | + | Question 1 | Correct answer | Good | Cluster | 1 | + | Question 1 | Incorrect answer | Bad | This page | 0 | + | Question 2 | Correct answer | Good | Cluster | 1 | + | Question 2 | Incorrect answer | Bad | This page | 0 | + | End of cluster | | | Next page | 0 | + | Second page name | Next page | | Next page | 0 | Scenario: Edit lesson cluster page - Given I click on "//th[normalize-space(.)='Cluster']/descendant::a[3]" "xpath_element" + Given I am on the "Lesson with cluster" "lesson activity" page logged in as teacher1 + And I press "Edit lesson" + And I select edit type "Expanded" + And I click on "//th[normalize-space(.)='Cluster']/descendant::a[3]" "xpath_element" When I set the following fields to these values: | Page title | Modified name | | Page contents | Modified contents | diff --git a/mod/lesson/tests/behat/lesson_edit_pages.feature b/mod/lesson/tests/behat/lesson_edit_pages.feature index d6fa377e384..ada2cbc3e6d 100644 --- a/mod/lesson/tests/behat/lesson_edit_pages.feature +++ b/mod/lesson/tests/behat/lesson_edit_pages.feature @@ -19,12 +19,12 @@ Feature: In a lesson activity, teacher can edit lesson's pages And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | numeric | Hardest question ever | 1 + 1? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | diff --git a/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature b/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature index 761e3963d75..f5cb851a667 100644 --- a/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature +++ b/mod/lesson/tests/behat/lesson_exit_enter_clusters.feature @@ -18,171 +18,51 @@ Feature: In a lesson activity, students can exit and re-enter the activity when And the following "activities" exist: | activity | name | course | idnumber | | lesson | Lesson with cluster | C1 | lesson1 | - And I am on the "Lesson with cluster" "lesson activity" page logged in as teacher1 - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" - And I follow "Update page: Cluster" - And I set the following fields to these values: - | Page title | C Cluster | - | Page contents | C Cluster | - | Jump | Unseen question within a cluster | - And I press "Save page" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" - And I follow "Update page: Cluster" - And I set the following fields to these values: - | Page title | B Cluster | - | Page contents | B Cluster | - | Jump | Unseen question within a cluster | - And I press "Save page" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" - And I follow "Update page: Cluster" - And I set the following fields to these values: - | Page title | A Cluster | - | Page contents | A Cluster | - | Jump | Unseen question within a cluster | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 1 A Cluster | - | Page contents | Question 1 from A cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | B Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][4]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 2 A Cluster | - | Page contents | Question 2 from A cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | B Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][5]" "xpath_element" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 3 A Cluster | - | Page contents | Question 3 from A cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | B Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][6]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][8]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 1 B Cluster | - | Page contents | Question 1 from B cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | C Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][9]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 2 B Cluster | - | Page contents | Question 2 from B cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | C Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][10]" "xpath_element" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 3 B Cluster | - | Page contents | Question 3 from B cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | C Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][11]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][13]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 1 C Cluster | - | Page contents | Question 1 from C cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][14]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 2 C Cluster | - | Page contents | Question 2 from C cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][15]" "xpath_element" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | Question 3 C Cluster | - | Page contents | Question 3 from C cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | End of lesson | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | Unseen question within a cluster | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][16]" "xpath_element" + And the following "mod_lesson > pages" exist: + | lesson | qtype | title | content | + | Lesson with cluster | content | First page name | First page contents | + | Lesson with cluster | cluster | A Cluster | A Cluster | + | Lesson with cluster | multichoice | Question 1 A Cluster | Question 1 from A cluster | + | Lesson with cluster | multichoice | Question 2 A Cluster | Question 2 from A cluster | + | Lesson with cluster | multichoice | Question 3 A Cluster | Question 3 from A cluster | + | Lesson with cluster | endofcluster | End of A cluster | End of A cluster | + | Lesson with cluster | cluster | B Cluster | B Cluster | + | Lesson with cluster | multichoice | Question 1 B Cluster | Question 1 from B cluster | + | Lesson with cluster | multichoice | Question 2 B Cluster | Question 2 from B cluster | + | Lesson with cluster | multichoice | Question 3 B Cluster | Question 3 from B cluster | + | Lesson with cluster | endofcluster | End of B cluster | End of B cluster | + | Lesson with cluster | cluster | C Cluster | C Cluster | + | Lesson with cluster | multichoice | Question 1 C Cluster | Question 1 from C cluster | + | Lesson with cluster | multichoice | Question 2 C Cluster | Question 2 from C cluster | + | Lesson with cluster | multichoice | Question 3 C Cluster | Question 3 from C cluster | + | Lesson with cluster | endofcluster | End of C cluster | End of C cluster | + And the following "mod_lesson > answers" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | A Cluster | | | Unseen question within a cluster | 0 | + | Question 1 A Cluster | Correct answer | Good | B Cluster | 1 | + | Question 1 A Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | Question 2 A Cluster | Correct answer | Good | B Cluster | 1 | + | Question 2 A Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | Question 3 A Cluster | Correct answer | Good | B Cluster | 1 | + | Question 3 A Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | End of A cluster | | | Next page | 0 | + | B Cluster | | | Unseen question within a cluster | 0 | + | Question 1 B Cluster | Correct answer | Good | C Cluster | 1 | + | Question 1 B Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | Question 2 B Cluster | Correct answer | Good | C Cluster | 1 | + | Question 2 B Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | Question 3 B Cluster | Correct answer | Good | C Cluster | 1 | + | Question 3 B Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | End of B cluster | | | Next page | 0 | + | C Cluster | | | Unseen question within a cluster | 0 | + | Question 1 C Cluster | Correct answer | Good | End of lesson | 1 | + | Question 1 C Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | Question 2 C Cluster | Correct answer | Good | End of lesson | 1 | + | Question 2 C Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | Question 3 C Cluster | Correct answer | Good | End of lesson | 1 | + | Question 3 C Cluster | Incorrect answer | Bad | Unseen question within a cluster | 0 | + | End of C cluster | | | Next page | 0 | Scenario: Accessing as student to a cluster only lesson Given I am on the "Lesson with cluster" "lesson activity" page logged in as student1 diff --git a/mod/lesson/tests/behat/lesson_group_override.feature b/mod/lesson/tests/behat/lesson_group_override.feature index 74bce42e7f8..7ab6ef14080 100644 --- a/mod/lesson/tests/behat/lesson_group_override.feature +++ b/mod/lesson/tests/behat/lesson_group_override.feature @@ -35,7 +35,7 @@ Feature: Lesson group override And the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | True/false question 1 | False | Correct | Next page | 1 | | True/false question 1 | True | Wrong | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_informations_at_end.feature b/mod/lesson/tests/behat/lesson_informations_at_end.feature index a62842457e6..63bcbee46fa 100644 --- a/mod/lesson/tests/behat/lesson_informations_at_end.feature +++ b/mod/lesson/tests/behat/lesson_informations_at_end.feature @@ -20,11 +20,11 @@ Feature: In a lesson activity, if custom scoring is not enabled, student should And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | numeric | Hardest question ever | 1 + 1? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Hardest question ever | 2 | Correct answer | Next page | 1 | diff --git a/mod/lesson/tests/behat/lesson_navigation.feature b/mod/lesson/tests/behat/lesson_navigation.feature index 37514f01d45..d329ba753d4 100644 --- a/mod/lesson/tests/behat/lesson_navigation.feature +++ b/mod/lesson/tests/behat/lesson_navigation.feature @@ -21,12 +21,12 @@ Feature: In a lesson activity, students can navigate through a series of pages i | lesson | Test lesson name | C1 | lesson1 | Scenario: Student navigation with pages and questions - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | numeric | Hardest question ever | 1 + 1? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | @@ -65,7 +65,7 @@ Feature: In a lesson activity, students can navigate through a series of pages i Given the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | Test question | Test content | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Test question | right | Next page | 1 | | Test question | wrong | This page | 0 | @@ -96,11 +96,11 @@ Feature: In a lesson activity, students can navigate through a series of pages i And I should see "Congratulations - end of lesson reached" Scenario: Student reattempts a question until out of attempts with specific jumps - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | Test question | Test content 1 | | Test lesson name | truefalse | Test question 2 | Test content 2 | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Test question | right | Next page | 1 | | Test question | wrong | This page | 0 | @@ -140,7 +140,7 @@ Feature: In a lesson activity, students can navigate through a series of pages i Given the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | Test question | Test content | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Test question | right | Next page | 1 | | Test question | wrong | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature b/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature index b8bc847f77a..74fc49a94a9 100644 --- a/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature +++ b/mod/lesson/tests/behat/lesson_number_of_student_attempts.feature @@ -27,12 +27,12 @@ Feature: In Dashboard, teacher can see the number of student attempts to lessons | idnumber | 0001 | | name | Test lesson name | | retake | 1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | | Test lesson name | truefalse | True/false question 2 | Paper is made from trees. | | Test lesson name | truefalse | True/false question 3 | 1+1=2 | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | True/false question 1 | False | Correct | Next page | 1 | | True/false question 1 | True | Wrong | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature index 7a7b39dc356..a94fcfded78 100644 --- a/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature +++ b/mod/lesson/tests/behat/lesson_numerical_question_with_locale.feature @@ -22,7 +22,7 @@ Feature: In a lesson activity, I need to edit pages in the lesson taking into ac And the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | numeric | Hardest question ever | 1 + 1? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | Hardest question ever | 2.87 | Correct answer | End of lesson | 1 | | Hardest question ever | 2.1:2.8 | Incorrect answer | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_outline_report.feature b/mod/lesson/tests/behat/lesson_outline_report.feature index 183de7a733b..fd922442b7c 100644 --- a/mod/lesson/tests/behat/lesson_outline_report.feature +++ b/mod/lesson/tests/behat/lesson_outline_report.feature @@ -24,11 +24,11 @@ Feature: Teachers can review student progress on all lessons in a course by view And I am on the "Test lesson name" "lesson activity" page logged in as teacher1 Scenario: View student progress for lesson that was never attempted - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | True/false question 1 | True | Correct | Next page | 1 | @@ -41,12 +41,12 @@ Feature: Teachers can review student progress on all lessons in a course by view Then I should see "No attempts have been made on this lesson" Scenario: View student progress for an incomplete lesson containing both content and question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | @@ -63,12 +63,12 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "Lesson has been started, but not yet completed" Scenario: View student progress for a lesson containing both content and question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | @@ -93,11 +93,11 @@ Feature: Teachers can review student progress on all lessons in a course by view And I should see "Grade: 100.00 / 100.00" Scenario: View student attempts in a lesson containing only content pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | First page name | Next page | Next page | 0 | | Second page name | Previous page | Previous page | 0 | diff --git a/mod/lesson/tests/behat/lesson_practice.feature b/mod/lesson/tests/behat/lesson_practice.feature index 35214daf307..9d7a8e2b528 100644 --- a/mod/lesson/tests/behat/lesson_practice.feature +++ b/mod/lesson/tests/behat/lesson_practice.feature @@ -24,7 +24,7 @@ Feature: Practice mode in a lesson activity And the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True or False | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | True or False | True | Next page | 1 | | True or False | False | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_progress_bar.feature b/mod/lesson/tests/behat/lesson_progress_bar.feature index b65adc13f04..d8e7ba1e1ac 100644 --- a/mod/lesson/tests/behat/lesson_progress_bar.feature +++ b/mod/lesson/tests/behat/lesson_progress_bar.feature @@ -19,12 +19,12 @@ Feature: In a lesson activity, students can see their progress viewing a progres And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | numeric | Hardest question ever | 1 + 1? | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | diff --git a/mod/lesson/tests/behat/lesson_question_attempts.feature b/mod/lesson/tests/behat/lesson_question_attempts.feature index 7f0c32b5a1c..110f626a9b7 100644 --- a/mod/lesson/tests/behat/lesson_question_attempts.feature +++ b/mod/lesson/tests/behat/lesson_question_attempts.feature @@ -22,7 +22,7 @@ Feature: In a lesson activity, students can not re-attempt a question more than | name | Test lesson name | | retake | 1 | | minquestions | 3 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | truefalse | True/false question 1 | The earth is round. | @@ -30,7 +30,7 @@ Feature: In a lesson activity, students can not re-attempt a question more than | Test lesson name | content | Second page name | Second page contents | | Test lesson name | truefalse | True/false question 3 | Paper is made from trees. | | Test lesson name | content | Third page name | Third page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | diff --git a/mod/lesson/tests/behat/lesson_report.feature b/mod/lesson/tests/behat/lesson_report.feature index 3d7f4ff9bbf..cdb850b66b5 100644 --- a/mod/lesson/tests/behat/lesson_report.feature +++ b/mod/lesson/tests/behat/lesson_report.feature @@ -21,14 +21,14 @@ Feature: In a lesson activity, teachers can review student attempts | lesson | Test lesson name | C1 | lesson1 | 1 | Scenario: View student attempts in a lesson containing both content and question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | content | Third page name | Third page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | | Test lesson name | truefalse | True/false question 2 | Kermit is a frog | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | @@ -66,13 +66,13 @@ Feature: In a lesson activity, teachers can review student attempts And I should see "Low score" Scenario: View student attempts in a lesson containing only content pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | content | Third page name | Third page contents | | Test lesson name | content | Fourth page name | Fourth page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | | Second page name | Previous page | Previous page | diff --git a/mod/lesson/tests/behat/lesson_review.feature b/mod/lesson/tests/behat/lesson_review.feature index 58012ab6603..7169af8adb2 100644 --- a/mod/lesson/tests/behat/lesson_review.feature +++ b/mod/lesson/tests/behat/lesson_review.feature @@ -19,11 +19,11 @@ Feature: In a lesson activity, students can review the answers they gave to ques And the following "activity" exist: | activity | name | course | idnumber | | lesson | Test lesson name | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | numeric | Hardest question ever | 1 + 1? | | Test lesson name | truefalse | Next question | Paper is made from trees. | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | Hardest question ever | 2 | Correct answer | Next page | 1 | | Hardest question ever | 1 | Incorrect answer | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_student_resume.feature b/mod/lesson/tests/behat/lesson_student_resume.feature index 6a7f7f0b97d..124b603a430 100644 --- a/mod/lesson/tests/behat/lesson_student_resume.feature +++ b/mod/lesson/tests/behat/lesson_student_resume.feature @@ -22,14 +22,14 @@ Feature: In a lesson activity a student should | retake | 1 | Scenario: resume a lesson with both content then question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | content | Third page name | Third page contents | | Test lesson name | truefalse | True/false question 1 | Paper is made from trees. | | Test lesson name | truefalse | True/false question 2 | Kermit is a frog | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | First page name | Next page | | Next page | 0 | | Second page name | Previous page | | Previous page | 0 | @@ -82,13 +82,13 @@ Feature: In a lesson activity a student should And I should see "Congratulations - end of lesson reached" Scenario: resume a lesson with only content pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | content | First page name | First page contents | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | content | Third page name | Third page contents | | Test lesson name | content | Fourth page name | Fourth page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | | Second page name | Previous page | Previous page | @@ -120,7 +120,7 @@ Feature: In a lesson activity a student should And I should see "First page contents" Scenario: resume a lesson with both question then content pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | | Test lesson name | content | First page name | First page contents | @@ -129,7 +129,7 @@ Feature: In a lesson activity a student should | Test lesson name | truefalse | True/false question 4 | 2+2=4 | | Test lesson name | content | Second page name | Second page contents | | Test lesson name | truefalse | True/false question 5 | Kermit is a frog | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | True/false question 1 | False | Correct | Next page | 1 | | True/false question 1 | True | Wrong | This page | 0 | @@ -192,14 +192,14 @@ Feature: In a lesson activity a student should And I should see "Congratulations - end of lesson reached" Scenario: resume a lesson with only question pages - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | | Test lesson name | truefalse | True/false question 2 | Paper is made from trees. | | Test lesson name | truefalse | True/false question 3 | 1+1=2 | | Test lesson name | truefalse | True/false question 4 | 2+2=4 | | Test lesson name | truefalse | True/false question 5 | Kermit is a frog | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | True/false question 1 | False | Correct | Next page | 1 | | True/false question 1 | True | Wrong | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_user_override.feature b/mod/lesson/tests/behat/lesson_user_override.feature index 6acdb3e9136..df9847047ed 100644 --- a/mod/lesson/tests/behat/lesson_user_override.feature +++ b/mod/lesson/tests/behat/lesson_user_override.feature @@ -24,7 +24,7 @@ Feature: Lesson user override And the following "mod_lesson > page" exist: | lesson | qtype | title | content | | Test lesson name | truefalse | True/false question 1 | Cat is an amphibian | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | response | jumpto | score | | True/false question 1 | False | Correct | Next page | 1 | | True/false question 1 | True | Wrong | This page | 0 | diff --git a/mod/lesson/tests/behat/lesson_with_clusters.feature b/mod/lesson/tests/behat/lesson_with_clusters.feature index ee5f1ce1b3d..b88bc1aff56 100644 --- a/mod/lesson/tests/behat/lesson_with_clusters.feature +++ b/mod/lesson/tests/behat/lesson_with_clusters.feature @@ -22,102 +22,39 @@ Feature: In a lesson activity, students can see questions in random order And I log in as "teacher1" Scenario: Lesson with two clusters - Given I am on the "Lesson with clusters" "lesson activity" page - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select "Add a content page" from the "qtype" singleselect - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | Second page contents | - | id_answer_editor_0 | Previous page | - | id_jumpto_0 | Previous page | - | id_answer_editor_1 | Next page | - | id_jumpto_1 | Next page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][4]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 1 | - | Page contents | Question from cluster 1 | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][5]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 2 | - | Page contents | Question from cluster 1 | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][6]" "xpath_element" - And I click on "Add a content page" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][7]" "xpath_element" - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Content page after cluster 1 | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][8]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][9]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 3 | - | Page contents | Question from cluster 2 | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Unseen question within a cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][10]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 4 | - | Page contents | Question from cluster 2 | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Unseen question within a cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][11]" "xpath_element" - And I click on "Add a content page" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][12]" "xpath_element" - And I set the following fields to these values: - | Page title | Fourth page name | - | Page contents | Content page after cluster 2 | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" + Given the following "mod_lesson > pages" exist: + | lesson | qtype | title | content | + | Lesson with clusters | content | First page name | First page contents | + | Lesson with clusters | content | Second page name | Second page contents | + | Lesson with clusters | cluster | Cluster 1 | Cluster 1 | + | Lesson with clusters | multichoice | Question 1 | Question from cluster 1 | + | Lesson with clusters | multichoice | Question 2 | Question from cluster 1 | + | Lesson with clusters | endofcluster | End of cluster 1 | End of cluster 1 | + | Lesson with clusters | content | Third page name | Content page after cluster 1 | + | Lesson with clusters | cluster | Cluster 2 | Cluster 2 | + | Lesson with clusters | multichoice | Question 3 | Question from cluster 2 | + | Lesson with clusters | multichoice | Question 4 | Question from cluster 2 | + | Lesson with clusters | endofcluster | End of cluster 2 | End of cluster 2 | + | Lesson with clusters | content | Fourth page name | Content page after cluster 2 | + And the following "mod_lesson > answers" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Second page name | Previous page | | Previous page | 0 | + | Second page name | Next page | | Next page | 0 | + | Cluster 1 | | | Unseen question within a cluster | 0 | + | Question 1 | Correct answer | Good | Cluster 1 | 1 | + | Question 1 | Incorrect answer | Bad | This page | 0 | + | Question 2 | Correct answer | Good | Cluster 1 | 1 | + | Question 2 | Incorrect answer | Bad | This page | 0 | + | End of cluster 1 | | | Next page | 0 | + | Third page name | Next page | | Next page | 0 | + | Cluster 2 | | | Unseen question within a cluster | 0 | + | Question 3 | Correct answer | Good | Unseen question within a cluster | 1 | + | Question 3 | Incorrect answer | Bad | This page | 0 | + | Question 4 | Correct answer | Good | Unseen question within a cluster | 1 | + | Question 4 | Incorrect answer | Bad | This page | 0 | + | End of cluster 2 | | | Next page | 0 | + | Fourth page name | Next page | | Next page | 0 | When I am on the "Lesson with clusters" "lesson activity" page logged in as student1 Then I should see "First page contents" And I press "Next page" diff --git a/mod/lesson/tests/behat/lesson_with_subcluster.feature b/mod/lesson/tests/behat/lesson_with_subcluster.feature index 006c491afcf..be6f92b492b 100644 --- a/mod/lesson/tests/behat/lesson_with_subcluster.feature +++ b/mod/lesson/tests/behat/lesson_with_subcluster.feature @@ -22,122 +22,40 @@ Feature: In a lesson activity, students can see questions in random order and a And I log in as "teacher1" Scenario: Lesson with subcluster - Given I am on the "Lesson with subcluster" "lesson activity" page - And I follow "Add a content page" - And I set the following fields to these values: - | Page title | First page name | - | Page contents | First page contents | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I select edit type "Expanded" - And I click on "Add a cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 1 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][4]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 2 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a content page" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][5]" "xpath_element" - And I set the following fields to these values: - | Page title | Second page name | - | Page contents | This page mark the the beginning of the subcluster it should not be seen by students | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][6]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 3 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][7]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 4 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][8]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 5 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of branch" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][9]" "xpath_element" - And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][10]" "xpath_element" - And I set the field "Select a question type" to "Multichoice" - And I press "Add a question page" - And I set the following fields to these values: - | Page title | question 6 | - | Page contents | Question from cluster | - | id_answer_editor_0 | Correct answer | - | id_response_editor_0 | Good | - | id_jumpto_0 | Cluster | - | id_score_0 | 1 | - | id_answer_editor_1 | Incorrect answer | - | id_response_editor_1 | Bad | - | id_jumpto_1 | This page | - | id_score_1 | 0 | - And I press "Save page" - And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][11]" "xpath_element" - And I click on "Add a content page" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][12]" "xpath_element" - And I set the following fields to these values: - | Page title | Third page name | - | Page contents | Content page after cluster | - | id_answer_editor_0 | Next page | - | id_jumpto_0 | Next page | - And I press "Save page" + Given the following "mod_lesson > pages" exist: + | lesson | qtype | title | content | + | Lesson with subcluster | content | First page name | First page contents | + | Lesson with subcluster | cluster | Cluster | Cluster | + | Lesson with subcluster | multichoice | Question 1 | Question from cluster | + | Lesson with subcluster | multichoice | Question 2 | Question from cluster | + | Lesson with subcluster | content | Second page name | Beginning of the subcluster, should not be seen by students | + | Lesson with subcluster | multichoice | Question 3 | Question from cluster | + | Lesson with subcluster | multichoice | Question 4 | Question from cluster | + | Lesson with subcluster | multichoice | Question 5 | Question from cluster | + | Lesson with subcluster | endofbranch | End of branch | End of branch | + | Lesson with subcluster | multichoice | Question 6 | Question from cluster | + | Lesson with subcluster | endofcluster | End of cluster | End of cluster | + | Lesson with subcluster | content | Third page name | Content page after cluster | + And the following "mod_lesson > answers" exist: + | page | answer | response | jumpto | score | + | First page name | Next page | | Next page | 0 | + | Cluster | | | Unseen question within a cluster | 0 | + | Question 1 | Correct answer | Good | Cluster | 1 | + | Question 1 | Incorrect answer | Bad | This page | 0 | + | Question 2 | Correct answer | Good | Cluster | 1 | + | Question 2 | Incorrect answer | Bad | This page | 0 | + | Second page name | Next page | | Next page | 0 | + | Question 3 | Correct answer | Good | Cluster | 1 | + | Question 3 | Incorrect answer | Bad | This page | 0 | + | Question 4 | Correct answer | Good | Cluster | 1 | + | Question 4 | Incorrect answer | Bad | This page | 0 | + | Question 5 | Correct answer | Good | Cluster | 1 | + | Question 5 | Incorrect answer | Bad | This page | 0 | + | End of branch | | | Second page name | 0 | + | Question 6 | Correct answer | Good | Cluster | 1 | + | Question 6 | Incorrect answer | Bad | This page | 0 | + | End of cluster | | | Next page | 0 | + | Third page name | Next page | | Next page | 0 | When I am on the "Lesson with subcluster" "lesson activity" page logged in as student1 Then I should see "First page contents" And I press "Next page" diff --git a/mod/lesson/tests/behat/link_to_gradebook.feature b/mod/lesson/tests/behat/link_to_gradebook.feature index 024a014544d..1e929c93f07 100644 --- a/mod/lesson/tests/behat/link_to_gradebook.feature +++ b/mod/lesson/tests/behat/link_to_gradebook.feature @@ -19,11 +19,11 @@ Feature: link to gradebook on the end of lesson page And the following "activities" exist: | activity | name | course | idnumber | | lesson | Test lesson | C1 | lesson1 | - And the following "mod_lesson > page" exist: + And the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson | content | First page name | First page contents | | Test lesson | content | Second page name | Second page contents | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | | First page name | Next page | Next page | | Second page name | Previous page | Previous page | diff --git a/mod/lesson/tests/behat/wrong_answer_continue.feature b/mod/lesson/tests/behat/wrong_answer_continue.feature index c31c9b18517..270bcdd89f4 100644 --- a/mod/lesson/tests/behat/wrong_answer_continue.feature +++ b/mod/lesson/tests/behat/wrong_answer_continue.feature @@ -26,11 +26,11 @@ Feature: An incorrect response to an answer with multiple attempts show appropri And I press "Save and display" Scenario: A student answering incorrectly to a question will see an option to move to the next question if set up. - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | numeric | Numerical question | What is 1 + 2? | | Test lesson name | content | Just move on page | You are here to move on | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Numerical question | 3 | Next page | 1 | | Numerical question | 2 | Next page | 0 | @@ -44,11 +44,11 @@ Feature: An incorrect response to an answer with multiple attempts show appropri Then I should see "You are here to move on" Scenario: A student answering incorrectly to a question will only see an option to try again if there is no matching wrong response. - Given the following "mod_lesson > page" exist: + Given the following "mod_lesson > pages" exist: | lesson | qtype | title | content | | Test lesson name | numeric | Numerical question | What is 1 + 2? | | Test lesson name | content | Just move on page | You are here to move on | - And the following "mod_lesson > answer" exist: + And the following "mod_lesson > answers" exist: | page | answer | jumpto | score | | Numerical question | 3 | Next page | 1 | | Just move on page | End this lesson | End of lesson | 0 | From 5bda7cac35ea53b150e4aba33b1d9374348904df Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Wed, 7 Jun 2023 12:43:27 +0200 Subject: [PATCH 8/8] MDL-77581 behat: Test create lesson pages using UI --- .../tests/behat/lesson_create_pages.feature | 284 ++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 mod/lesson/tests/behat/lesson_create_pages.feature diff --git a/mod/lesson/tests/behat/lesson_create_pages.feature b/mod/lesson/tests/behat/lesson_create_pages.feature new file mode 100644 index 00000000000..d39be894c27 --- /dev/null +++ b/mod/lesson/tests/behat/lesson_create_pages.feature @@ -0,0 +1,284 @@ +@mod @mod_lesson +Feature: In a lesson activity, teacher can create lesson's pages + In order to set up an existing lesson + As a teacher + I need to create pages in the lesson + + Background: + Given the following "users" exist: + | username | firstname | lastname | email | + | teacher1 | Teacher | 1 | teacher1@example.com | + | student1 | Student | 1 | student1@example.com | + And the following "courses" exist: + | fullname | shortname | category | + | Course 1 | C1 | 0 | + And the following "course enrolments" exist: + | user | course | role | + | teacher1 | C1 | editingteacher | + | student1 | C1 | student | + And the following "activities" exist: + | activity | name | course | idnumber | + | lesson | Test lesson name | C1 | lesson1 | + + Scenario: Create content page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a content page" + And I set the following fields to these values: + | Page title | First page name | + | Page contents | First page contents | + | id_answer_editor_0 | Forward | + | id_jumpto_0 | Next page | + | id_answer_editor_1 | Backward | + | id_jumpto_1 | Previous page | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "First page name" + And I should see "First page contents" + And I should see "Forward" in the "Content 1" "table_row" + And I should see "Next page" in the "Jump 1" "table_row" + And I should see "Backward" in the "Content 2" "table_row" + And I should see "Previous page" in the "Jump 2" "table_row" + + Scenario: Create essay page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a question page" + And I set the field "Select a question type" to "Essay" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Music essay | + | Page contents | Write a really interesting music essay | + | Jump | End of lesson | + | Score | 1 | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "Music essay" + And I should see "Write a really interesting music essay" + And I should see "End of lesson" in the "Jump 1" "table_row" + + Scenario: Create matching page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a question page" + And I set the field "Select a question type" to "Matching" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Geography | + | Page contents | Match each city with its country | + | id_answer_editor_0 | Correct! | + | id_jumpto_0 | End of lesson | + | id_score_0 | 2 | + | id_answer_editor_1 | Wrong! | + | id_jumpto_1 | This page | + | id_score_1 | 0 | + | id_answer_editor_2 | Barcelona | + | id_response_editor_2 | Spain | + | id_answer_editor_3 | Perth | + | id_response_editor_3 | Australia | + | id_answer_editor_4 | Tokyo | + | id_response_editor_4 | Japan | + | id_answer_editor_5 | Buenos Aires | + | id_response_editor_5 | Argentina | + | id_answer_editor_6 | Cairo | + | id_response_editor_6 | Egypt | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "Geography" + And I should see "Match each city with its country" + And I should see "Correct!" in the "Correct response" "table_row" + And I should see "2" in the "Correct answer score" "table_row" + And I should see "End of lesson" in the "Correct answer jump" "table_row" + And I should see "Wrong!" in the "Wrong response" "table_row" + And I should see "0" in the "Wrong answer score" "table_row" + And I should see "This page" in the "Wrong answer jump" "table_row" + And I should see "Barcelona" in the "Answer 1" "table_row" + And I should see "Spain" in the "Matches with answer 1" "table_row" + And I should see "Perth" in the "Answer 2" "table_row" + And I should see "Australia" in the "Matches with answer 2" "table_row" + And I should see "Tokyo" in the "Answer 3" "table_row" + And I should see "Japan" in the "Matches with answer 3" "table_row" + And I should see "Buenos Aires" in the "Answer 4" "table_row" + And I should see "Argentina" in the "Matches with answer 4" "table_row" + And I should see "Cairo" in the "Answer 5" "table_row" + And I should see "Egypt" in the "Matches with answer 5" "table_row" + + Scenario: Create multichoice page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a question page" + And I set the field "Select a question type" to "Multichoice" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Multichoice question | + | Page contents | What animal is an amphibian? | + | id_answer_editor_0 | Frog | + | id_response_editor_0 | Correct answer | + | id_jumpto_0 | End of lesson | + | id_score_0 | 2 | + | id_answer_editor_1 | Cat | + | id_response_editor_1 | Incorrect answer | + | id_jumpto_1 | This page | + | id_score_1 | 0 | + | id_answer_editor_2 | Dog | + | id_response_editor_2 | Incorrect answer | + | id_jumpto_2 | Next page | + | id_score_2 | 0 | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "Multichoice question" + And I should see "What animal is an amphibian?" + And I should see "Frog" in the "Answer 1" "table_row" + And I should see "Correct answer" in the "Response 1" "table_row" + And I should see "End of lesson" in the "//tr[contains(.,'Jump')][1]" "xpath_element" + And I should see "2" in the "//tr[contains(.,'Score')][1]" "xpath_element" + And I should see "Cat" in the "Answer 2" "table_row" + And I should see "Incorrect answer" in the "Response 2" "table_row" + And I should see "This page" in the "//tr[contains(.,'Jump')][2]" "xpath_element" + And I should see "0" in the "//tr[contains(.,'Score')][2]" "xpath_element" + And I should see "Dog" in the "Answer 3" "table_row" + And I should see "Incorrect answer" in the "Response 3" "table_row" + And I should see "Next page" in the "//tr[contains(.,'Jump')][3]" "xpath_element" + And I should see "0" in the "//tr[contains(.,'Score')][3]" "xpath_element" + + Scenario: Create numerical page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a question page" + And I set the field "Select a question type" to "Numerical" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Really hard question | + | Page contents | What is 1 + 2? | + | id_answer_editor_0 | 3 | + | id_response_editor_0 | Correct | + | id_jumpto_0 | End of lesson | + | id_score_0 | 2 | + | id_answer_editor_1 | 2 | + | id_response_editor_1 | Close, but wrong | + | id_jumpto_1 | Next page | + | id_score_1 | 1 | + | id_enableotheranswers | 1 | + | id_response_editor_6 | Wrong | + | id_jumpto_6 | This page | + | id_score_6 | 0 | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "Really hard question" + And I should see "What is 1 + 2?" + And I should see "3" in the "Answer 1" "table_row" + And I should see "Correct" in the "Response 1" "table_row" + And I should see "End of lesson" in the "//tr[contains(.,'Jump')][1]" "xpath_element" + And I should see "2" in the "//tr[contains(.,'Score')][1]" "xpath_element" + And I should see "2" in the "Answer 2" "table_row" + And I should see "Close, but wrong" in the "Response 2" "table_row" + And I should see "Next page" in the "//tr[contains(.,'Jump')][2]" "xpath_element" + And I should see "1" in the "//tr[contains(.,'Score')][2]" "xpath_element" + And I should see "@#wronganswer#@" in the "Answer 3" "table_row" + And I should see "Wrong" in the "Response 3" "table_row" + And I should see "This page" in the "//tr[contains(.,'Jump')][3]" "xpath_element" + And I should see "0" in the "//tr[contains(.,'Score')][3]" "xpath_element" + + Scenario: Create short answer page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a question page" + And I set the field "Select a question type" to "Short answer" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | Geography | + | Page contents | Capital of Canada | + | id_answer_editor_0 | Ottawa | + | id_response_editor_0 | Correct | + | id_jumpto_0 | End of lesson | + | id_score_0 | 2 | + | id_answer_editor_1 | Toronto | + | id_response_editor_1 | It's in Canada, but it's not the capital | + | id_jumpto_1 | Next page | + | id_score_1 | 1 | + | id_answer_editor_2 | Vancouver | + | id_response_editor_2 | It's in Canada, but it's not the capital | + | id_jumpto_2 | Next page | + | id_score_2 | 1 | + | id_enableotheranswers | 1 | + | id_response_editor_6 | Wrong | + | id_jumpto_6 | This page | + | id_score_6 | 0 | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "Geography" + And I should see "Capital of Canada" + And I should see "Ottawa" in the "Answer 1" "table_row" + And I should see "Correct" in the "Response 1" "table_row" + And I should see "End of lesson" in the "//tr[contains(.,'Jump')][1]" "xpath_element" + And I should see "2" in the "//tr[contains(.,'Score')][1]" "xpath_element" + And I should see "Toronto" in the "Answer 2" "table_row" + And I should see "It's in Canada, but it's not the capital" in the "Response 2" "table_row" + And I should see "Next page" in the "//tr[contains(.,'Jump')][2]" "xpath_element" + And I should see "1" in the "//tr[contains(.,'Score')][2]" "xpath_element" + And I should see "Vancouver" in the "Answer 3" "table_row" + And I should see "It's in Canada, but it's not the capital" in the "Response 3" "table_row" + And I should see "Next page" in the "//tr[contains(.,'Jump')][3]" "xpath_element" + And I should see "1" in the "//tr[contains(.,'Score')][3]" "xpath_element" + And I should see "@#wronganswer#@" in the "Answer 4" "table_row" + And I should see "Wrong" in the "Response 4" "table_row" + And I should see "This page" in the "//tr[contains(.,'Jump')][4]" "xpath_element" + And I should see "0" in the "//tr[contains(.,'Score')][4]" "xpath_element" + + Scenario: Create true/false page + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a question page" + And I set the field "Select a question type" to "True/false" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | True/false question | + | Page contents | Paper is made from trees. | + | id_answer_editor_0 | True | + | id_response_editor_0 | Correct | + | id_jumpto_0 | End of lesson | + | id_score_0 | 2 | + | id_answer_editor_1 | False | + | id_response_editor_1 | Wrong | + | id_jumpto_1 | This page | + | id_score_1 | 0 | + And I press "Save page" + And I select edit type "Expanded" + Then I should see "True/false question" + And I should see "Paper is made from trees." + And I should see "True" in the "Answer 1" "table_row" + And I should see "Correct" in the "Response 1" "table_row" + And I should see "End of lesson" in the "//tr[contains(.,'Jump')][1]" "xpath_element" + And I should see "2" in the "//tr[contains(.,'Score')][1]" "xpath_element" + And I should see "False" in the "Answer 2" "table_row" + And I should see "Wrong" in the "Response 2" "table_row" + And I should see "This page" in the "//tr[contains(.,'Jump')][2]" "xpath_element" + And I should see "0" in the "//tr[contains(.,'Score')][2]" "xpath_element" + + Scenario: Create cluster pages + When I am on the "Test lesson name" "lesson activity" page logged in as teacher1 + And I follow "Add a cluster" + And I select edit type "Expanded" + And I click on "Add a question page here" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][2]" "xpath_element" + And I set the field "Select a question type" to "Multichoice" + And I press "Add a question page" + And I set the following fields to these values: + | Page title | question 1 | + | Page contents | Question from cluster | + | id_answer_editor_0 | Correct answer | + | id_response_editor_0 | Good | + | id_jumpto_0 | Cluster | + | id_score_0 | 1 | + | id_answer_editor_1 | Incorrect answer | + | id_response_editor_1 | Bad | + | id_jumpto_1 | This page | + | id_score_1 | 0 | + And I press "Save page" + And I click on "Add a content page" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][3]" "xpath_element" + And I set the following fields to these values: + | Page title | Second page name | + | Page contents | This page mark the the beginning of the subcluster it should not be seen by students | + | id_answer_editor_0 | Next page | + | id_jumpto_0 | Next page | + And I press "Save page" + And I click on "Add an end of branch" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][4]" "xpath_element" + And I click on "Add an end of cluster" "link" in the "//div[contains(concat(' ', normalize-space(@class), ' '), ' addlinks ')][5]" "xpath_element" + Then I should see "Cluster" + And I should see "Unseen question within a cluster" in the "//tr[contains(.,'Jump')][1]" "xpath_element" + And I should see "Question from cluster" + And I should see "This page mark the the beginning of the subcluster it should not be seen by students" + And I should see "End of branch" + And I should see "End of cluster"