mirror of
https://github.com/moodle/moodle.git
synced 2025-04-14 13:02:07 +02:00
MDL-57412 course: Unit test get_view_url for course formats
This commit is contained in:
parent
1832b68142
commit
52fe3c4683
@ -224,4 +224,41 @@ class format_topics_testcase extends advanced_testcase {
|
||||
$this->assertEquals($enddate, $weeksformat->get_default_course_enddate($courseform->get_quick_form()));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_view_url() to ensure that the url is only given for the correct cases
|
||||
*/
|
||||
public function test_get_view_url() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$linkcoursesections = $CFG->linkcoursesections;
|
||||
|
||||
// Generate a course with two sections (0 and 1) and two modules.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course1 = $generator->create_course(array('format' => 'topics'));
|
||||
course_create_sections_if_missing($course1, array(0, 1));
|
||||
|
||||
$data = (object)['id' => $course1->id];
|
||||
$format = course_get_format($course1);
|
||||
$format->update_course_format_options($data);
|
||||
|
||||
// In page.
|
||||
$CFG->linkcoursesections = 0;
|
||||
$this->assertNotEmpty($format->get_view_url(null));
|
||||
$this->assertNotEmpty($format->get_view_url(0));
|
||||
$this->assertNotEmpty($format->get_view_url(1));
|
||||
$CFG->linkcoursesections = 1;
|
||||
$this->assertNotEmpty($format->get_view_url(null));
|
||||
$this->assertNotEmpty($format->get_view_url(0));
|
||||
$this->assertNotEmpty($format->get_view_url(1));
|
||||
|
||||
// Navigation.
|
||||
$CFG->linkcoursesections = 0;
|
||||
$this->assertNull($format->get_view_url(1, ['navigation' => 1]));
|
||||
$this->assertNull($format->get_view_url(0, ['navigation' => 1]));
|
||||
$CFG->linkcoursesections = 1;
|
||||
$this->assertNotEmpty($format->get_view_url(1, ['navigation' => 1]));
|
||||
$this->assertNotEmpty($format->get_view_url(0, ['navigation' => 1]));
|
||||
}
|
||||
}
|
||||
|
@ -232,4 +232,41 @@ class format_weeks_testcase extends advanced_testcase {
|
||||
$this->assertEquals($enddate, $weeksformat->get_default_course_enddate($courseform->get_quick_form()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_view_url() to ensure that the url is only given for the correct cases
|
||||
*/
|
||||
public function test_get_view_url() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$linkcoursesections = $CFG->linkcoursesections;
|
||||
|
||||
// Generate a course with two sections (0 and 1) and two modules.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course1 = $generator->create_course(array('format' => 'weeks'));
|
||||
course_create_sections_if_missing($course1, array(0, 1));
|
||||
|
||||
$data = (object)['id' => $course1->id];
|
||||
$format = course_get_format($course1);
|
||||
$format->update_course_format_options($data);
|
||||
|
||||
// In page.
|
||||
$CFG->linkcoursesections = 0;
|
||||
$this->assertNotEmpty($format->get_view_url(null));
|
||||
$this->assertNotEmpty($format->get_view_url(0));
|
||||
$this->assertNotEmpty($format->get_view_url(1));
|
||||
$CFG->linkcoursesections = 1;
|
||||
$this->assertNotEmpty($format->get_view_url(null));
|
||||
$this->assertNotEmpty($format->get_view_url(0));
|
||||
$this->assertNotEmpty($format->get_view_url(1));
|
||||
|
||||
// Navigation.
|
||||
$CFG->linkcoursesections = 0;
|
||||
$this->assertNull($format->get_view_url(1, ['navigation' => 1]));
|
||||
$this->assertNull($format->get_view_url(0, ['navigation' => 1]));
|
||||
$CFG->linkcoursesections = 1;
|
||||
$this->assertNotEmpty($format->get_view_url(1, ['navigation' => 1]));
|
||||
$this->assertNotEmpty($format->get_view_url(0, ['navigation' => 1]));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -162,6 +162,44 @@ class core_course_courseformat_testcase extends advanced_testcase {
|
||||
$format = course_get_format((object)['format' => 'testlegacy']);
|
||||
$this->assertTrue($format->supports_news());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for get_view_url() to ensure that the url is only given for the correct cases
|
||||
*/
|
||||
public function test_get_view_url() {
|
||||
global $CFG;
|
||||
$this->resetAfterTest();
|
||||
|
||||
$linkcoursesections = $CFG->linkcoursesections;
|
||||
|
||||
// Generate a course with two sections (0 and 1) and two modules. Course format is set to 'testformat'.
|
||||
// This will allow us to test the default implementation of get_view_url.
|
||||
$generator = $this->getDataGenerator();
|
||||
$course1 = $generator->create_course(array('format' => 'testformat'));
|
||||
course_create_sections_if_missing($course1, array(0, 1));
|
||||
|
||||
$data = (object)['id' => $course1->id];
|
||||
$format = course_get_format($course1);
|
||||
$format->update_course_format_options($data);
|
||||
|
||||
// In page.
|
||||
$CFG->linkcoursesections = 0;
|
||||
$this->assertNotEmpty($format->get_view_url(null));
|
||||
$this->assertNotEmpty($format->get_view_url(0));
|
||||
$this->assertNotEmpty($format->get_view_url(1));
|
||||
$CFG->linkcoursesections = 1;
|
||||
$this->assertNotEmpty($format->get_view_url(null));
|
||||
$this->assertNotEmpty($format->get_view_url(0));
|
||||
$this->assertNotEmpty($format->get_view_url(1));
|
||||
|
||||
// Navigation.
|
||||
$CFG->linkcoursesections = 0;
|
||||
$this->assertNull($format->get_view_url(1, ['navigation' => 1]));
|
||||
$this->assertNull($format->get_view_url(0, ['navigation' => 1]));
|
||||
$CFG->linkcoursesections = 1;
|
||||
$this->assertNotEmpty($format->get_view_url(1, ['navigation' => 1]));
|
||||
$this->assertNotEmpty($format->get_view_url(0, ['navigation' => 1]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user