Skip to content

Commit

Permalink
Moodle 40
Browse files Browse the repository at this point in the history
  • Loading branch information
rdebleu committed Apr 24, 2022
1 parent 86b31d1 commit 84b68a8
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cron.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
moodle-branch: ['MOODLE_311_STABLE']
php: ['7.4']
php: ['8.0']
database: ['mysqli']

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down
8 changes: 4 additions & 4 deletions classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<style>.masonry {margin: auto auto} $str</style>";
Expand Down
8 changes: 4 additions & 4 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
* Privacy main class.
*
* @package format_masonry
* @copyright 2018 Renaat Debleu (www.eWallah.net)
* @copyright 2018 eWallah.net
* @author Renaat Debleu <info@eWallah.net>
* @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 <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements null_provider {
Expand Down
4 changes: 1 addition & 3 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
*
* @package format_masonry
* @copyright 2018 eWallah.net
* @author Renaat Debleu (www.ewallah.net)
* @author Renaat Debleu <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

/**
* Upgrade script for format_masonry
*
Expand Down
5 changes: 3 additions & 2 deletions format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,14 +41,15 @@ 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, {

initializer: function() {
this._create();
this._init();
this._reLayout();
},

destructor: function() {
Expand Down
8 changes: 6 additions & 2 deletions templates/content.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,14 @@
<h2 class="accesshide">{{{title}}}</h2>
<ul class="masonry mb-5" data-for="course_sectionlist">
{{#initialsection}}
{{> format_masonry/section }}
<li id="section-{{num}}" class="section masonry-brick course-section float-left pr-0 mt-2 mr-2 rounded">
{{> format_masonry/section }}
</li>
{{/initialsection}}
{{#sections}}
{{> format_masonry/section }}
<li id="section-{{num}}" class="section masonry-brick course-section float-left pr-0 mt-2 mr-2 rounded">
{{> format_masonry/section }}
</li>
{{/sections}}
</ul>
</div>
35 changes: 17 additions & 18 deletions templates/section.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"controlmenu": "[tools menu]",
"header": {
"name": "Section title",
"title": "Section title",
"url": "#",
"ishidden": false
},
Expand Down Expand Up @@ -79,23 +80,21 @@
"sitehome": false
}
}}
<li id="section-{{num}}" class="section masonry-brick course-section float-left pr-0 mt-2 mr-2 rounded">
<div class="course-section-header">
{{#header}} {{> format_masonry/header }} {{/header}}
<div data-region="sectionbadges" class="sectionbadges d-flex align-items-center">
{{> core_courseformat/local/content/section/badges }}
</div>
<div class="course-section-header">
{{#header}} {{> format_masonry/header }} {{/header}}
<div data-region="sectionbadges" class="sectionbadges d-flex align-items-center">
{{> core_courseformat/local/content/section/badges }}
</div>
<div class="coursecontentmasonry content show">
<div class="{{#hasavailability}}description small{{/hasavailability}}">
{{#summary}}
{{> core_courseformat/local/content/section/summary }}
{{/summary}}
{{#availability}}
{{> core_courseformat/local/content/section/availability }}
{{/availability}}
</div>
{{#cmsummary}} {{> core_courseformat/local/content/section/cmsummary }} {{/cmsummary}}
{{#cmlist}} {{> format_masonry/cmlist }} {{/cmlist}}
</div>
<div class="coursecontentmasonry content show">
<div class="{{#hasavailability}}description small{{/hasavailability}}">
{{#summary}}
{{> core_courseformat/local/content/section/summary }}
{{/summary}}
{{#availability}}
{{> core_courseformat/local/content/section/availability }}
{{/availability}}
</div>
</li>
{{#cmsummary}} {{> core_courseformat/local/content/section/cmsummary }} {{/cmsummary}}
{{#cmlist}} {{> format_masonry/cmlist }} {{/cmlist}}
</div>
61 changes: 25 additions & 36 deletions tests/masonry_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <info@eWallah.net>
* @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 <info@eWallah.net>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class masonry_test extends \advanced_testcase {

Expand Down Expand Up @@ -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();
Expand 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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');
Expand All @@ -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;
Expand All @@ -302,6 +301,7 @@ public function test_format_editing() {

/**
* Test other.
* @covers \format_masonry
*/
public function test_other() {
$this->setAdminUser();
Expand All @@ -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');
}
}
67 changes: 67 additions & 0 deletions tests/other_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* format_masonry related other unit tests
*
* @package format_masonry
* @copyright 2018 eWallah.net
* @author Renaat Debleu <info@eWallah.net>
* @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 <info@eWallah.net>
* @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);
}
}

0 comments on commit 84b68a8

Please sign in to comment.