MDL-32960 put phpunit integration tests to one test suite and execute them first
authorPetr Skoda <commits@skodak.org>
Sat, 12 May 2012 19:11:53 +0000 (21:11 +0200)
committerPetr Skoda <commits@skodak.org>
Sat, 12 May 2012 19:33:23 +0000 (21:33 +0200)
lib/phpunit/tests/advanced_test.php [moved from lib/tests/phpunit_test.php with 62% similarity]
lib/phpunit/tests/basic_test.php [new file with mode: 0644]
lib/phpunit/tests/fixtures/sample_dataset.csv [moved from lib/tests/fixtures/sample_dataset.csv with 100% similarity]
lib/phpunit/tests/fixtures/sample_dataset.xml [moved from lib/tests/fixtures/sample_dataset.xml with 100% similarity]
lib/phpunit/tests/generator_test.php [new file with mode: 0644]
phpunit.xml.dist

similarity index 62%
rename from lib/tests/phpunit_test.php
rename to lib/phpunit/tests/advanced_test.php
index d24a0d1..e82164d 100644 (file)
@@ -15,7 +15,7 @@
 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
 
 /**
- * PHPUnit integration unit tests
+ * PHPUnit integration tests
  *
  * @package    core
  * @category   phpunit
 defined('MOODLE_INTERNAL') || die();
 
 
-/**
- * Test basic_testcase extra features and PHPUnit Moodle integration.
- *
- * @package    core
- * @category   phpunit
- * @copyright  2012 Petr Skoda {@link http://skodak.org}
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class core_phpunit_basic_testcase extends basic_testcase {
-
-    /**
-     * Tests that bootstrapping has occurred correctly
-     * @return void
-     */
-    public function test_bootstrap() {
-        global $CFG;
-        $this->assertTrue(isset($CFG->httpswwwroot));
-        $this->assertEquals($CFG->httpswwwroot, $CFG->wwwroot);
-        $this->assertEquals($CFG->prefix, $CFG->phpunit_prefix);
-    }
-
-    /**
-     * This is just a verification if I understand the PHPUnit assert docs right --skodak
-     * @return void
-     */
-    public function test_assert_behaviour() {
-        // arrays
-        $a = array('a', 'b', 'c');
-        $b = array('a', 'c', 'b');
-        $c = array('a', 'b', 'c');
-        $d = array('a', 'b', 'C');
-        $this->assertNotEquals($a, $b);
-        $this->assertNotEquals($a, $d);
-        $this->assertEquals($a, $c);
-        $this->assertEquals($a, $b, '', 0, 10, true);
-
-        // objects
-        $a = new stdClass();
-        $a->x = 'x';
-        $a->y = 'y';
-        $b = new stdClass(); // switched order
-        $b->y = 'y';
-        $b->x = 'x';
-        $c = $a;
-        $d = new stdClass();
-        $d->x = 'x';
-        $d->y = 'y';
-        $d->z = 'z';
-        $this->assertEquals($a, $b);
-        $this->assertNotSame($a, $b);
-        $this->assertEquals($a, $c);
-        $this->assertSame($a, $c);
-        $this->assertNotEquals($a, $d);
-
-        // string comparison
-        $this->assertEquals(1, '1');
-        $this->assertEquals(null, '');
-
-        $this->assertNotEquals(1, '1 ');
-        $this->assertNotEquals(0, '');
-        $this->assertNotEquals(null, '0');
-        $this->assertNotEquals(array(), '');
-
-        // other comparison
-        $this->assertEquals(null, null);
-        $this->assertEquals(false, null);
-        $this->assertEquals(0, null);
-
-        // emptiness
-        $this->assertEmpty(0);
-        $this->assertEmpty(0.0);
-        $this->assertEmpty('');
-        $this->assertEmpty('0');
-        $this->assertEmpty(false);
-        $this->assertEmpty(null);
-        $this->assertEmpty(array());
-
-        $this->assertNotEmpty(1);
-        $this->assertNotEmpty(0.1);
-        $this->assertNotEmpty(-1);
-        $this->assertNotEmpty(' ');
-        $this->assertNotEmpty('0 ');
-        $this->assertNotEmpty(true);
-        $this->assertNotEmpty(array(null));
-        $this->assertNotEmpty(new stdClass());
-    }
-
-// Uncomment following tests to see logging of unexpected changes in global state and database
-/*
-    public function test_db_modification() {
-        global $DB;
-        $DB->set_field('user', 'confirmed', 1, array('id'=>-1));
-    }
-
-    public function test_cfg_modification() {
-        global $CFG;
-        $CFG->xx = 'yy';
-        unset($CFG->admin);
-        $CFG->rolesactive = 0;
-    }
-
-    public function test_user_modification() {
-        global $USER;
-        $USER->id = 10;
-    }
-
-    public function test_course_modification() {
-        global $COURSE;
-        $COURSE->id = 10;
-    }
-
-    public function test_all_modifications() {
-        global $DB, $CFG, $USER, $COURSE;
-        $DB->set_field('user', 'confirmed', 1, array('id'=>-1));
-        $CFG->xx = 'yy';
-        unset($CFG->admin);
-        $CFG->rolesactive = 0;
-        $USER->id = 10;
-        $COURSE->id = 10;
-    }
-
-    public function test_transaction_problem() {
-        global $DB;
-        $DB->start_delegated_transaction();
-    }
-*/
-}
-
-
 /**
  * Test advanced_testcase extra features.
  *
@@ -391,65 +262,3 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $this->assertTrue($DB->record_exists('user', array('username'=>'onemore')));
     }
 }
-
-
-/**
- * Test data generator
- *
- * @package    core
- * @category   phpunit
- * @copyright  2012 Petr Skoda {@link http://skodak.org}
- * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-class core_phpunit_generator_testcase extends advanced_testcase {
-    public function test_create() {
-        global $DB;
-
-        $this->resetAfterTest(true);
-        $generator = $this->getDataGenerator();
-
-        $count = $DB->count_records('user');
-        $user = $generator->create_user();
-        $this->assertEquals($count+1, $DB->count_records('user'));
-
-        $count = $DB->count_records('course_categories');
-        $category = $generator->create_category();
-        $this->assertEquals($count+1, $DB->count_records('course_categories'));
-
-        $count = $DB->count_records('course');
-        $course = $generator->create_course();
-        $this->assertEquals($count+1, $DB->count_records('course'));
-
-        $section = $generator->create_course_section(array('course'=>$course->id, 'section'=>3));
-        $this->assertEquals($course->id, $section->course);
-
-        $scale = $generator->create_scale();
-        $this->assertNotEmpty($scale);
-    }
-
-    public function test_create_module() {
-        global $CFG, $SITE;
-        if (!file_exists("$CFG->dirroot/mod/page/")) {
-            $this->markTestSkipped('Can not find standard Page module');
-        }
-
-        $this->resetAfterTest(true);
-        $generator = $this->getDataGenerator();
-
-        $page = $generator->create_module('page', array('course'=>$SITE->id));
-        $this->assertNotEmpty($page);
-    }
-
-    public function test_create_block() {
-        global $CFG;
-        if (!file_exists("$CFG->dirroot/blocks/online_users/")) {
-            $this->markTestSkipped('Can not find standard Online users block');
-        }
-
-        $this->resetAfterTest(true);
-        $generator = $this->getDataGenerator();
-
-        $page = $generator->create_block('online_users');
-        $this->assertNotEmpty($page);
-    }
-}
diff --git a/lib/phpunit/tests/basic_test.php b/lib/phpunit/tests/basic_test.php
new file mode 100644 (file)
index 0000000..2ad03cb
--- /dev/null
@@ -0,0 +1,155 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * PHPUnit integration tests
+ *
+ * @package    core
+ * @category   phpunit
+ * @copyright  2012 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+
+/**
+ * Test basic_testcase extra features and PHPUnit Moodle integration.
+ *
+ * @package    core
+ * @category   phpunit
+ * @copyright  2012 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class core_phpunit_basic_testcase extends basic_testcase {
+
+    /**
+     * Tests that bootstrapping has occurred correctly
+     * @return void
+     */
+    public function test_bootstrap() {
+        global $CFG;
+        $this->assertTrue(isset($CFG->httpswwwroot));
+        $this->assertEquals($CFG->httpswwwroot, $CFG->wwwroot);
+        $this->assertEquals($CFG->prefix, $CFG->phpunit_prefix);
+    }
+
+    /**
+     * This is just a verification if I understand the PHPUnit assert docs right --skodak
+     * @return void
+     */
+    public function test_assert_behaviour() {
+        // arrays
+        $a = array('a', 'b', 'c');
+        $b = array('a', 'c', 'b');
+        $c = array('a', 'b', 'c');
+        $d = array('a', 'b', 'C');
+        $this->assertNotEquals($a, $b);
+        $this->assertNotEquals($a, $d);
+        $this->assertEquals($a, $c);
+        $this->assertEquals($a, $b, '', 0, 10, true);
+
+        // objects
+        $a = new stdClass();
+        $a->x = 'x';
+        $a->y = 'y';
+        $b = new stdClass(); // switched order
+        $b->y = 'y';
+        $b->x = 'x';
+        $c = $a;
+        $d = new stdClass();
+        $d->x = 'x';
+        $d->y = 'y';
+        $d->z = 'z';
+        $this->assertEquals($a, $b);
+        $this->assertNotSame($a, $b);
+        $this->assertEquals($a, $c);
+        $this->assertSame($a, $c);
+        $this->assertNotEquals($a, $d);
+
+        // string comparison
+        $this->assertEquals(1, '1');
+        $this->assertEquals(null, '');
+
+        $this->assertNotEquals(1, '1 ');
+        $this->assertNotEquals(0, '');
+        $this->assertNotEquals(null, '0');
+        $this->assertNotEquals(array(), '');
+
+        // other comparison
+        $this->assertEquals(null, null);
+        $this->assertEquals(false, null);
+        $this->assertEquals(0, null);
+
+        // emptiness
+        $this->assertEmpty(0);
+        $this->assertEmpty(0.0);
+        $this->assertEmpty('');
+        $this->assertEmpty('0');
+        $this->assertEmpty(false);
+        $this->assertEmpty(null);
+        $this->assertEmpty(array());
+
+        $this->assertNotEmpty(1);
+        $this->assertNotEmpty(0.1);
+        $this->assertNotEmpty(-1);
+        $this->assertNotEmpty(' ');
+        $this->assertNotEmpty('0 ');
+        $this->assertNotEmpty(true);
+        $this->assertNotEmpty(array(null));
+        $this->assertNotEmpty(new stdClass());
+    }
+
+// Uncomment following tests to see logging of unexpected changes in global state and database
+    /*
+        public function test_db_modification() {
+            global $DB;
+            $DB->set_field('user', 'confirmed', 1, array('id'=>-1));
+        }
+
+        public function test_cfg_modification() {
+            global $CFG;
+            $CFG->xx = 'yy';
+            unset($CFG->admin);
+            $CFG->rolesactive = 0;
+        }
+
+        public function test_user_modification() {
+            global $USER;
+            $USER->id = 10;
+        }
+
+        public function test_course_modification() {
+            global $COURSE;
+            $COURSE->id = 10;
+        }
+
+        public function test_all_modifications() {
+            global $DB, $CFG, $USER, $COURSE;
+            $DB->set_field('user', 'confirmed', 1, array('id'=>-1));
+            $CFG->xx = 'yy';
+            unset($CFG->admin);
+            $CFG->rolesactive = 0;
+            $USER->id = 10;
+            $COURSE->id = 10;
+        }
+
+        public function test_transaction_problem() {
+            global $DB;
+            $DB->start_delegated_transaction();
+        }
+    */
+}
diff --git a/lib/phpunit/tests/generator_test.php b/lib/phpunit/tests/generator_test.php
new file mode 100644 (file)
index 0000000..eb5df6b
--- /dev/null
@@ -0,0 +1,88 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * PHPUnit integration tests
+ *
+ * @package    core
+ * @category   phpunit
+ * @copyright  2012 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+defined('MOODLE_INTERNAL') || die();
+
+
+/**
+ * Test data generator
+ *
+ * @package    core
+ * @category   phpunit
+ * @copyright  2012 Petr Skoda {@link http://skodak.org}
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class core_phpunit_generator_testcase extends advanced_testcase {
+    public function test_create() {
+        global $DB;
+
+        $this->resetAfterTest(true);
+        $generator = $this->getDataGenerator();
+
+        $count = $DB->count_records('user');
+        $user = $generator->create_user();
+        $this->assertEquals($count+1, $DB->count_records('user'));
+
+        $count = $DB->count_records('course_categories');
+        $category = $generator->create_category();
+        $this->assertEquals($count+1, $DB->count_records('course_categories'));
+
+        $count = $DB->count_records('course');
+        $course = $generator->create_course();
+        $this->assertEquals($count+1, $DB->count_records('course'));
+
+        $section = $generator->create_course_section(array('course'=>$course->id, 'section'=>3));
+        $this->assertEquals($course->id, $section->course);
+
+        $scale = $generator->create_scale();
+        $this->assertNotEmpty($scale);
+    }
+
+    public function test_create_module() {
+        global $CFG, $SITE;
+        if (!file_exists("$CFG->dirroot/mod/page/")) {
+            $this->markTestSkipped('Can not find standard Page module');
+        }
+
+        $this->resetAfterTest(true);
+        $generator = $this->getDataGenerator();
+
+        $page = $generator->create_module('page', array('course'=>$SITE->id));
+        $this->assertNotEmpty($page);
+    }
+
+    public function test_create_block() {
+        global $CFG;
+        if (!file_exists("$CFG->dirroot/blocks/online_users/")) {
+            $this->markTestSkipped('Can not find standard Online users block');
+        }
+
+        $this->resetAfterTest(true);
+        $generator = $this->getDataGenerator();
+
+        $page = $generator->create_block('online_users');
+        $this->assertNotEmpty($page);
+    }
+}
index be46f6b..82bf8fb 100644 (file)
@@ -20,6 +20,9 @@
 <!--All core suites need to be manually added here-->
 
     <testsuites>
+        <testsuite name="core_phpunit">
+            <directory suffix="_test.php">lib/phpunit/tests</directory>
+        </testsuite>
         <testsuite name="core_db">
             <directory suffix="_test.php">lib/ddl/tests</directory>
             <directory suffix="_test.php">lib/dml/tests</directory>