function FlagTestCase::testFlagAdmin in Flag 6
Same name and namespace in other branches
- 6.2 tests/flag.test \FlagTestCase::testFlagAdmin()
- 7.2 tests/flag.test \FlagTestCase::testFlagAdmin()
Create a flag through the UI and ensure that it is saved properly.
File
- tests/
flag.test, line 31
Class
Code
function testFlagAdmin() {
// Add a new flag using the UI.
$edit = array(
'name' => strtolower($this
->randomName()),
'title' => $this
->randomName(),
'flag_short' => 'flag short [nid]',
'flag_long' => 'flag long [nid]',
'flag_confirmation' => 'flag confirm [nid]',
'flag_message' => 'flag message [nid]',
'unflag_short' => 'unflag short [nid]',
'unflag_long' => 'unflag long [nid]',
'unflag_confirmation' => 'unflag confirm [nid]',
'unflag_message' => 'unflag message [nid]',
'roles[2]' => TRUE,
'types[story]' => FALSE,
'types[page]' => TRUE,
'show_on_teaser' => FALSE,
'show_on_page' => FALSE,
'show_on_form' => FALSE,
'link_type' => 'toggle',
);
$saved = $edit;
$saved['roles'] = array(
2,
);
$saved['types'] = array(
'page',
);
unset($saved['roles[2]'], $saved['types[story]'], $saved['types[page]']);
$this
->drupalPost('admin/build/flags/add/node/' . $edit['name'], $edit, t('Submit'));
$flag = flag_get_flag($edit['name']);
// Check that the flag object is in the database.
$this
->assertTrue($flag != FALSE, t('Flag object found in database'));
// Check each individual property of the flag and make sure it was set.
foreach ($saved as $property => $value) {
$this
->assertEqual($flag->{$property}, $value, t('Flag property %property properly saved.', array(
'%property' => $property,
)));
}
// Edit the flag through the UI.
$edit = array(
'name' => strtolower($this
->randomName()),
'title' => $this
->randomName(),
'flag_short' => 'flag 2 short [nid]',
'flag_long' => 'flag 2 long [nid]',
'flag_confirmation' => 'flag 2 confirm [nid]',
'flag_message' => 'flag 2 message [nid]',
'unflag_short' => 'unflag 2 short [nid]',
'unflag_long' => 'unflag 2 long [nid]',
'unflag_confirmation' => 'unflag 2 confirm [nid]',
'unflag_message' => 'unflag 2 message [nid]',
'roles[2]' => TRUE,
'types[story]' => TRUE,
'types[page]' => FALSE,
'show_on_teaser' => TRUE,
'show_on_page' => TRUE,
'show_on_form' => TRUE,
'link_type' => 'normal',
);
$saved = $edit;
$saved['roles'] = array(
2,
);
$saved['types'] = array(
'story',
);
unset($saved['roles[2]'], $saved['types[story]'], $saved['types[page]']);
$this
->drupalPost('admin/build/flags/edit/' . $flag->name, $edit, t('Submit'));
flag_get_flags(NULL, NULL, NULL, TRUE);
$flag = flag_get_flag($edit['name']);
// Check that the flag object is in the database.
$this
->assertTrue($flag != FALSE, t('Flag object found in database'));
// Check each individual property of the flag and make sure it was set.
foreach ($saved as $property => $value) {
$this
->assertEqual($flag->{$property}, $value, t('Flag property %property properly saved.', array(
'%property' => $property,
)));
}
// Delete the flag through the UI.
$this
->drupalPost('admin/build/flags/delete/' . $flag->name, array(), t('Delete'));
flag_get_flags(NULL, NULL, NULL, TRUE);
$this
->assertFalse(flag_get_flag($flag->name), t('Flag successfully deleted.'));
}