You are here

function NodeDisplaysBuildModes::testNdBuildModes in Node displays 6

Same name and namespace in other branches
  1. 6.3 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
  2. 6.2 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()
  3. 7 tests/nd.buildmodes.test \NodeDisplaysBuildModes::testNdBuildModes()

Test build modes.

File

tests/nd.buildmodes.test, line 124
Tests for Node displays (Build modes)

Class

NodeDisplaysBuildModes
@file Tests for Node displays (Build modes)

Code

function testNdBuildModes() {
  $admin_user = $this
    ->drupalCreateUser(array(
    'administer content types',
    'administer nodes',
  ));
  $this
    ->drupalLogin($admin_user);
  $this
    ->drupalGet('admin/content/types/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/content/types/nd/buildmodes', $edit, t('Save display'));
  $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/content/types/nd/buildmodes', $edit, t('Save display'));
  $this
    ->assertText(t('This display 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/content/types/nd/buildmodes/edit/test_key', $edit, t('Save display'));
  $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/content/types/nd/buildmodes', $edit, t('Save display'));
  $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/content/types/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/content/types/nd/buildmodes', $edit, t('Save display'));
  $this
    ->assertText(t('The machine-readable name must contain only lowercase letters and underscores.'), 'Key is not valid', t('Custom build modes'));
}