|
16 | 16 |
|
17 | 17 | namespace core; |
18 | 18 |
|
| 19 | +use core\context\course; |
| 20 | +use core\context\module; |
19 | 21 | use core_question\local\bank\question_bank_helper; |
20 | 22 | use mod_quiz\quiz_settings; |
| 23 | +use PHPUnit\Framework\Attributes\DataProvider; |
21 | 24 | use question_bank; |
22 | 25 |
|
23 | 26 | defined('MOODLE_INTERNAL') || die(); |
@@ -53,9 +56,9 @@ public function setUp(): void { |
53 | 56 |
|
54 | 57 | /** |
55 | 58 | * Generate a course and question bank module instance for use in test cases, and return the bank context. |
56 | | - * @return \core\context\module |
| 59 | + * @return module |
57 | 60 | */ |
58 | | - protected function create_course_and_question_bank(): \core\context\module { |
| 61 | + protected function create_course_and_question_bank(): module { |
59 | 62 | $course = self::getDataGenerator()->create_course(); |
60 | 63 | $qbank = self::getDataGenerator()->create_module('qbank', ['course' => $course->id]); |
61 | 64 | return \context_module::instance($qbank->cmid); |
@@ -1777,4 +1780,76 @@ public function test_move_question_set_references_category(): void { |
1777 | 1780 | $this->assertEquals($randomquestion->contextid, $context2->id); |
1778 | 1781 | $this->assertEquals($randomquestion->filtercondition['filter']['category']['values'][0], $topcategory2->id); |
1779 | 1782 | } |
| 1783 | + |
| 1784 | + /** |
| 1785 | + * Provide examples of different modules and the page types returned by their _page_type_list function. |
| 1786 | + * |
| 1787 | + * @return array[] Module name, and a list of page types. |
| 1788 | + */ |
| 1789 | + public static function module_page_types(): array { |
| 1790 | + return [ |
| 1791 | + 'quiz' => [ |
| 1792 | + 'module' => 'quiz', |
| 1793 | + 'pagetypes' => [ |
| 1794 | + 'mod-quiz-*', |
| 1795 | + 'mod-quiz-view', |
| 1796 | + 'mod-quiz-attempt', |
| 1797 | + 'mod-quiz-summary', |
| 1798 | + 'mod-quiz-review', |
| 1799 | + 'mod-quiz-edit', |
| 1800 | + 'mod-quiz-report', |
| 1801 | + ], |
| 1802 | + ], |
| 1803 | + 'forum' => [ |
| 1804 | + 'module' => 'forum', |
| 1805 | + 'pagetypes' => [ |
| 1806 | + 'mod-forum-*', |
| 1807 | + 'mod-forum-view', |
| 1808 | + 'mod-forum-discuss', |
| 1809 | + ], |
| 1810 | + ], |
| 1811 | + 'scorm' => [ |
| 1812 | + 'module' => 'scorm', |
| 1813 | + 'pagetypes' => [ |
| 1814 | + 'mod-scorm-*', |
| 1815 | + ], |
| 1816 | + ], |
| 1817 | + 'lti' => [ // LTI has no additional page types. |
| 1818 | + 'module' => 'lti', |
| 1819 | + 'pagetypes' => [], |
| 1820 | + ], |
| 1821 | + ]; |
| 1822 | + } |
| 1823 | + |
| 1824 | + /** |
| 1825 | + * Calling question_page_type_list should return the question page types, plus the page types for the module context. |
| 1826 | + * |
| 1827 | + * @covers ::question_page_type_list |
| 1828 | + * @param string $module The module name. |
| 1829 | + * @param string[] $pagetypes A list of the page type patterns this module should add. |
| 1830 | + */ |
| 1831 | + #[DataProvider('module_page_types')] |
| 1832 | + public function test_question_page_type_list(string $module, array $pagetypes): void { |
| 1833 | + $this->resetAfterTest(); |
| 1834 | + $this->setAdminUser(); |
| 1835 | + |
| 1836 | + $course = $this->getDataGenerator()->create_course(); |
| 1837 | + $coursecontext = course::instance($course->id); |
| 1838 | + |
| 1839 | + $modulerecord = $this->getDataGenerator()->create_module($module, ['course' => $course->id]); |
| 1840 | + $modulecontext = module::instance($modulerecord->cmid); |
| 1841 | + |
| 1842 | + $questionpagetypes = [ |
| 1843 | + 'question-*', |
| 1844 | + 'question-edit', |
| 1845 | + 'question-bank-managecategories-category', |
| 1846 | + 'question-bank-exportquestions-export', |
| 1847 | + 'question-bank-importquestions-import', |
| 1848 | + ]; |
| 1849 | + |
| 1850 | + $expectedpagetypes = array_merge($pagetypes, $questionpagetypes); |
| 1851 | + $actualpagetypes = question_page_type_list('question-edit', $coursecontext, $modulecontext); |
| 1852 | + // Check that the expected page type patterns match those returned for this module. |
| 1853 | + $this->assertEquals($expectedpagetypes, array_keys($actualpagetypes)); |
| 1854 | + } |
1780 | 1855 | } |
0 commit comments