Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * mod_wiki generator tests 19 * 20 * @package mod_wiki 21 * @category test 22 * @copyright 2013 Marina Glancy 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 /** 27 * Genarator tests class for mod_wiki. 28 * 29 * @package mod_wiki 30 * @category test 31 * @copyright 2013 Marina Glancy 32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 33 */ 34 class mod_wiki_generator_testcase extends advanced_testcase { 35 36 public function test_create_instance() { 37 global $DB; 38 $this->resetAfterTest(); 39 $this->setAdminUser(); 40 41 $course = $this->getDataGenerator()->create_course(); 42 43 $this->assertFalse($DB->record_exists('wiki', array('course' => $course->id))); 44 $wiki = $this->getDataGenerator()->create_module('wiki', array('course' => $course)); 45 $records = $DB->get_records('wiki', array('course' => $course->id), 'id'); 46 $this->assertEquals(1, count($records)); 47 $this->assertTrue(array_key_exists($wiki->id, $records)); 48 49 $params = array('course' => $course->id, 'name' => 'Another wiki'); 50 $wiki = $this->getDataGenerator()->create_module('wiki', $params); 51 $records = $DB->get_records('wiki', array('course' => $course->id), 'id'); 52 $this->assertEquals(2, count($records)); 53 $this->assertEquals('Another wiki', $records[$wiki->id]->name); 54 } 55 56 public function test_create_content() { 57 global $DB; 58 $this->resetAfterTest(); 59 $this->setAdminUser(); 60 61 $course = $this->getDataGenerator()->create_course(); 62 $wiki = $this->getDataGenerator()->create_module('wiki', array('course' => $course)); 63 $wikigenerator = $this->getDataGenerator()->get_plugin_generator('mod_wiki'); 64 65 $page1 = $wikigenerator->create_first_page($wiki); 66 $page2 = $wikigenerator->create_content($wiki); 67 $page3 = $wikigenerator->create_content($wiki, array('title' => 'Custom title', 'tags' => array('Cats', 'mice'))); 68 unset($wiki->cmid); 69 $page4 = $wikigenerator->create_content($wiki, array('tags' => 'Cats, dogs')); 70 $subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id), 'id'); 71 $this->assertEquals(1, count($subwikis)); 72 $subwikiid = key($subwikis); 73 $records = $DB->get_records('wiki_pages', array('subwikiid' => $subwikiid), 'id'); 74 $this->assertEquals(4, count($records)); 75 $this->assertEquals($page1->id, $records[$page1->id]->id); 76 $this->assertEquals($page2->id, $records[$page2->id]->id); 77 $this->assertEquals($page3->id, $records[$page3->id]->id); 78 $this->assertEquals('Custom title', $records[$page3->id]->title); 79 $this->assertEquals(array('Cats', 'mice'), 80 array_values(core_tag_tag::get_item_tags_array('mod_wiki', 'wiki_pages', $page3->id))); 81 $this->assertEquals(array('Cats', 'dogs'), 82 array_values(core_tag_tag::get_item_tags_array('mod_wiki', 'wiki_pages', $page4->id))); 83 } 84 85 public function test_create_content_individual() { 86 global $DB; 87 $this->resetAfterTest(); 88 $this->setAdminUser(); 89 90 $course = $this->getDataGenerator()->create_course(); 91 $wiki = $this->getDataGenerator()->create_module('wiki', 92 array('course' => $course, 'wikimode' => 'individual')); 93 $wikigenerator = $this->getDataGenerator()->get_plugin_generator('mod_wiki'); 94 95 $page1 = $wikigenerator->create_first_page($wiki); 96 $page2 = $wikigenerator->create_content($wiki); 97 $page3 = $wikigenerator->create_content($wiki, array('title' => 'Custom title for admin')); 98 $subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id), 'id'); 99 $this->assertEquals(1, count($subwikis)); 100 $subwikiid = key($subwikis); 101 $records = $DB->get_records('wiki_pages', array('subwikiid' => $subwikiid), 'id'); 102 $this->assertEquals(3, count($records)); 103 $this->assertEquals($page1->id, $records[$page1->id]->id); 104 $this->assertEquals($page2->id, $records[$page2->id]->id); 105 $this->assertEquals($page3->id, $records[$page3->id]->id); 106 $this->assertEquals('Custom title for admin', $records[$page3->id]->title); 107 108 $user = $this->getDataGenerator()->create_user(); 109 $role = $DB->get_record('role', array('shortname' => 'student')); 110 $this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id); 111 $this->setUser($user); 112 113 $page1s = $wikigenerator->create_first_page($wiki); 114 $page2s = $wikigenerator->create_content($wiki); 115 $page3s = $wikigenerator->create_content($wiki, array('title' => 'Custom title for student')); 116 $subwikis = $DB->get_records('wiki_subwikis', array('wikiid' => $wiki->id), 'id'); 117 $this->assertEquals(2, count($subwikis)); 118 next($subwikis); 119 $subwikiid = key($subwikis); 120 $records = $DB->get_records('wiki_pages', array('subwikiid' => $subwikiid), 'id'); 121 $this->assertEquals(3, count($records)); 122 $this->assertEquals($page1s->id, $records[$page1s->id]->id); 123 $this->assertEquals($page2s->id, $records[$page2s->id]->id); 124 $this->assertEquals($page3s->id, $records[$page3s->id]->id); 125 $this->assertEquals('Custom title for student', $records[$page3s->id]->title); 126 } 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body