function FlexsliderTestCase::testOptionSetCrud in Flex Slider 7.2
File
- ./flexslider.test, line 51
- Test cases for FlexSlider
Class
- FlexsliderTestCase
- @file
Test cases for FlexSlider
Code
function testOptionSetCrud() {
$this
->drupalLogin($this->admin_user);
$testsets = array(
'testset',
'testset2',
);
foreach ($testsets as $name) {
$optionset = flexslider_optionset_create(array(
'name' => $name,
));
$this
->assertTrue($optionset->name == $name, t('Optionset object created: @name', array(
'@name' => $optionset->name,
)));
$this
->assertFalse(empty($optionset->options), t('Create optionset works.'));
$optionset = flexslider_optionset_save($optionset, TRUE);
$this
->assertFalse(FALSE === $optionset, t('Optionset saved to database.'));
$optionset = flexslider_optionset_load($name);
$this
->assertTrue(is_object($optionset), t('Loaded option set.'));
$this
->assertEqual($name, $optionset->name, t('Loaded name matches: @name', array(
'@name' => $optionset->name,
)));
$default_optionset = flexslider_optionset_create();
foreach ($default_optionset->options as $key => $value) {
$this
->assertEqual($value, $optionset->options[$key], t('Option @option matches saved value.', array(
'@option' => $key,
)));
}
}
$optionsets = flexslider_optionset_load_all();
$this
->assertTrue(is_array($optionsets), t('Array of optionsets loaded'));
$this
->assertTrue(count($optionsets) == 3, t('Proper number of optionsets loaded (two created, one default): 3'));
foreach ($optionsets as $optionset) {
$this
->assertTrue(isset($optionset->name), t('Loaded optionsets have a defined machine name'));
$this
->assertTrue(isset($optionset->title), t('Loaded optionsets have a defined human readable name (title)'));
$this
->assertTrue(isset($optionset->options), t('Loaded optionsets have a defined array of options'));
}
$test_options = _flexslider_test_options();
$test_options = $test_options['valid'];
$optionset = flexslider_optionset_load($testsets[0]);
$optionset->options = $test_options['set2'] + $optionset->options;
$optionset = flexslider_optionset_save($optionset);
$this
->assertFalse(FALSE == $optionset, t('Saved updates to optionset to database.'));
$optionset = flexslider_optionset_load($testsets[0]);
foreach ($test_options['set2'] as $key => $value) {
$this
->assertEqual($optionset->options[$key], $value, t('Saved value matches set value: @key', array(
'@key' => $key,
)));
}
$this
->assertTrue(flexslider_optionset_exists($optionset->name), t('Optionset exists and is ready to be deleted.'));
flexslider_optionset_delete($optionset->name);
$this
->assertFalse(flexslider_optionset_exists($optionset->name), t('Optionset successfully deleted: @name', array(
'@name' => $optionset->name,
)));
}