Skip to content

Commit

Permalink
remove behat tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ewallah committed Apr 1, 2021
1 parent b6d623f commit 01d258e
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 119 deletions.
4 changes: 2 additions & 2 deletions classes/output/course_format.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ public function export_for_template(\renderer_base $output) {
$course = $this->format->get_course();
$completioninfo = new \completion_info($course);
$context = \context_course::instance($course->id);
$border = "$course->borderwidth px solid $course->bordercolor";
$border = $course->borderwidth . 'px solid ' . $course->bordercolor;
$sections = [];
foreach ($modinfo->get_section_info_all() as $sectionnum => $section) {
$showsection = $section->uservisible ||
($section->visible && !$section->available && !empty($section->availableinfo)) ||
(!$section->visible && !$course->hiddensections);
if ($showsection) {
if ($showsection ) {
if ($sectionnum == 0) {
$sectionname = get_string('section0name', 'format_masonry');
} else {
Expand Down
133 changes: 78 additions & 55 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,52 @@
*/
class format_masonry extends core_course\course_format {

/**
* Returns true if this course format uses sections.
*
* @return bool
*/
public function uses_sections() {
return true;
}

/**
* Returns the display name of the given section that the course prefers.
*
* @param int|stdClass $section Section object from database or just field section.section
* @return string Display name that the course format prefers, e.g. "Topic 2"
*/
public function get_section_name($section) {
$section = $this->get_section($section);
if ((string)$section->name !== '') {
return format_string($section->name, true, ['context' => context_course::instance($this->courseid)]);
} else {
return $this->get_default_section_name($section);
}
}

/**
* Returns the default section name for the topics course format.
*
* @param stdClass $section Section object from database or just field course_sections section
* @return string The default value for the section name.
*/
public function get_default_section_name($section) {
if ($section->section == 0) {
return get_string('section0name', 'format_masonry');
}
return parent::get_default_section_name($section);
}

/**
* Generate the title for this section page.
*
* @return string the page title
*/
public function page_title(): string {
return get_string('topicoutline');
}

/**
* The URL to use for the specified course (with section)
*
Expand All @@ -47,6 +93,26 @@ public function get_view_url($section, $options = []) {
return new \moodle_url('/course/view.php', ['id' => $course->id]);
}

/**
* Loads no course sections into the navigation
*
* @param global_navigation $navigation
* @param navigation_node $node The course node within the navigation
*/
public function extend_course_navigation($navigation, navigation_node $node) {
return [];
}

/**
* Returns the list of blocks to be automatically added for the newly created course.
*
* @return array of default blocks, must contain two keys BLOCK_POS_LEFT and BLOCK_POS_RIGHT
* each of values is an array of block names (for left and right side columns)
*/
public function get_default_blocks() {
return [BLOCK_POS_LEFT => [], BLOCK_POS_RIGHT => []];
}

/**
* Definitions of the additional options that this course format uses for section
*
Expand All @@ -68,6 +134,18 @@ public function section_format_options($foreditform = false) {
'help_component' => 'format_masonry']];
}

/**
* Whether this format allows to delete sections.
*
* Do not call this function directly, instead use {@link course_can_delete_section()}
*
* @param int|stdClass|section_info $section
* @return bool
*/
public function can_delete_section($section) {
return true;
}

/**
* Definitions of the additional options that this course format uses for course
*
Expand Down Expand Up @@ -170,59 +248,4 @@ public function get_config_for_external() {
// Return everything (nothing to hide).
return $this->get_format_options();
}

/**
* Returns the default section name for the topics course format.
*
* @param stdClass $section Section object from database or just field course_sections section
* @return string The default value for the section name.
*/
public function get_default_section_name($section) {
if ($section->section == 0) {
return get_string('section0name', 'format_masonry');
}
return parent::get_default_section_name($section);
}

/**
* Prepares the templateable object to display section name
*
* @param \section_info|\stdClass $section
* @param bool $linkifneeded
* @param bool $editable
* @param null|lang_string|string $edithint
* @param null|lang_string|string $editlabel
* @return \core\output\inplace_editable
*/
public function inplace_editable_render_section_name(
$section, $linkifneeded = true, $editable = null, $edithint = null, $editlabel = null) {

if (empty($edithint)) {
$edithint = new \lang_string('editsectionname', 'format_topics');
}
if (empty($editlabel)) {
$title = get_section_name($section->course, $section);
$editlabel = new \lang_string('newsectionname', 'format_topics', $title);
}
return parent::inplace_editable_render_section_name($section, $linkifneeded, $editable, $edithint, $editlabel);
}
}

/**
* Implements callback inplace_editable() allowing to edit values in-place
*
* @param string $itemtype
* @param int $itemid
* @param mixed $newvalue
* @return \core\output\inplace_editable
*/
function format_masonry_inplace_editable($itemtype, $itemid, $newvalue) {
global $DB, $CFG;
require_once($CFG->dirroot . '/course/lib.php');
if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
$section = $DB->get_record_sql(
'SELECT s.* FROM {course_sections} s JOIN {course} c ON s.course = c.id WHERE s.id = ? AND c.format = ?',
[$itemid, 'masonry'], MUST_EXIST);
return course_get_format($section->course)->inplace_editable_update_section_name($section, $itemtype, $newvalue);
}
}
1 change: 0 additions & 1 deletion renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,4 @@ public function render(renderable $widget) {
}
return parent::render($widget);
}

}
3 changes: 1 addition & 2 deletions templates/course_format.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@
}
}}
<h2 class="accesshide">{{{title}}}</h2>
<div style="float:right">{{{completionhelp}}}</div>
<ul id="coursemasonry" class="masonry">
{{#sections}}
<li id="section-{{num}}"
Expand All @@ -91,7 +90,7 @@
<div class="content">
<h3 class="sectionid-{{id}}-title sectionname">
{{#controlmenu}}
<a href="/course/editsection.php?id={{id}}">{{# pix }} t/edit, core, Edit David Beckham {{/ pix }}</a>
<a href="/course/editsection.php?id={{id}}">{{# pix }} t/edit, core, {{#str}} editsection, moodle {{/str}} {{/ pix }}</a>
{{/controlmenu}}
{{#aheader}} {{ aheader}} {{/aheader}}
{{^aheader}} {{#str}} sectionname, format_masonry {{/str}} {{ num }} {{/aheader}}
Expand Down
16 changes: 2 additions & 14 deletions tests/behat/format_masonry.feature
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Feature: format_masonry

Scenario: Empty section 0 stays hidden
Given I am on the "C1" "Course" page logged in as "teacher1"
Then I should not see "General" in the ".course-content" "css_element"
Then I should see "General" in the ".course-content" "css_element"

When I turn editing mode on
And I add a "Page" to section "0"
Expand All @@ -42,7 +42,7 @@ Feature: format_masonry
| Page content | x |
And I click on "Save and return to course" "button"
And I turn editing mode off
Then I should not see "General" in the "li#section-0" "css_element"
Then I should see "General" in the "li#section-0" "css_element"

Scenario: The modules should be visible and hidden in masonry format
Given I am on the "C1" "Course" page logged in as "teacher1"
Expand Down Expand Up @@ -84,15 +84,3 @@ Feature: format_masonry
And I press "Save changes"
And I turn editing mode off
Then I should see "first" in the "li#section-1" "css_element"

@javascript
Scenario: Inline edit section name in masonry format
Given I am on the "C1" "Course" page logged in as "teacher1"
And I turn editing mode on
And I set the field "Edit topic name" in the "li#section-1" "css_element" to "Masonry"
Then I should not see "Topic 1" in the "region-main" "region"
And "New name for topic" "field" should not exist
And I should see "Masonry" in the "li#section-1" "css_element"
And I am on "Course 1" course homepage
And I should not see "Topic 1" in the "region-main" "region"
And I should see "Masonry" in the "li#section-1" "css_element"

0 comments on commit 01d258e

Please sign in to comment.