You are here

public function CustomBreadcrumbsFeaturesMachineNamesTestCase::testMachineNames in Custom Breadcrumbs Features 7.2

By default, crumbs have no machine name. If we enable our module, crumbs have machine names. If we create new crumbs, they have machine names. If we uninstall our module, crumbs have no machine name.

File

tests/machine_names.test, line 45
Test that custom_breadcrumbs_features provides allows crumbs to have a machine name.

Class

CustomBreadcrumbsFeaturesMachineNamesTestCase
Test that Custom Breadcrumbs can be associated with machine names.

Code

public function testMachineNames() {

  // Prepare crumbs to be created *before* features support is enabled.
  $crumbs1 = $this->crumbs;
  foreach ($crumbs1 as $type => $edit) {
    $crumbs1[$type]['name'] = $this
      ->randomName();
  }

  // Create crumbs + assert they have *no* machine name.
  foreach ($crumbs1 as $type => $edit) {
    $this
      ->createBreadcrumb($type, $edit);
    $this
      ->assertText($edit['name']);
    $this
      ->assertNoMachineName($type, $edit['name']);
  }

  // Enable our module + assert they *do* have a machine name.
  $this
    ->drupalGet('admin/modules');
  $this
    ->assertResponse(200);
  $edit = array(
    'modules[Custom breadcrumbs][custom_breadcrumbs_features][enable]' => TRUE,
    'modules[Features][features][enable]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertResponse(200);
  $this
    ->assertText(t('Generated machine name'));
  foreach ($crumbs1 as $type => $edit) {
    $this
      ->assertMachineName($type, $edit['name']);
  }

  // Prepare crumbs to be created *after* features support is enabled.
  $crumbs2 = $this->crumbs;
  foreach ($crumbs2 as $type => $edit) {
    $crumbs2[$type]['name'] = $this
      ->randomName();
  }

  // Create new crumbs + assert they *do* have a machine name.
  foreach ($crumbs2 as $type => $edit) {
    $this
      ->createBreadcrumb($type, $edit);
    $this
      ->assertNoText($edit['name']);
    $this
      ->createBreadcrumb($type, $edit + array(
      'machine_name' => 'foobar',
    ));
    $this
      ->assertText($edit['name']);
    $this
      ->assertMachineName($type, $edit['name']);
  }

  // Disable our module + assert crumbs *still* have machine names.
  $this
    ->drupalGet('admin/modules');
  $this
    ->assertResponse(200);
  $edit = array(
    'modules[Custom breadcrumbs][custom_breadcrumbs_features][enable]' => FALSE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Save configuration'));
  $this
    ->assertText(t('The configuration options have been saved.'));
  foreach ($crumbs1 as $type => $edit) {
    $this
      ->assertMachineName($type, $edit['name']);
  }
  foreach ($crumbs2 as $type => $edit) {
    $this
      ->assertMachineName($type, $edit['name']);
  }

  // Uninstall our module + assert crumbs have *no* machine names.
  $this
    ->drupalGet('admin/modules/uninstall');
  $edit = array(
    'uninstall[custom_breadcrumbs_features]' => TRUE,
  );
  $this
    ->drupalPost(NULL, $edit, t('Uninstall'));
  $this
    ->assertResponse(200);
  $this
    ->assertText(t('Confirm uninstall'));
  $this
    ->drupalPost(NULL, array(), t('Uninstall'));
  $this
    ->assertResponse(200);
  $this
    ->assertText(t('The selected modules have been uninstalled.'));
  foreach ($crumbs1 as $type => $edit) {
    $this
      ->assertNoMachineName($type, $edit['name']);
  }
  foreach ($crumbs2 as $type => $edit) {
    $this
      ->assertNoMachineName($type, $edit['name']);
  }
}