You are here

public function EntityFormBlockTestCase::assignEntityFormBlock in Entityform block 7

1 call to EntityFormBlockTestCase::assignEntityFormBlock()
EntityFormBlockTestCase::testEntityFormBlock in ./entityform_block.test

File

./entityform_block.test, line 70
Tests for the Entityform Block module

Class

EntityFormBlockTestCase
@file Tests for the Entityform Block module

Code

public function assignEntityFormBlock() {

  // Enable block to some region.
  $region = 'sidebar_first';
  $block = array(
    'module' => 'entityform_block',
    'delta' => $this->entityFormType,
    'title' => $this->entityFormType,
  );
  $edit = array();
  $edit['blocks[' . $block['module'] . '_' . $block['delta'] . '][region]'] = $region;
  $this
    ->drupalPost('admin/structure/block', $edit, t('Save blocks'));

  // Confirm that the block was moved to the proper region.
  $this
    ->assertText(t('The block settings have been updated.'), t('Block successfully moved to %region_name region.', array(
    '%region_name' => $region,
  )));

  // Confirm that the block is being displayed.
  $this
    ->drupalGet('node');
  $this
    ->assertText(t($block['title']), t('Block successfully being displayed on the page.'));

  // Confirm that the custom block was found at the proper region.
  $xpath = $this
    ->buildXPathQuery('//div[@class=:region-class]//div[@id=:block-id]/*', array(
    ':region-class' => 'region region-' . str_replace('_', '-', $region),
    ':block-id' => 'block-' . str_replace('_', '-', $block['module']) . '-' . $block['delta'],
  ));
  $this
    ->assertFieldByXPath($xpath, NULL, t('Custom block found in %region_name region.', array(
    '%region_name' => $region,
  )));

  // Check the form fields.
  $xpath_field = $this
    ->buildXPathQuery('//div[@id=:field-id]/*', array(
    ':field-id' => 'edit-field-' . $this->entityFieldName,
  ));
  $this
    ->assertFieldByXPath($xpath_field, NULL, t('Custom form\'s fields found in form @title', array(
    '@title' => $this->entityFormType,
  )));
  $this
    ->assertFieldByName('field_' . $this->entityFieldName . '[und][0][value]', '', t('Custom form\'s fields found in form @title', array(
    '@title' => $this->entityFormType,
  )));

  // Test submission
  $this
    ->drupalPost('node', array(
    'field_' . $this->entityFieldName . '[und][0][value]' => $this
      ->randomName(8),
  ), $submit);
  $arg = arg(2);
  $this
    ->assertEqual($arg, 'confirm', 'The confirmation page has been loaded.');
}