Skip to content

Instantly share code, notes, and snippets.

@damiankloip
Created April 30, 2012 15:37
Show Gist options
  • Save damiankloip/2559388 to your computer and use it in GitHub Desktop.
Save damiankloip/2559388 to your computer and use it in GitHub Desktop.
<?php
/**
* @file
* Tests different parts of the ctools export system.
*/
/**
* Tests export crud.
*/
class CtoolsExportCrudTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Ctools export crud test',
'description' => 'Test the crud functionality for the ctools export system.',
'group' => 'Chaos Tools Suite',
);
}
protected function setUp() {
parent::setUp('ctools_export_test');
$this->resetAll();
}
/**
* Tests the crud operation: load.
*/
function testCrudLoad() {
$loaded_export = ctools_export_crud_load('ctools_export_test', 'export_0');
$expected_export = new stdClass();
$expected_export->machine = 'export_0';
$expected_export->title = 'Export 0';
$expected_export->number = 0;
$expected_export->data = array(
'test_1' => 'Test 1',
'test_2' => 'Test 2',
);
$expected_export->table = 'ctools_export_test';
$expected_export->export_type = 1;
$expected_export->type = 'Normal';
$this->assertEqual($expected_export, $loaded_export, 'Make sure that an exportable object has been loaded correctly from the database.');
}
/**
* Tests the crud operation: load.
*/
function testCrudSave() {
$default_export = ctools_export_crud_load('ctools_export_test', 'export_2');
$this->assertTrue($default_export->in_code_only,'Make sure the loaded exportable is in code only.');
ctools_export_crud_save('ctools_export_test', $default_export);
// Clear the static cache.
ctools_export_load_object_reset('ctools_export_test');
$overridden_export = ctools_export_crud_load('ctools_export_test', 'export_2');
$this->assertTrue($overridden_export->export_type === 3, 'Make sure the loaded exportable is overridden in the database.');
}
/**
* Tests the crud operation: new.
*/
function testCrudNew() {
$new_export = ctools_export_crud_new('ctools_export_test');
$expected_export = new stdClass();
$expected_export->machine = '';
$expected_export->title = '';
$expected_export->number = NULL;
$expected_export->data = NULL;
$expected_export->export_type = NULL;
$expected_export->type = 'Local';
$this->assertEqual($expected_export, $new_export, 'Make sure that an export object with default values is created.');
$new_export = ctools_export_crud_new('ctools_export_test', FALSE);
$expected_export = new stdClass();
$expected_export->machine = '';
$expected_export->title = '';
$expected_export->number = NULL;
$expected_export->data = NULL;
$this->assertEqual($expected_export, $new_export, 'Make sure that an export object without default values is created.');
}
/**
* Tests the crud operation: revert.
*/
function testCrudRevert() {
// Load exportable, will come from database.
$original_export = ctools_export_crud_load('ctools_export_test', 'export_1');
$this->assertTrue($original_export->export_type === 3, 'Loaded export is overridden.');
$machine = $original_export->machine;
ctools_export_crud_delete('ctools_export_test', $original_export);
$result = db_query("SELECT machine FROM {ctools_export_test} WHERE machine = :machine", array(':machine' => $machine))->fetchField();
$this->assertFalse($result, 'Make sure the exportable object is removed from the database.');
// Clear the static cache.
ctools_export_load_object_reset('ctools_export_test');
// Reload the same object.
$default_export = ctools_export_crud_load('ctools_export_test', 'export_1');
// Check the exportable is now in_code_only.
$this->assertTrue($default_export->in_code_only, 'Loaded export is in database only');
// Make sure the default object loaded matches the same overridden one in the database.
$this->assertEqual($original_export->machine, $default_export->machine, 'The default exportable has been loaded and matches the overridden exportable.');
}
/**
* Tests the crud operation: delete.
*/
function testCrudDelete() {
// Create a stub entry save it and delete it from the database.
$export = ctools_export_crud_new('ctools_export_test');
ctools_export_crud_save('ctools_export_test', $export);
$machine = $export->machine;
ctools_export_crud_delete('ctools_export_test', $export);
$result = db_query("SELECT machine FROM {ctools_export_test} WHERE machine = :machine", array(':machine' => $machine))->fetchField();
$this->assertFalse($result, 'Make sure the export item is removed from the database.');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment