You are here

function NodeDisplaysBuildModes::testNdBuildModes in Node displays 6.2

Same name and namespace in other branches
  1. 6.3 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
  2. 6 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
  3. 7 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(DS_PATH_MODULES . '/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(DS_PATH_MODULES . '/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(DS_PATH_MODULES . '/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(
    'name' => 'Test label 2',
  );
  $this
    ->drupalPost(DS_PATH_MODULES . '/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(DS_PATH_MODULES . '/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(DS_PATH_MODULES . '/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(DS_PATH_MODULES . '/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'));
}