Differences Between: [Versions 310 and 402] [Versions 39 and 402]
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 namespace mod_glossary; 18 19 /** 20 * Genarator tests class for mod_glossary. 21 * 22 * @package mod_glossary 23 * @category test 24 * @copyright 2013 Marina Glancy 25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 26 */ 27 class generator_test extends \advanced_testcase { 28 29 public function test_create_instance() { 30 global $DB; 31 $this->resetAfterTest(); 32 $this->setAdminUser(); 33 34 $course = $this->getDataGenerator()->create_course(); 35 36 $this->assertFalse($DB->record_exists('glossary', array('course' => $course->id))); 37 $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course)); 38 $records = $DB->get_records('glossary', array('course' => $course->id), 'id'); 39 $this->assertCount(1, $records); 40 $this->assertTrue(array_key_exists($glossary->id, $records)); 41 42 $params = array('course' => $course->id, 'name' => 'Another glossary'); 43 $glossary = $this->getDataGenerator()->create_module('glossary', $params); 44 $records = $DB->get_records('glossary', array('course' => $course->id), 'id'); 45 $this->assertCount(2, $records); 46 $this->assertEquals('Another glossary', $records[$glossary->id]->name); 47 } 48 49 public function test_create_content() { 50 global $DB; 51 $this->resetAfterTest(); 52 $this->setAdminUser(); 53 54 $course = $this->getDataGenerator()->create_course(); 55 $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course)); 56 /** @var mod_glossary_generator $glossarygenerator */ 57 $glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary'); 58 59 $entry1 = $glossarygenerator->create_content($glossary); 60 $entry2 = $glossarygenerator->create_content($glossary, 61 array('concept' => 'Custom concept', 'tags' => array('Cats', 'mice')), array('alias1', 'alias2')); 62 $records = $DB->get_records('glossary_entries', array('glossaryid' => $glossary->id), 'id'); 63 $this->assertCount(2, $records); 64 $this->assertEquals($entry1->id, $records[$entry1->id]->id); 65 $this->assertEquals($entry2->id, $records[$entry2->id]->id); 66 $this->assertEquals('Custom concept', $records[$entry2->id]->concept); 67 $this->assertEquals(array('Cats', 'mice'), 68 array_values(\core_tag_tag::get_item_tags_array('mod_glossary', 'glossary_entries', $entry2->id))); 69 $aliases = $DB->get_records_menu('glossary_alias', array('entryid' => $entry2->id), 'id ASC', 'id, alias'); 70 $this->assertSame(array('alias1', 'alias2'), array_values($aliases)); 71 72 // Test adding of category to entry. 73 $categories = $DB->get_records('glossary_categories', array('glossaryid' => $glossary->id)); 74 $this->assertCount(0, $categories); 75 $entry3 = $glossarygenerator->create_content($glossary, array('concept' => 'In category')); 76 $category1 = $glossarygenerator->create_category($glossary, array()); 77 $categories = $DB->get_records('glossary_categories', array('glossaryid' => $glossary->id)); 78 $this->assertCount(1, $categories); 79 $category2 = $glossarygenerator->create_category($glossary, array('name' => 'Some category'), array($entry2, $entry3)); 80 $categories = $DB->get_records('glossary_categories', array('glossaryid' => $glossary->id)); 81 $this->assertCount(2, $categories); 82 $members = $DB->get_records_menu('glossary_entries_categories', array('categoryid' => $category2->id), 'id ASC', 'id, entryid'); 83 $this->assertSame(array($entry2->id, $entry3->id), array_values($members)); 84 } 85 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body