You are here

public function BlockClassTestCase::assertUpdateBlockClass in Block Class 7

Same name and namespace in other branches
  1. 7.2 block_class.test \BlockClassTestCase::assertUpdateBlockClass()

Update Block CSS class and assert whether it is found when displayed.

Parameters

bool $anon: (optional) Set to TRUE to view block with anon user, defaults to TRUE.

string $module: (optional) Machine name of the module Defaults to $this->module if set to NULL.

string $delta: (optional) Block delta as provided by its module. Defaults to $this->delta if set to NULL.

1 call to BlockClassTestCase::assertUpdateBlockClass()
BlockClassUpdateDisplayTestCase::testUpdateDisplayClass in ./block_class.test
Update and display a Block multiple times to ensure CSS class is found.

File

./block_class.test, line 71
Test the Block Class module.

Class

BlockClassTestCase
Provides common functionality for the Block Class test classes.

Code

public function assertUpdateBlockClass($anon = FALSE, $module = NULL, $delta = NULL) {

  // Initialize $module and $delta by default if no value is provided.
  if (!isset($module)) {
    $module = $this->module;
  }
  if (!isset($delta)) {
    $delta = $this->delta;
  }

  // Test with three random class names.
  $css_classes = implode(' ', array(
    $this
      ->randomName(8),
    $this
      ->randomName(8),
    $this
      ->randomName(8),
  ));

  // Update Block CSS class field.
  $this
    ->drupalPost("admin/structure/block/manage/{$module}/{$delta}/configure", array(
    'css_class' => $css_classes,
  ), t('Save block'));

  // Check Block configuration was saved successfully.
  $this
    ->assertText(t('The block configuration has been saved.'));

  // Browse to the homepage.
  $this
    ->drupalGet('');

  // Log out if the test is for anonymous user.
  if ($anon) {
    $this
      ->drupalLogout();

    // Browse back to the homepage.
    $this
      ->drupalGet('');
  }

  // Check if the Block CSS classes could be found.
  $this
    ->assertPattern('/class=\\"(.*?)' . $css_classes . '(.*?)\\"/', format_string('The CSS classes were found: @css_classes', array(
    '@css_classes' => $css_classes,
  )));

  // Login again after testing with the anonumous user.
  if ($anon) {
    $this
      ->drupalLogin($this->privilegedUser);
  }
}