[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/glossary/tests/ -> generator_test.php (source)

   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_glossary generator tests
  19   *
  20   * @package    mod_glossary
  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_glossary.
  28   *
  29   * @package    mod_glossary
  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_glossary_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('glossary', array('course' => $course->id)));
  44          $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
  45          $records = $DB->get_records('glossary', array('course' => $course->id), 'id');
  46          $this->assertCount(1, $records);
  47          $this->assertTrue(array_key_exists($glossary->id, $records));
  48  
  49          $params = array('course' => $course->id, 'name' => 'Another glossary');
  50          $glossary = $this->getDataGenerator()->create_module('glossary', $params);
  51          $records = $DB->get_records('glossary', array('course' => $course->id), 'id');
  52          $this->assertCount(2, $records);
  53          $this->assertEquals('Another glossary', $records[$glossary->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          $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course));
  63          /** @var mod_glossary_generator $glossarygenerator */
  64          $glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
  65  
  66          $entry1 = $glossarygenerator->create_content($glossary);
  67          $entry2 = $glossarygenerator->create_content($glossary, array('concept' => 'Custom concept'), array('alias1', 'alias2'));
  68          $records = $DB->get_records('glossary_entries', array('glossaryid' => $glossary->id), 'id');
  69          $this->assertCount(2, $records);
  70          $this->assertEquals($entry1->id, $records[$entry1->id]->id);
  71          $this->assertEquals($entry2->id, $records[$entry2->id]->id);
  72          $this->assertEquals('Custom concept', $records[$entry2->id]->concept);
  73          $aliases = $DB->get_records_menu('glossary_alias', array('entryid' => $entry2->id), 'id ASC', 'id, alias');
  74          $this->assertSame(array('alias1', 'alias2'), array_values($aliases));
  75  
  76          // Test adding of category to entry.
  77          $categories = $DB->get_records('glossary_categories', array('glossaryid' => $glossary->id));
  78          $this->assertCount(0, $categories);
  79          $entry3 = $glossarygenerator->create_content($glossary, array('concept' => 'In category'));
  80          $category1 = $glossarygenerator->create_category($glossary, array());
  81          $categories = $DB->get_records('glossary_categories', array('glossaryid' => $glossary->id));
  82          $this->assertCount(1, $categories);
  83          $category2 = $glossarygenerator->create_category($glossary, array('name' => 'Some category'), array($entry2, $entry3));
  84          $categories = $DB->get_records('glossary_categories', array('glossaryid' => $glossary->id));
  85          $this->assertCount(2, $categories);
  86          $members = $DB->get_records_menu('glossary_entries_categories', array('categoryid' => $category2->id), 'id ASC', 'id, entryid');
  87          $this->assertSame(array($entry2->id, $entry3->id), array_values($members));
  88      }
  89  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1