You are here

public function GroupContentMenuTest::testCreateGroupContentMenu in Group Content Menu 8

Test creation of a group content menu.

File

tests/src/Functional/GroupContentMenuTest.php, line 149

Class

GroupContentMenuTest
Test description.

Namespace

Drupal\Tests\group_content_menu\Functional

Code

public function testCreateGroupContentMenu() {

  /** @var \Drupal\Tests\WebAssert $assert */
  $assert = $this
    ->assertSession();

  /** @var \Behat\Mink\Element\DocumentElement $page */
  $page = $this
    ->getSession()
    ->getPage();

  // Generate a group content menu type.
  $this
    ->drupalGet('admin/structure/group_content_menu_types');
  $page
    ->clickLink('Add group menu type');
  $assert
    ->statusCodeEquals(200);
  $page
    ->fillField('label', 'Group Menu');
  $page
    ->fillField('id', 'group_menu');
  $page
    ->pressButton('Save');
  $assert
    ->statusCodeEquals(200);
  $assert
    ->pageTextContains('The group menu type Group Menu has been added.');

  // Place a group content menu block.
  $default_theme = $this
    ->config('system.theme')
    ->get('default');
  $options = [
    'query' => [
      'region' => 'sidebar_first',
      'weight' => 0,
    ],
  ];
  $this
    ->drupalGet(Url::fromRoute('block.admin_library', [
    'theme' => $default_theme,
  ], $options));
  $block_name = 'group_content_menu:group_menu';
  $add_url = Url::fromRoute('block.admin_add', [
    'plugin_id' => $block_name,
    'theme' => $default_theme,
  ]);
  $links = $this
    ->xpath('//a[contains(@href, :href)]', [
    ':href' => $add_url
      ->toString(),
  ]);
  $this
    ->assertCount(1, $links, 'Found one matching link.');
  $links[0]
    ->click();
  $assert
    ->statusCodeEquals(200);
  $page
    ->fillField('settings[context_mapping][group]', '@group.group_route_context:group');
  $page
    ->pressButton('Save block');
  $assert
    ->statusCodeEquals(200);

  // Enable the group content plugin.
  $this
    ->drupalGet('/admin/group/content/install/default/group_content_menu:group_menu');
  $page
    ->checkField('auto_create_group_menu');
  $page
    ->checkField('auto_create_home_link');
  $page
    ->fillField('auto_create_home_link_title', 'Group home page');
  $page
    ->pressButton('Install plugin');
  $assert
    ->pageTextContains('The content plugin was installed on the group type. ');

  // Add a group and group content menu.
  $this
    ->drupalGet('/group/add/default');
  $group_title = $this
    ->randomString();
  $page
    ->fillField('label[0][value]', $group_title);
  $page
    ->pressButton('Create Default label and complete your membership');
  $page
    ->pressButton('Save group and membership');
  $assert
    ->linkExists('Group home page');

  // Home link is editable.
  $this
    ->drupalGet('/group/1/menu/1/link/1');
  $assert
    ->statusCodeEquals(200);
  $page
    ->pressButton('Save');
  $assert
    ->pageTextContains('The menu link has been saved.');

  // Add menu links to the newly created menu and render the menu.
  $this
    ->drupalGet('/group/1/menu/1/edit');
  $assert
    ->statusCodeEquals(200);
  $this
    ->drupalGet('/group/1/menu/1/add-link');
  $assert
    ->statusCodeEquals(200);

  // Add a link.
  $link_title = $this
    ->randomString();
  $page
    ->fillField('title[0][value]', $link_title);
  $page
    ->fillField('link[0][uri]', '<front>');
  $page
    ->pressButton('Save');

  // Edit the link
  $this
    ->drupalGet('/group/1/menu/1/link/2');
  $page
    ->selectFieldOption('menu_parent', '-- Group home page');
  $page
    ->pressButton('Save');
  $assert
    ->pageTextContains('The menu link has been saved. ');
  $this
    ->drupalGet('/group/1');
  $assert
    ->linkExists($link_title);
  $this
    ->drupalGet('/group/1/menu/1/edit');
  $assert
    ->statusCodeEquals(200);

  // Delete menu.
  $this
    ->drupalGet('/group/1/menu/1/delete');
  $page
    ->pressButton('Delete');
  $assert
    ->pageTextContains('The group content menu Group Menu has been deleted.');

  // Re-add menu.
  $this
    ->drupalGet('/group/1/content/create/group_content_menu:group_menu');
  $menu_title = $this
    ->randomString();
  $page
    ->fillField('label[0][value]', $menu_title);
  $page
    ->pressButton('Save');
  $assert
    ->pageTextContains("New group menu {$menu_title} has been created. ");
}