From 84b68a8e59ec8f44912b162b77a1c837ab7412bf Mon Sep 17 00:00:00 2001 From: Renaat Debleu Date: Sun, 24 Apr 2022 13:09:40 +0000 Subject: [PATCH] Moodle 40 --- .github/workflows/cron.yml | 2 +- .github/workflows/main.yml | 2 +- classes/output/renderer.php | 8 ++-- classes/privacy/provider.php | 8 ++-- db/upgrade.php | 4 +- format.js | 5 ++- templates/content.mustache | 8 +++- templates/section.mustache | 35 +++++++-------- tests/masonry_test.php | 61 +++++++++++-------------- tests/other_test.php | 67 ++++++++++++++++++++++++++++ tests/{ => privacy}/privacy_test.php | 10 ++--- 11 files changed, 134 insertions(+), 76 deletions(-) create mode 100644 tests/other_test.php rename tests/{ => privacy}/privacy_test.php (88%) diff --git a/.github/workflows/cron.yml b/.github/workflows/cron.yml index 9998a35..9551c16 100644 --- a/.github/workflows/cron.yml +++ b/.github/workflows/cron.yml @@ -13,7 +13,7 @@ jobs: fail-fast: false matrix: moodle-branch: ['MOODLE_311_STABLE'] - php: ['7.4'] + php: ['8.0'] database: ['mysqli'] steps: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 191d076..bd5cbb8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - moodle-branch: ['master'] + moodle-branch: ['MOODLE_400_STABLE', 'master'] php: ['8.0', '7.4'] database: ['mysqli'] diff --git a/classes/output/renderer.php b/classes/output/renderer.php index 8af7222..c870df0 100644 --- a/classes/output/renderer.php +++ b/classes/output/renderer.php @@ -79,10 +79,10 @@ public function render_content($widget) { $str .= 'background-color:' . $options->backcolor . ' !important;'; $str .= 'border: ' . trim($options->borderwidth) . 'px solid '. $options->bordercolor . ' !important;}'; $moduleinfo = $format->get_modinfo(); - $sections = $moduleinfo->get_sections(); - foreach ($sections as $sectionnumber => $section) { - $options = (object) $format->get_format_options($sectionnumber); - $str .= '#section-' . $sectionnumber . ' {'; + $sections = array_keys($moduleinfo->get_sections()); + foreach ($sections as $section) { + $options = (object) $format->get_format_options($section); + $str .= '#section-' . $section . ' {'; $str .= 'background-color:' . $options->backcolor . ' !important;} '; } $extra = ""; diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php index 20fd0bd..d76e443 100644 --- a/classes/privacy/provider.php +++ b/classes/privacy/provider.php @@ -18,21 +18,21 @@ * Privacy main class. * * @package format_masonry - * @copyright 2018 Renaat Debleu (www.eWallah.net) + * @copyright 2018 eWallah.net + * @author Renaat Debleu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace format_masonry\privacy; -defined('MOODLE_INTERNAL') || die(); - use \core_privacy\local\metadata\null_provider; /** * Privacy main class. * * @package format_masonry - * @copyright 2018 Renaat Debleu (www.eWallah.net) + * @copyright 2018 eWallah.net + * @author Renaat Debleu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class provider implements null_provider { diff --git a/db/upgrade.php b/db/upgrade.php index c8fe985..adc49d2 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -19,12 +19,10 @@ * * @package format_masonry * @copyright 2018 eWallah.net - * @author Renaat Debleu (www.ewallah.net) + * @author Renaat Debleu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -defined('MOODLE_INTERNAL') || die(); - /** * Upgrade script for format_masonry * diff --git a/format.js b/format.js index 8eeac66..f4189a7 100644 --- a/format.js +++ b/format.js @@ -25,7 +25,7 @@ M.masonry.init = function(Y, cfg) { setter: function(node) { var n = Y.one(node); if (!n) { - n = Y.one('#coursemasonry'); + n = Y.one('.masonry'); } if (!n) { Y.fail('Masonry: Invalid Node Given: ' + node); @@ -41,7 +41,7 @@ M.masonry.init = function(Y, cfg) { isFitWidth: {value: true}, containerStyle: {value: {position: 'relative'}}, columnWidth: {value: 2}, - itemSelector: {value: '.section.main'} + itemSelector: {value: '.masonry-brick'} }; Y.extend(Masonry, Y.Base, { @@ -49,6 +49,7 @@ M.masonry.init = function(Y, cfg) { initializer: function() { this._create(); this._init(); + this._reLayout(); }, destructor: function() { diff --git a/templates/content.mustache b/templates/content.mustache index bba1cfc..7533dc7 100644 --- a/templates/content.mustache +++ b/templates/content.mustache @@ -138,10 +138,14 @@

{{{title}}}

    {{#initialsection}} - {{> format_masonry/section }} +
  • + {{> format_masonry/section }} +
  • {{/initialsection}} {{#sections}} - {{> format_masonry/section }} +
  • + {{> format_masonry/section }} +
  • {{/sections}}
diff --git a/templates/section.mustache b/templates/section.mustache index 31779d6..3486b16 100644 --- a/templates/section.mustache +++ b/templates/section.mustache @@ -26,6 +26,7 @@ "controlmenu": "[tools menu]", "header": { "name": "Section title", + "title": "Section title", "url": "#", "ishidden": false }, @@ -79,23 +80,21 @@ "sitehome": false } }} -
  • -
    - {{#header}} {{> format_masonry/header }} {{/header}} -
    - {{> core_courseformat/local/content/section/badges }} -
    +
    + {{#header}} {{> format_masonry/header }} {{/header}} +
    + {{> core_courseformat/local/content/section/badges }}
    -
    -
    - {{#summary}} - {{> core_courseformat/local/content/section/summary }} - {{/summary}} - {{#availability}} - {{> core_courseformat/local/content/section/availability }} - {{/availability}} -
    - {{#cmsummary}} {{> core_courseformat/local/content/section/cmsummary }} {{/cmsummary}} - {{#cmlist}} {{> format_masonry/cmlist }} {{/cmlist}} +
    +
    +
    + {{#summary}} + {{> core_courseformat/local/content/section/summary }} + {{/summary}} + {{#availability}} + {{> core_courseformat/local/content/section/availability }} + {{/availability}}
    -
  • + {{#cmsummary}} {{> core_courseformat/local/content/section/cmsummary }} {{/cmsummary}} + {{#cmlist}} {{> format_masonry/cmlist }} {{/cmlist}} + diff --git a/tests/masonry_test.php b/tests/masonry_test.php index abdea52..dfbb3f8 100644 --- a/tests/masonry_test.php +++ b/tests/masonry_test.php @@ -17,21 +17,21 @@ /** * format_masonry related unit tests * - * @package format_masonry - * @copyright 2017 Renaat Debleu (www.eWallah.net) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package format_masonry + * @copyright 2018 eWallah.net + * @author Renaat Debleu + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace format_masonry; -defined('MOODLE_INTERNAL') || die(); - /** * format_masonry related unit tests * - * @package format_masonry - * @copyright 2017 Renaat Debleu (www.eWallah.net) - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @package format_masonry + * @copyright 2018 eWallah.net + * @author Renaat Debleu + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class masonry_test extends \advanced_testcase { @@ -74,6 +74,7 @@ public function setUp(): void { /** * Tests for format_masonry::get_section_name method with default section names. + * @covers \format_masonry */ public function test_get_section_name() { $sections = get_fast_modinfo($this->course)->get_section_info_all(); @@ -93,6 +94,7 @@ public function test_get_section_name() { /** * Tests for format_masonry::get_section_name method with modified section names. + * @covers \format_masonry */ public function test_get_section_name_customised() { global $DB; @@ -115,6 +117,7 @@ public function test_get_section_name_customised() { /** * Test web service updating section name + * @covers \format_masonry_inplace_editable */ public function test_update_inplace_editable() { global $CFG, $DB, $USER; @@ -147,6 +150,7 @@ public function test_update_inplace_editable() { /** * Test callback updating section name + * @covers \format_masonry_inplace_editable */ public function test_inplace_editable() { global $DB, $PAGE, $USER; @@ -175,6 +179,7 @@ public function test_inplace_editable() { /** * Test get_default_course_enddate. + * @covers \format_masonry */ public function test_default_course_enddate() { global $CFG, $DB; @@ -208,6 +213,8 @@ public function test_default_course_enddate() { /** * Test renderer. + * @covers \format_masonry\output\renderer + * @covers \format_masonry\output\courseformat\content\cm */ public function test_renderer() { global $USER; @@ -238,22 +245,17 @@ public function test_renderer() { $outputclass = $format->get_output_classname('content'); $widget = new $outputclass($format); $this->assertStringContainsString('Topic 2', $renderer->render($widget)); - } - - /** - * Test upgrade. - */ - public function test_upgrade() { - global $CFG; - require_once($CFG->dirroot . '/course/format/masonry/db/upgrade.php'); - require_once($CFG->libdir . '/upgradelib.php'); - $this->expectException(\moodle_exception::class); - $this->expectExceptionMessage('Cannot downgrade'); - xmldb_format_masonry_upgrade(time()); + $masonryformat = course_get_format($this->course->id); + $cms = $modinfo->get_cms(); + foreach ($cms as $cm) { + $cmb = new \format_masonry\output\courseformat\content\cm($masonryformat, $section, $cm); + $cmb->export_for_template($renderer); + } } /** * Test format. + * @covers \format_masonry */ public function test_format() { global $CFG, $PAGE, $USER; @@ -265,12 +267,10 @@ public function test_format() { $PAGE->get_renderer('format_masonry'); $course = $this->course; $_POST['sesskey'] = sesskey(); - $marker = 1; ob_start(); include_once($CFG->dirroot . '/course/format/masonry/format.php'); ob_end_clean(); - // Marker changed. - $this->assertNotEquals($course, $this->course); + $this->assertEquals($course, $this->course); $USER->editing = true; ob_start(); include_once($CFG->dirroot . '/course/format/masonry/format.php'); @@ -279,8 +279,7 @@ public function test_format() { /** * Test format editing. - * @covers format_masonry - * @covers format_masonry\output\courseformat\content\cm + * @covers \format_masonry */ public function test_format_editing() { global $CFG, $PAGE, $USER; @@ -302,6 +301,7 @@ public function test_format_editing() { /** * Test other. + * @covers \format_masonry */ public function test_other() { $this->setAdminUser(); @@ -320,15 +320,4 @@ public function test_other() { $this->assertNull(format_masonry_inplace_editable('othername', $sections[2]->id, 'newname')); } - /** - * Settings testcase. - */ - public function test_settings() { - global $ADMIN, $CFG, $USER; - $this->setAdminUser(); - $ADMIN = $USER; - $ADMIN->fulltree = true; - $settings = new \admin_settingpage('test', 'test'); - require_once($CFG->dirroot . '/course/format/masonry/settings.php'); - } } diff --git a/tests/other_test.php b/tests/other_test.php new file mode 100644 index 0000000..506a193 --- /dev/null +++ b/tests/other_test.php @@ -0,0 +1,67 @@ +. + +/** + * format_masonry related other unit tests + * + * @package format_masonry + * @copyright 2018 eWallah.net + * @author Renaat Debleu + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace format_masonry; + +/** + * format_masonry related other unit tests + * + * @package format_masonry + * @copyright 2018 eWallah.net + * @author Renaat Debleu + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class other_test extends \advanced_testcase { + + + /** + * Test upgrade. + * @coversNothing + */ + public function test_upgrade() { + global $CFG; + $this->resetAfterTest(true); + require_once($CFG->dirroot . '/course/format/masonry/db/upgrade.php'); + require_once($CFG->libdir . '/upgradelib.php'); + $this->expectException(\moodle_exception::class); + $this->expectExceptionMessage('Cannot downgrade'); + xmldb_format_masonry_upgrade(time()); + } + + /** + * Settings testcase. + * @covers \format_masonry + */ + public function test_settings() { + global $ADMIN, $CFG, $USER; + $this->resetAfterTest(true); + $this->setAdminUser(); + $ADMIN = $USER; + $ADMIN->fulltree = true; + $settings = new \admin_settingpage('test', 'test'); + require_once($CFG->dirroot . '/course/format/masonry/settings.php'); + $this->assertNotEmpty($settings); + } +} diff --git a/tests/privacy_test.php b/tests/privacy/privacy_test.php similarity index 88% rename from tests/privacy_test.php rename to tests/privacy/privacy_test.php index ab58f42..7d5d26a 100644 --- a/tests/privacy_test.php +++ b/tests/privacy/privacy_test.php @@ -18,14 +18,13 @@ * Course format masonry privacy tests. * * @package format_masonry - * @copyright 2017 eWallah.net + * @copyright 2018 eWallah.net + * @author Renaat Debleu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ namespace format_masonry\privacy; -defined('MOODLE_INTERNAL') || die(); - use core_privacy\tests\provider_testcase; use core_privacy\local\metadata\collection; @@ -33,14 +32,15 @@ * Course format masonry privacy tests. * * @package format_masonry - * @copyright 2017 eWallah.net + * @copyright 2018 eWallah.net + * @author Renaat Debleu * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class privacy_test extends provider_testcase { /** * Test returning metadata. - * @covers format_masonry\privacy\provider + * @covers \format_masonry\privacy\provider */ public function test_get_metadata() { $collection = new collection('format_masonry');