Merge branch 'MDL-86020-main' of https://github.com/sarjona/moodle

This commit is contained in:
Sara Arjona
2025-07-28 16:10:20 +02:00
3 changed files with 64 additions and 49 deletions
@@ -16,14 +16,14 @@
namespace mod_wiki\courseformat;
use core\output\renderer_helper;
use core\url;
use cm_info;
use core_courseformat\local\overview\overviewitem;
use core\output\action_link;
use core\output\local\properties\text_align;
use core\output\local\properties\button;
use core\url;
use mod_wiki\manager;
use core\output\action_link;
use core\output\renderer_helper;
use core\output\local\properties\button;
use core\output\local\properties\text_align;
use core_courseformat\local\overview\overviewitem;
/**
* Wiki overview integration.
@@ -43,14 +43,11 @@ class overview extends \core_courseformat\activityoverviewbase {
*
* @param cm_info $cm the course module instance.
* @param renderer_helper $rendererhelper the renderer helper.
* @param \core_string_manager $stringmanager
*/
public function __construct(
cm_info $cm,
/** @var renderer_helper $rendererhelper the renderer helper */
protected readonly renderer_helper $rendererhelper,
/** @var \core_string_manager $stringmanager the string manager */
protected readonly \core_string_manager $stringmanager,
) {
parent::__construct($cm);
$this->manager = manager::create_from_coursemodule($cm);
@@ -61,24 +58,30 @@ class overview extends \core_courseformat\activityoverviewbase {
if (!has_capability('mod/wiki:managewiki', $this->cm->context)) {
return null; // If the user cannot manage the wiki, we don't show the actions.
}
// If a wiki does not have a main page means it is not used yet, so we do not show the action link.
$pageid = $this->manager->get_main_wiki_pageid();
if (!$pageid) {
return null;
}
$text = $this->stringmanager->get_string('view');
$content = new action_link(
url: new url(
if ($pageid) {
// If the main page of the wiki exists, link to the map view.
$url = new url(
'/mod/wiki/map.php',
['pageid' => $pageid],
),
);
} else {
$url = new url(
'/mod/wiki/view.php',
['id' => $this->cm->id],
);
}
$text = get_string('view');
$content = new action_link(
url: $url,
text: $text,
attributes: ['class' => button::SECONDARY_OUTLINE->classes()],
);
return new overviewitem(
name: $this->stringmanager->get_string('actions'),
name: get_string('actions'),
value: $text,
content: $content,
textalign: text_align::CENTER,
@@ -100,10 +103,9 @@ class overview extends \core_courseformat\activityoverviewbase {
*/
private function get_extra_wiki_type(): overviewitem {
return new overviewitem(
name: $this->stringmanager->get_string('wikimode', 'wiki'),
name: get_string('wikimode', 'wiki'),
value: $this->manager->get_wiki_mode()->value,
content: $this->manager->get_wiki_mode()->to_string(),
textalign: text_align::CENTER,
);
}
@@ -119,7 +121,7 @@ class overview extends \core_courseformat\activityoverviewbase {
}
$entriescount = $this->manager->get_user_entries_count($USER->id);
return new overviewitem(
name: $this->stringmanager->get_string('myentries', 'wiki'),
name: get_string('myentries', 'wiki'),
value: $entriescount,
content: $entriescount,
textalign: text_align::CENTER,
@@ -134,9 +136,9 @@ class overview extends \core_courseformat\activityoverviewbase {
private function get_total_entries(): overviewitem {
global $USER;
$entriescount = $this->manager->get_all_entries_count($USER->id);
$label = $this->stringmanager->get_string('totalentries', 'wiki');
$label = get_string('totalentries', 'wiki');
if (has_capability('mod/wiki:managewiki', $this->cm->context)) {
$label = $this->stringmanager->get_string('entries', 'wiki');
$label = get_string('entries', 'wiki');
}
return new overviewitem(
name: $label,
@@ -31,9 +31,11 @@ Feature: Testing overview integration in mod_wiki
| student2 | G2 |
| student3 | G3 |
And the following "activities" exist:
| activity | course | name | idnumber | wikimode | firstpagetitle | groupmode |
| wiki | C1 | Separate wiki | wiki1 | collaborative | Separate page 1 | 1 |
| wiki | C1 | Visible wiki | wiki2 | collaborative | Visible page 1 | 2 |
| activity | course | name | idnumber | wikimode | firstpagetitle | groupmode |
| wiki | C1 | Separate wiki | wiki1 | collaborative | Separate page 1 | 1 |
| wiki | C1 | Visible wiki | wiki2 | collaborative | Visible page 1 | 2 |
| wiki | C1 | Collaborative wiki empty | wiki3 | collaborative | Collaborative page 1 | |
| wiki | C1 | Individual wiki empty | wiki4 | individual | Individual page 1 | |
And the following wiki pages exist:
| wiki | title | content | group |
| wiki1 | Separate page 1 | Group 1 page | G1 |
@@ -57,16 +59,26 @@ Feature: Testing overview integration in mod_wiki
Scenario: Students can see relevant columns in the wiki overview
Given I am on the "Course 1" "course > activities > wiki" page logged in as "student1"
Then the following should exist in the "Table listing all Wiki activities" table:
| Name | My entries | Total entries |
| Separate wiki | 0 | 0 |
| Visible wiki | 0 | 3 |
| Name | My entries | Total entries |
| Separate wiki | 0 | 0 |
| Visible wiki | 0 | 3 |
| Collaborative wiki empty | 0 | 0 |
| Individual wiki empty | 0 | 0 |
@javascript
Scenario: Teachers can see relevant columns in the wiki overview
Given I am on the "Course 1" "course > activities > wiki" page logged in as "teacher1"
When I am on the "Course 1" "course > activities > wiki" page logged in as "teacher1"
Then the following should exist in the "Table listing all Wiki activities" table:
| Name | Wiki mode | Entries | Actions |
| Separate wiki | Collaborative wiki | 3 | View |
| Visible wiki | Collaborative wiki | 3 | View |
| Name | Wiki mode | Entries | Actions |
| Separate wiki | Collaborative wiki | 3 | View |
| Visible wiki | Collaborative wiki | 3 | View |
| Collaborative wiki empty | Collaborative wiki | 0 | View |
| Individual wiki empty | Individual wiki | 0 | View |
And I click on "View" "link" in the "Separate wiki" "table_row"
And I should see "Page list"
And I am on the "Course 1" "course > activities > wiki" page
And I click on "View" "link" in the "Collaborative wiki empty" "table_row"
And I should not see "Page list"
Scenario: The wiki index redirect to the activities overview
When I log in as "admin"
@@ -77,3 +89,4 @@ Feature: Testing overview integration in mod_wiki
And I should see "Name" in the "wiki_overview_collapsible" "region"
And I should see "Wiki mode" in the "wiki_overview_collapsible" "region"
And I should see "Entries" in the "wiki_overview_collapsible" "region"
And I should see "Actions" in the "wiki_overview_collapsible" "region"
@@ -16,9 +16,8 @@
namespace mod_wiki\courseformat;
use core_courseformat\local\overview\overviewfactory;
use mod_wiki\wiki_mode;
use ReflectionClass;
use core_courseformat\local\overview\overviewfactory;
/**
* Tests for Wiki integration.
@@ -31,7 +30,6 @@ use ReflectionClass;
*/
final class overview_test extends \advanced_testcase {
/**
* Data provider for wiki modes.
*
@@ -249,11 +247,14 @@ final class overview_test extends \advanced_testcase {
[
'users' => $users,
'instance' => $instance,
'instance' => $instancecol,
'course' => $course
] = $this->setup_users_and_activity(SEPARATEGROUPS);
] = $this->setup_users_and_activity(
groupmode: SEPARATEGROUPS, // Use separate groups to initialise pages too.
mode: wiki_mode::COLLABORATIVE->value,
);
$notinitinstance = $this->getDataGenerator()->create_module(
$instanceind = $this->getDataGenerator()->create_module(
'wiki',
[
'course' => $course,
@@ -263,17 +264,16 @@ final class overview_test extends \advanced_testcase {
$this->setUser($users['t1']->id);
$cm = get_fast_modinfo($course)->get_cm($instance->cmid);
$emptycm = get_fast_modinfo($course)->get_cm($notinitinstance->cmid);
$overview = overviewfactory::create($cm);
$cmcol = get_fast_modinfo($course)->get_cm($instancecol->cmid);
$overview = overviewfactory::create($cmcol);
$item = $overview->get_actions_overview();
$this->assertNotNull($item);
$this->assertStringContainsString('wiki/map.php', $item->get_content()->url->out(false));
$overview = overviewfactory::create($emptycm);
// Test the individual wiki instance, which is also empty, has actions.
$cmind = get_fast_modinfo($course)->get_cm($instanceind->cmid);
$overview = overviewfactory::create($cmind);
$item = $overview->get_actions_overview();
$this->assertNull($item);
$this->assertStringContainsString('wiki/view.php', $item->get_content()->url->out(false));
}
}