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() {
// Login as the admin user
$this
->drupalLogin($this->admin_user);
$testsets = array(
'testset',
'testset2',
);
foreach ($testsets as $name) {
// Create a new optionset with default settings
$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.'));
// Save the optionset to the database
$optionset = flexslider_optionset_save($optionset, TRUE);
$this
->assertFalse(FALSE === $optionset, t('Optionset saved to database.'));
// Read the values from the 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,
)));
}
}
// Load all optionsets
$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'));
// Ensure they all loaded correctly
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'));
}
// Update the optionset
$test_options = _flexslider_test_options();
$test_options = $test_options['valid'];
// Load one of the test option sets
$optionset = flexslider_optionset_load($testsets[0]);
// Change the settings
$optionset->options = $test_options['set2'] + $optionset->options;
// Save the updated values
$optionset = flexslider_optionset_save($optionset);
$this
->assertFalse(FALSE == $optionset, t('Saved updates to optionset to database.'));
// Load the values from the database again
$optionset = flexslider_optionset_load($testsets[0]);
// Compare settings to the test options
foreach ($test_options['set2'] as $key => $value) {
$this
->assertEqual($optionset->options[$key], $value, t('Saved value matches set value: @key', array(
'@key' => $key,
)));
}
// Delete the optionset
$this
->assertTrue(flexslider_optionset_exists($optionset->name), t('Optionset exists and is ready to be deleted.'));
flexslider_optionset_delete($optionset->name);
// Ensure the delete is successful
$this
->assertFalse(flexslider_optionset_exists($optionset->name), t('Optionset successfully deleted: @name', array(
'@name' => $optionset->name,
)));
}