Add more test cases to the transformEmptyValuesToNull() test

refs #2751
This commit is contained in:
Eric Lippmann 2017-11-09 09:10:57 +01:00
parent 9ed5685849
commit f0ad3d5188
1 changed files with 63 additions and 24 deletions

View File

@ -11,42 +11,81 @@ class ConfigFormTest extends BaseTestCase
public function testWhetherTransformEmptyValuesToNullHandlesValuesCorrectly() public function testWhetherTransformEmptyValuesToNullHandlesValuesCorrectly()
{ {
$values = array( $values = array(
'value1' => '', 'empty_string' => '',
'value2' => 'this is a test', 'example_string' => 'this is a test',
'value3' => array(), 'empty_array' => array(),
'value4' => array('Test1', 'Test2'), 'example_array' => array('test1', 'test2'),
'value5' => 0, 'zero_as_int' => 0,
'value6' => 1 'one_as_int' => 1,
); 'zero_as_string' => '0',
'one_as_string' => '1',
'bool_true' => true,
'bool_false' => false,
'null' => null
);
$values = ConfigForm::transformEmptyValuesToNull($values); $values = ConfigForm::transformEmptyValuesToNull($values);
$this->assertNull( $this->assertNull(
$values['value1'], $values['empty_string'],
'ConfigForm::transformEmptyValuesToNull does not handle empty strings correctly' 'ConfigForm::transformEmptyValuesToNull() does not handle empty strings correctly'
); );
$this->assertEquals(
$this->assertSame(
'this is a test', 'this is a test',
$values['value2'], $values['example_string'],
'ConfigForm::transformEmptyValuesToNull does not handle strings correctly' 'ConfigForm::transformEmptyValuesToNull() does not handle strings correctly'
); );
$this->assertNull( $this->assertNull(
$values['value3'], $values['empty_array'],
'ConfigForm::transformEmptyValuesToNull does not handle empty arrays correctly' 'ConfigForm::transformEmptyValuesToNull() does not handle empty arrays correctly'
); );
$this->assertEquals(
'Test1', $this->assertSame(
$values['value4'][0], 'test1',
'ConfigForm::transformEmptyValuesToNull does not handle arrays correctly' $values['example_array'][0],
'ConfigForm::transformEmptyValuesToNull() does not handle arrays correctly'
); );
$this->assertEquals(
$this->assertSame(
0, 0,
$values['value5'], $values['zero_as_int'],
'ConfigForm::transformEmptyValuesToNull does not handle zeros correctly' 'ConfigForm::transformEmptyValuesToNull() does not handle zeros correctly'
); );
$this->assertEquals(
$this->assertSame(
1, 1,
$values['value6'], $values['one_as_int'],
'ConfigForm::transformEmptyValuesToNull does not handle numbers correctly' 'ConfigForm::transformEmptyValuesToNull() does not handle numbers correctly'
);
$this->assertSame(
'0',
$values['zero_as_string'],
'ConfigForm::transformEmptyValuesToNull() does not handle zeros correctly'
);
$this->assertSame(
'1',
$values['one_as_string'],
'ConfigForm::transformEmptyValuesToNull() does not handle numbers correctly'
);
$this->assertSame(
true,
$values['bool_true'],
'ConfigForm::transformEmptyValuesToNull() does not handle bool true correctly'
);
$this->assertNull(
$values['bool_false'],
'ConfigForm::transformEmptyValuesToNull() does not handle bool false correctly'
);
$this->assertNull(
$values['null'],
'ConfigForm::transformEmptyValuesToNull() does not handle null correctly'
); );
} }
} }