|
20 | 20 | use core\context\module; |
21 | 21 | use core_question\local\bank\question_bank_helper; |
22 | 22 | use mod_quiz\quiz_settings; |
| 23 | +use PHPUnit\Framework\Attributes\DataProvider; |
23 | 24 | use question_bank; |
24 | 25 |
|
25 | 26 | defined('MOODLE_INTERNAL') || die(); |
@@ -1781,31 +1782,74 @@ public function test_move_question_set_references_category(): void { |
1781 | 1782 | } |
1782 | 1783 |
|
1783 | 1784 | /** |
1784 | | - * Check the page type list is correct based on the context of the module the question is in. |
| 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. |
1785 | 1826 | * |
1786 | 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. |
1787 | 1830 | */ |
1788 | | - public function test_question_page_type_list(): void { |
| 1831 | + #[DataProvider('module_page_types')] |
| 1832 | + public function test_question_page_type_list(string $module, array $pagetypes): void { |
1789 | 1833 | $this->resetAfterTest(); |
1790 | 1834 | $this->setAdminUser(); |
1791 | 1835 |
|
1792 | 1836 | $course = $this->getDataGenerator()->create_course(); |
1793 | 1837 | $coursecontext = course::instance($course->id); |
1794 | 1838 |
|
1795 | | - $quiz = $this->getDataGenerator()->create_module('quiz', ['course' => $course->id]); |
1796 | | - $quizcontext = module::instance($quiz->cmid); |
| 1839 | + $modulerecord = $this->getDataGenerator()->create_module($module, ['course' => $course->id]); |
| 1840 | + $modulecontext = module::instance($modulerecord->cmid); |
1797 | 1841 |
|
1798 | | - $forum = $this->getDataGenerator()->create_module('forum', ['course' => $course->id]); |
1799 | | - $forumcontext = module::instance($forum->cmid); |
1800 | | - |
1801 | | - $scorm = $this->getDataGenerator()->create_module('scorm', ['course' => $course->id]); |
1802 | | - $scormcontext = module::instance($scorm->cmid); |
| 1842 | + $questionpagetypes = [ |
| 1843 | + 'question-*', |
| 1844 | + 'question-edit', |
| 1845 | + 'question-bank-managecategories-category', |
| 1846 | + 'question-bank-exportquestions-export', |
| 1847 | + 'question-bank-importquestions-import', |
| 1848 | + ]; |
1803 | 1849 |
|
1804 | | - // Function quiz_page_type_list has 7 additional page types. |
1805 | | - $this->assertCount(12, question_page_type_list('question-edit', $coursecontext, $quizcontext)); |
1806 | | - // Function forum_page_type_list has 3 additional page types. |
1807 | | - $this->assertCount(8, question_page_type_list('question-edit', $coursecontext, $forumcontext)); |
1808 | | - // Function scorm_page_type_list has 1 additional page types. |
1809 | | - $this->assertCount(6, question_page_type_list('question-edit', $coursecontext, $scormcontext)); |
| 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)); |
1810 | 1854 | } |
1811 | 1855 | } |
0 commit comments