MDL-67673 phpunit: Move tests to use new phpunit_dataset

- Make advanced_testcase old methods to use new ones internally.
- Fix advanced_testcase, statslib, mod/quiz and mod/data tests.

Originally MDL-64600
This commit is contained in:
Eloy Lafuente (stronk7)
2020-10-21 12:46:00 +02:00
parent ed103545dd
commit 8183def69e
7 changed files with 139 additions and 126 deletions
+37 -18
View 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);
$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);
$dataset = $this->createCsvDataSet(array('user'=>__DIR__.'/fixtures/sample_dataset.csv'));
}
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', '[email protected]'),
),
);
$this->assertFalse($DB->record_exists('user', array('email' => '[email protected]')));
$this->assertFalse($DB->record_exists('user', array('email' => '[email protected]')));
$dataset = $this->createArrayDataSet($data);
$this->loadDataSet($dataset);
$this->assertTrue($DB->record_exists('user', array('email'=>'[email protected]')));
$this->assertTrue($DB->record_exists('user', array('email'=>'[email protected]')));
$this->assertTrue($DB->record_exists('user', array('email' => '[email protected]')));
$this->assertTrue($DB->record_exists('user', array('email' => '[email protected]')));
$data = array(
'user' => array(
array('username'=>'noidea', 'email'=>'[email protected]'),
array('username'=>'onemore', 'email'=>'[email protected]'),
array('username' => 'noidea', 'email' => '[email protected]'),
array('username' => 'onemore', 'email' => '[email protected]'),
),
);
$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() {