MDL-67673 phpunit: Move tests to use new phpunit_dataset
[moodle.git] / lib / phpunit / tests / advanced_test.php
index 5cef89d..9a60a82 100644 (file)
@@ -318,26 +318,42 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
         $this->assertFalse($DB->get_record('user', array('id'=>9999)));
     }
 
-    public function test_load_dataset() {
+    public function test_load_data_dataset_xml() {
         global $DB;
 
         $this->resetAfterTest();
 
-        $this->assertFalse($DB->record_exists('user', array('id'=>5)));
-        $this->assertFalse($DB->record_exists('user', array('id'=>7)));
+        $this->assertFalse($DB->record_exists('user', array('id' => 5)));
+        $this->assertFalse($DB->record_exists('user', array('id' => 7)));
         $dataset = $this->createXMLDataSet(__DIR__.'/fixtures/sample_dataset.xml');
         $this->loadDataSet($dataset);
-        $this->assertTrue($DB->record_exists('user', array('id'=>5)));
-        $this->assertTrue($DB->record_exists('user', array('id'=>7)));
-        $user5 = $DB->get_record('user', array('id'=>5));
-        $user7 = $DB->get_record('user', array('id'=>7));
-        $this->assertSame('john.doe', $user5->username);
-        $this->assertSame('jane.doe', $user7->username);
-
-        $dataset = $this->createCsvDataSet(array('user'=>__DIR__.'/fixtures/sample_dataset.csv'));
+        $this->assertTrue($DB->record_exists('user', array('id' => 5)));
+        $this->assertTrue($DB->record_exists('user', array('id' => 7)));
+        $user5 = $DB->get_record('user', array('id' => 5));
+        $user7 = $DB->get_record('user', array('id' => 7));
+        $this->assertSame('bozka.novakova', $user5->username);
+        $this->assertSame('pepa.novak', $user7->username);
+
+    }
+
+    public function test_load_dataset_csv() {
+        global $DB;
+
+        $this->resetAfterTest();
+
+        $this->assertFalse($DB->record_exists('user', array('id' => 8)));
+        $this->assertFalse($DB->record_exists('user', array('id' => 9)));
+        $dataset = $this->createCsvDataSet(array('user' => __DIR__.'/fixtures/sample_dataset.csv'));
         $this->loadDataSet($dataset);
-        $this->assertEquals(8, $DB->get_field('user', 'id', array('username'=>'pepa.novak')));
-        $this->assertEquals(9, $DB->get_field('user', 'id', array('username'=>'bozka.novakova')));
+        $this->assertEquals(5, $DB->get_field('user', 'id', array('username' => 'bozka.novakova')));
+        $this->assertEquals(7, $DB->get_field('user', 'id', array('username' => 'pepa.novak')));
+
+    }
+
+    public function test_load_dataset_array() {
+        global $DB;
+
+        $this->resetAfterTest();
 
         $data = array(
             'user' => array(
@@ -346,21 +362,24 @@ class core_phpunit_advanced_testcase extends advanced_testcase {
                 array('low.secret', 'low@example.com'),
             ),
         );
+
+        $this->assertFalse($DB->record_exists('user', array('email' => 'top@example.com')));
+        $this->assertFalse($DB->record_exists('user', array('email' => 'low@example.com')));
         $dataset = $this->createArrayDataSet($data);
         $this->loadDataSet($dataset);
-        $this->assertTrue($DB->record_exists('user', array('email'=>'top@example.com')));
-        $this->assertTrue($DB->record_exists('user', array('email'=>'low@example.com')));
+        $this->assertTrue($DB->record_exists('user', array('email' => 'top@example.com')));
+        $this->assertTrue($DB->record_exists('user', array('email' => 'low@example.com')));
 
         $data = array(
             'user' => array(
-                array('username'=>'noidea', 'email'=>'noidea@example.com'),
-                array('username'=>'onemore', 'email'=>'onemore@example.com'),
+                array('username' => 'noidea', 'email' => 'noidea@example.com'),
+                array('username' => 'onemore', 'email' => 'onemore@example.com'),
             ),
         );
         $dataset = $this->createArrayDataSet($data);
         $this->loadDataSet($dataset);
-        $this->assertTrue($DB->record_exists('user', array('username'=>'noidea')));
-        $this->assertTrue($DB->record_exists('user', array('username'=>'onemore')));
+        $this->assertTrue($DB->record_exists('user', array('username' => 'noidea')));
+        $this->assertTrue($DB->record_exists('user', array('username' => 'onemore')));
     }
 
     public function test_assert_time_current() {