1.20.x layout.test public LayoutHookTestCase::testLayoutHooks()

Tests hook invocations for operations on layouts.

File

modules/layout/tests/layout.test, line 2710
Tests for the Layout module.

Class

LayoutHookTestCase
Tests invocation of hooks when performing an action.

Code

public function testLayoutHooks() {
  state_set('layout_test', array());

  $this->backdropGet('admin/structure/layouts');
  $this->clickLink(t('Add layout'));

  // Create a new layout at a new path.
  $layout_title = $this->randomName();
  $layout_name = strtolower($layout_title);
  $layout_url = 'layout-test-path';
  $edit = array(
    'title' => $layout_title,
    'name' => $layout_name,
    'layout_template' => 'moscone_flipped',
    'path' => $layout_url,
  );
  $this->backdropPost(NULL, $edit, t('Create layout'));

  // We should be taken to the layout content page next.
  $this->assertText(t('Layout created. Blocks may now be added to this layout.'));

  // Save the layout.
  $this->backdropPost(NULL, array(), t('Save layout'));

  $this->assertHookMessageOrder(array(
    'layout_test_layout_presave called',
    'layout_test_layout_insert called',
  ));

  state_set('layout_test', array());

  // Return to the layout edit page and save it again.
  $this->backdropGet('admin/structure/layouts/manage/' . $layout_name);
  $this->backdropPost(NULL, array(), t('Save layout'));

  $this->assertHookMessageOrder(array(
    'layout_test_layout_presave called',
    'layout_test_layout_update called',
  ));

  // Disable the layout via the dropbutton link.
  state_set('layout_test', array());
  $this->backdropGet('admin/structure/layouts');
  $disable_link = $this->xpath('//*[contains(@class, "disable")]//a');
  $disable_url_parts = backdrop_parse_url($disable_link[0]['href']);
  $this->backdropGet($disable_url_parts['path'], $disable_url_parts);
  $this->assertHookMessageOrder(array(
    'layout_test_layout_disable called',
  ));

  state_set('layout_test', array());

  // Re-enable the layout.
  $this->backdropGet('admin/structure/layouts/manage');
  $enable_link = $this->xpath('//li[contains(@class, "enable")]//a');
  $enable_url_parts = backdrop_parse_url($enable_link[0]['href']);
  $this->backdropGet($enable_url_parts['path'], $enable_url_parts);
  $this->assertHookMessageOrder(array(
    'layout_test_layout_enable called',
  ));

  // Delete the layout.
  state_set('layout_test', array());
  $this->backdropPost('admin/structure/layouts/manage/' . $layout_name . '/delete', array(), t('Delete layout'));
  $this->assertHookMessageOrder(array(
    'layout_test_layout_delete called',
  ));

  // Go to the Default layout's edit page and change the layout to the
  // boxton layout.
  state_set('layout_test', array());
  $edit = array(
    'layout_template' => 'boxton',
  );
  $this->backdropPost('admin/structure/layouts/manage/default/configure', $edit, t('Save layout'));
  $this->assertHookMessageOrder(array(
    'layout_test_layout_template_change called',
  ));

  // Save the layout.
  $this->backdropPost(NULL, array(), t('Save layout'));

  // Revert the Default layout.
  state_set('layout_test', array());
  $this->backdropPost('admin/structure/layouts/manage/default/delete', array(), t('Revert layout'));
  $this->assertHookMessageOrder(array(
    'layout_test_layout_revert called',
  ));
}