function LinksetControllerTest::setUp

Same name and namespace in other branches
  1. 11.x core/modules/system/tests/src/Functional/Menu/LinksetControllerTest.php \Drupal\Tests\system\Functional\Menu\LinksetControllerTest::setUp()

Test set up.

Installs necessary database schemas, then creates test content and menu items. The concept of this set up is to replicate a typical site's menus.

Throws

\Drupal\Core\Entity\EntityStorageException

Overrides BrowserTestBase::setUp

File

core/modules/system/tests/src/Functional/Menu/LinksetControllerTest.php, line 61

Class

LinksetControllerTest
Tests the behavior of the linkset controller.

Namespace

Drupal\Tests\system\Functional\Menu

Code

public function setUp() : void {
  parent::setUp();
  $permissions = [
    'view own unpublished content',
  ];
  $this->authorAccount = $this->setUpCurrentUser([
    'name' => 'author',
    'pass' => 'authorPass',
  ], $permissions);
  NodeType::create([
    'type' => 'page',
    'name' => 'Page',
  ])->save();
  $home_page_link = $this->createMenuItem([
    'title' => 'Home',
    'description' => 'Links to the home page.',
    'link' => 'internal:/<front>',
    'weight' => 0,
    'menu_name' => 'main',
  ]);
  $about_us_page = $this->createNode([
    'nid' => 1,
    'title' => 'About us',
    'type' => 'page',
    'path' => '/about',
  ]);
  $about_us_link = $this->createMenuItem([
    'title' => 'About us',
    'description' => 'Links to the about us page.',
    'link' => 'entity:node/' . (int) $about_us_page->id(),
    'weight' => $home_page_link->getWeight() + 1,
    'menu_name' => 'main',
  ]);
  $our_name_page = $this->createNode([
    'nid' => 2,
    'title' => 'Our name',
    'type' => 'page',
    'path' => '/about/name',
  ]);
  $this->createMenuItem([
    'title' => 'Our name',
    'description' => 'Links to the page which describes the origin of the organization name.',
    'link' => 'entity:node/' . (int) $our_name_page->id(),
    'menu_name' => 'main',
    'parent' => $about_us_link->getPluginId(),
  ]);
  $custom_attributes_test_page = $this->createNode([
    'nid' => 3,
    'title' => 'Custom attributes test page',
    'type' => 'page',
    'path' => '/about/custom-attributes',
  ]);
  $options = [
    'attributes' => [
      'class' => [
        'foo',
        'bar',
        1729,
        TRUE,
        -1,
        3.141592,
      ],
      'data-baz' => '42',
      '*ignored' => '¯\\_(ツ)_/¯',
      "hreflang" => "en-mx",
      "media" => "???",
      "type" => "???",
      "title" => "???",
      "title*" => "???",
    ],
  ];
  $this->createMenuItem([
    'title' => 'Custom attributes test page',
    'description' => 'Links to the page which describes the origin of the organization name.',
    'link' => 'entity:node/' . (int) $custom_attributes_test_page->id(),
    'menu_name' => 'main',
    'parent' => $about_us_link->getPluginId(),
  ], $options);
  $this->httpKernel = $this->container
    ->get('http_kernel');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.