MDL-24863 unit tests - tidy up a bit some tests

This commit is contained in:
Eloy Lafuente 2010-11-18 14:02:02 +00:00
parent 3b8b116ec3
commit 39cf0e8e74

View file

@ -699,13 +699,10 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext' => '1'); $conditions = array('onetext' => '1');
try { try {
$rs = $DB->get_recordset($tablename, $conditions); $rs = $DB->get_recordset($tablename, $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
// notes: // notes:
@ -959,13 +956,10 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext' => '1'); $conditions = array('onetext' => '1');
try { try {
$records = $DB->get_records($tablename, $conditions); $records = $DB->get_records($tablename, $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
// note: delegate limits testing to test_get_records_sql() // note: delegate limits testing to test_get_records_sql()
@ -1310,13 +1304,10 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext' => '1'); $conditions = array('onetext' => '1');
try { try {
$DB->get_field($tablename, 'course', $conditions); $DB->get_field($tablename, 'course', $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
} }
@ -2108,13 +2099,10 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext' => '1'); $conditions = array('onetext' => '1');
try { try {
$DB->set_field($tablename, 'onechar', 'frog', $conditions); $DB->set_field($tablename, 'onechar', 'frog', $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
// Note: All the nulls, booleans, empties, quoted and backslashes tests // Note: All the nulls, booleans, empties, quoted and backslashes tests
@ -2291,13 +2279,10 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext' => '1'); $conditions = array('onetext' => '1');
try { try {
$DB->count_records($tablename, $conditions); $DB->count_records($tablename, $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
} }
@ -2369,13 +2354,10 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext' => '1'); $conditions = array('onetext' => '1');
try { try {
$DB->record_exists($tablename, $conditions); $DB->record_exists($tablename, $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
} }
@ -2456,26 +2438,20 @@ class dml_test extends UnitTestCase {
$conditions = array('onetext'=>'1'); $conditions = array('onetext'=>'1');
try { try {
$DB->delete_records($tablename, $conditions); $DB->delete_records($tablename, $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
// test for exception throwing on text conditions being compared. (MDL-24863, unwanted auto conversion of param to int) // test for exception throwing on text conditions being compared. (MDL-24863, unwanted auto conversion of param to int)
$conditions = array('onetext' => 1); $conditions = array('onetext' => 1);
try { try {
$DB->delete_records($tablename, $conditions); $DB->delete_records($tablename, $conditions);
$this->assertFalse(true, 'An Exception is missing, expected due to equating of text fields'); $this->fail('An Exception is missing, expected due to equating of text fields');
} catch (dml_exception $e) { } catch (exception $e) {
if ($e->errorcode == 'textconditionsnotallowed') { $this->assertTrue($e instanceof dml_exception);
$this->assertTrue(true, 'The Expected exception was caught.'); $this->assertEqual($e->errorcode, 'textconditionsnotallowed');
} else {
throw $e;
}
} }
} }