Orphaned activities (section 1)
';
-
- $this->assertEquals($thevalue, $theclass);
- }
-
- public function test_section_hidden() {
- $section = $this->courseformat->get_section(1);
- $theclass = self::call_method($this->outputus, 'section_hidden',
- array($section, null));
- $thevalue = '
';
- $thevalue .= '1
Topic
1
';
- $thevalue .= 'Not available
';
-
- $this->assertEquals($thevalue, $theclass);
- }
-
- public function test_print_multiple_section_page() {
- self::call_method($this->outputus, 'print_multiple_section_page',
- array($this->course, null, null, null, null, null));
- $theoutput = '
Section
';
- $this->expectOutputString($theoutput);
- }
-
- public function test_toggle_all() {
- $theclass = self::call_method($this->outputus, 'toggle_all', array());
- $thevalue = '
assertEquals($thevalue, $theclass);
- }
-
- public function test_display_instructions() {
- $theclass = self::call_method($this->outputus, 'display_instructions', array());
- $thevalue = '
';
- $thevalue .= '
';
- $thevalue .= '
';
- $thevalue .= '
Instructions: Clicking on the section ';
- $thevalue .= 'name will show / hide the section.
';
-
- $this->assertEquals($thevalue, $theclass);
- }
+.
+
+/**
+ * Collapsed Topics course format.
+ *
+ * @package course/format
+ * @subpackage topcoll
+ * @version See the value of '$plugin->version' in below.
+ * @copyright © 2015-onwards G J Barnard in respect to modifications of standard topics format.
+ * @author G J Barnard - gjbarnard at gmail dot com, {@link http://about.me/gjbarnard} and
+ * {@link http://moodle.org/user/profile.php?id=442195}
+ * @link http://docs.moodle.org/en/Collapsed_Topics_course_format
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ */
+
+/**
+ * Renderer unit tests for the Collapsed Topics course format.
+ * @group format_topcoll
+ */
+class format_topcoll_courseformatrenderer_testcase extends advanced_testcase {
+
+ protected $outputus;
+ protected $course;
+ protected $courseformat;
+
+ /**
+ * Call protected and private methods for the purpose of testing.
+ *
+ * @param stdClass $obj The object.
+ * @param string $name Name of the method.
+ * @param array $args Array of arguments if any, like Monty Python could be no minutes, ten, or even thirty.
+ * @return any What the method returns if anything, go, go on, look at the specification, you know you want to.
+ */
+ protected static function call_method($obj, $name, array $args) {
+ // Ref: http://stackoverflow.com/questions/249664/best-practices-to-test-protected-methods-with-phpunit.
+ $class = new \ReflectionClass($obj);
+ $method = $class->getMethod($name);
+ $method->setAccessible(true);
+ return $method->invokeArgs($obj, $args);
+ }
+
+ /**
+ * Set protected and private attributes for the purpose of testing.
+ *
+ * @param stdClass $obj The object.
+ * @param string $name Name of the method.
+ * @param any $value Value to set.
+ */
+ protected static function set_property($obj, $name, $value) {
+ // Ref: http://stackoverflow.com/questions/18558183/phpunit-mockbuilder-set-mock-object-internal-property ish.
+ $class = new \ReflectionClass($obj);
+ $property = $class->getProperty($name);
+ $property->setAccessible(true);
+ $property->setValue($obj, $value);
+ }
+
+ /**
+ * Get protected and private methods for the purpose of testing.
+ *
+ * @param stdClass $obj The object.
+ * @param string $name Name of the method.
+ */
+ protected static function get_property($obj, $name) {
+ // Ref: http://stackoverflow.com/questions/18558183/phpunit-mockbuilder-set-mock-object-internal-property ish.
+ $class = new \ReflectionClass($obj);
+ $property = $class->getProperty($name);
+ $property->setAccessible(true);
+ return $property;
+ }
+
+ protected function setUp() {
+ $this->resetAfterTest(true);
+
+ global $PAGE;
+ $this->outputus = $PAGE->get_renderer('format_topcoll');
+ // Ref: https://docs.moodle.org/dev/Writing_PHPUnit_tests.
+ $this->course = $this->getDataGenerator()->create_course(array('format' => 'topcoll', 'numsections' => 1),
+ array('createsections' => true));
+
+ $this->courseformat = course_get_format($this->course);
+ self::set_property($this->outputus, 'courseformat', $this->courseformat);
+ $target = self::get_property($this->outputus, 'target');
+ $ouroutput = $PAGE->get_renderer('core', null, $target);
+ self::set_property($this->outputus, 'output', $ouroutput);
+ $tcsettings = $this->courseformat->get_settings();
+ self::set_property($this->outputus, 'tcsettings', $tcsettings);
+ }
+
+ public function test_start_section_list() {
+ $theclass = self::call_method($this->outputus, 'start_section_list',
+ array());
+ $thevalue = '
';
+
+ $this->assertEquals($thevalue, $theclass);
+ }
+
+ public function test_start_toggle_section_list() {
+ // With defaults unchanged.
+ $theclass = self::call_method($this->outputus, 'start_toggle_section_list',
+ array());
+ $thevalue = '