function NodeDisplaysBuildModes::testNdBuildModes in Node displays 7
Same name and namespace in other branches
- 6.3 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
- 6 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
- 6.2 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
Test build modes.
File
- tests/
nd.buildmodes.test, line 115 - Tests for Node displays (Build modes)
Class
- NodeDisplaysBuildModes
- @file Tests for Node displays (Build modes)
Code
function testNdBuildModes() {
$admin_user = $this
->drupalCreateUser(array(
'administer nodes',
'access display suite',
'administer nd',
'configure layout for nd',
'export and import settings',
'revert overridden settings',
'use PHP in custom fields',
));
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/ds/nd/buildmodes');
// Test being empty.
$build_modes = variable_get('nd_build_modes', array());
$this
->assertEqual(array(), $build_modes, t('Build modes are empty'), t('Custom build modes.'));
// Valid build mode.
$edit = array(
'key' => 'test_key',
'name' => 'Test label',
);
$this
->drupalPost('admin/ds/nd/buildmodes', $edit, t('Save build mode'));
$build_modes = variable_get('nd_build_modes', array());
$this
->assertTrue(array_key_exists('test_key', $build_modes), t('test_key exists'), t('Custom build modes'));
$this
->assertEqual($build_modes['test_key'], $edit['name'], t('Label equals Test label'), t('Custom build modes'));
// Try to add the same build mode, must fail.
$this
->drupalPost('admin/ds/nd/buildmodes', $edit, t('Save build mode'));
$this
->assertText(t('This build mode already exists.'), 'Key already exists', t('Custom build modes'));
// Update build mode.
$edit = array(
'key' => 'test_key',
'name' => 'Test label 2',
);
$this
->drupalPost('admin/ds/nd/buildmodes/edit/test_key', $edit, t('Save build mode'));
$build_modes = variable_get('nd_build_modes', array());
$this
->assertEqual($build_modes['test_key'], $edit['name'], t('Label equals Test label 2'), t('Custom build modes'));
$this
->assertEqual(count($build_modes), 1, t('Only 1 build mode'), t('Custom build modes'));
// Add new build mode.
$edit = array(
'key' => 'test_key_two',
'name' => 'Test label 3',
);
$this
->drupalPost('admin/ds/nd/buildmodes', $edit, t('Save build mode'));
$build_modes = variable_get('nd_build_modes', array());
$this
->assertEqual($build_modes['test_key_two'], $edit['name'], t('Label equals Test label 3'), t('Custom build modes'));
$this
->assertEqual(count($build_modes), 2, t('2 build modes found'), t('Custom build modes'));
// Delete build mode.
$this
->drupalPost('admin/ds/nd/buildmodes/delete/test_key', array(), t('Delete'));
$build_modes = variable_get('nd_build_modes', array());
$this
->assertFalse(array_key_exists('test_key', $build_modes), t('test_key removed'), t('Custom build modes'));
$this
->assertEqual(count($build_modes), 1, t('Only 1 build mode'), t('Custom build modes'));
// Invalid key.
$edit = array(
'key' => 'test_key moehaha',
'name' => 'Test label',
);
$this
->drupalPost('admin/ds/nd/buildmodes', $edit, t('Save build mode'));
$this
->assertText(t('The machine-readable name must contain only lowercase letters, numbers and underscores.'), 'Key is not valid', t('Custom build modes'));
}