You are here

function NodeDisplaysFields::testNdCustomBlockFields in Node displays 7

Same name and namespace in other branches
  1. 6.3 tests/nd.fields.test \NodeDisplaysFields::testNdCustomBlockFields()
  2. 6.2 tests/nd.fields.test \NodeDisplaysFields::testNdCustomBlockFields()

Test custom block fields.

File

tests/nd.fields.test, line 180
Tests for Node displays (fields)

Class

NodeDisplaysFields
@file Tests for Node displays (fields)

Code

function testNdCustomBlockFields() {
  $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/fields');

  // Valid field.
  $edit = array(
    'block_key' => 'test_field',
    'block_title' => 'Test field label',
    'block_block' => 'user|3',
    'block_render' => DS_BLOCK_TEMPLATE,
  );
  $this
    ->drupalPost('admin/ds/nd/fields', $edit, t('Save block field'));
  $fields = variable_get('nd_fields', array());
  $this
    ->assertTrue(array_key_exists('test_field', $fields), t('test_field exists'), t('Block fields'));
  $this
    ->assertEqual($fields['test_field']['title'], $edit['block_title'], t('Title equals Test field label'), t('Block fields'));
  $this
    ->assertEqual($fields['test_field']['properties']['block'], $edit['block_block'], t('Code equals user|3'), t('Block fields'));
  $this
    ->assertEqual($fields['test_field']['properties']['render'], $edit['block_render'], t('Code equals ' . DS_BLOCK_TEMPLATE), t('Block fields'));

  // Create a node and set some fields.
  $page_node = $this
    ->drupalCreateNode();
  $edit = array(
    'title[full][region]' => 'header',
    'test_field[full][region]' => 'middle',
  );
  $this
    ->drupalPost('admin/ds/layout/page', $edit, t('Save'));

  // Block rendering through template.
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertText('Who\'s online', t('Block title found'), t('Block fields'));
  $this
    ->assertText('There are currently 1 user and 0 guests online.', t('Block text found'), t('Block fields'));
  $this
    ->assertRaw('block-user-3', t('Block ID found'), t('Block fields'));

  // Block rendering without template.
  $edit = array(
    'block_key' => 'test_field',
    'block_title' => 'Test field label',
    'block_block' => 'user|3',
    'block_render' => DS_BLOCK_TITLE_CONTENT,
  );
  $this
    ->drupalPost('admin/ds/nd/fields/edit/test_field', $edit, t('Save block field'));
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertText('Who\'s online', t('Block title found'), t('Block fields'));
  $this
    ->assertText('There are currently 1 user and 0 guests online.', t('Block text found'), t('Block fields'));
  $this
    ->assertNoRaw('block-user-3', t('Block ID found'), t('Block fields'));

  // Only block content.
  $edit = array(
    'block_key' => 'test_field',
    'block_title' => 'Test field label',
    'block_block' => 'user|3',
    'block_render' => DS_BLOCK_CONTENT,
  );
  $this
    ->drupalPost('admin/ds/nd/fields/edit/test_field', $edit, t('Save block field'));
  $this
    ->drupalGet('node/' . $page_node->nid);
  $this
    ->assertNoText('Who\'s online', t('Block title found'), t('Block fields'));
  $this
    ->assertText('There are currently 1 user and 0 guests online.', t('Block text found'), t('Block fields'));
  $this
    ->assertNoRaw('block-user-3', t('Block ID found'), t('Block fields'));
}