MDL-32960 put phpunit integration tests to one test suite and execute them first
[moodle.git] / lib / phpunit / tests / generator_test.php
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/>.
17 /**
18  * PHPUnit integration tests
19  *
20  * @package    core
21  * @category   phpunit
22  * @copyright  2012 Petr Skoda {@link http://skodak.org}
23  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24  */
26 defined('MOODLE_INTERNAL') || die();
29 /**
30  * Test data generator
31  *
32  * @package    core
33  * @category   phpunit
34  * @copyright  2012 Petr Skoda {@link http://skodak.org}
35  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36  */
37 class core_phpunit_generator_testcase extends advanced_testcase {
38     public function test_create() {
39         global $DB;
41         $this->resetAfterTest(true);
42         $generator = $this->getDataGenerator();
44         $count = $DB->count_records('user');
45         $user = $generator->create_user();
46         $this->assertEquals($count+1, $DB->count_records('user'));
48         $count = $DB->count_records('course_categories');
49         $category = $generator->create_category();
50         $this->assertEquals($count+1, $DB->count_records('course_categories'));
52         $count = $DB->count_records('course');
53         $course = $generator->create_course();
54         $this->assertEquals($count+1, $DB->count_records('course'));
56         $section = $generator->create_course_section(array('course'=>$course->id, 'section'=>3));
57         $this->assertEquals($course->id, $section->course);
59         $scale = $generator->create_scale();
60         $this->assertNotEmpty($scale);
61     }
63     public function test_create_module() {
64         global $CFG, $SITE;
65         if (!file_exists("$CFG->dirroot/mod/page/")) {
66             $this->markTestSkipped('Can not find standard Page module');
67         }
69         $this->resetAfterTest(true);
70         $generator = $this->getDataGenerator();
72         $page = $generator->create_module('page', array('course'=>$SITE->id));
73         $this->assertNotEmpty($page);
74     }
76     public function test_create_block() {
77         global $CFG;
78         if (!file_exists("$CFG->dirroot/blocks/online_users/")) {
79             $this->markTestSkipped('Can not find standard Online users block');
80         }
82         $this->resetAfterTest(true);
83         $generator = $this->getDataGenerator();
85         $page = $generator->create_block('online_users');
86         $this->assertNotEmpty($page);
87     }
88 }