You are here

public function ViewsBaseUrlFieldTest::setUp in Views base url 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Functional/ViewsBaseUrlFieldTest.php \Drupal\Tests\views_base_url\Functional\ViewsBaseUrlFieldTest::setUp()

Overrides BrowserTestBase::setUp

File

tests/src/Functional/ViewsBaseUrlFieldTest.php, line 88

Class

ViewsBaseUrlFieldTest
Basic test for views base url.

Namespace

Drupal\Tests\views_base_url\Functional

Code

public function setUp() {
  parent::setUp();
  $this->adminUser = $this
    ->drupalCreateUser([
    'create article content',
  ]);
  $random = new Random();

  /** @var \Drupal\path_alias\PathAliasStorage $pathAliasStorage */
  $this->pathAliasStorage = $this->container
    ->get('entity_type.manager')
    ->getStorage('path_alias');

  /** @var \Drupal\path_alias\AliasManager $pathAliasManager */
  $this->pathAliasManager = $this->container
    ->get('path_alias.manager');

  /** @var \Drupal\Core\File\FileSystemInterface $fileSystem */
  $this->fileSystem = $this->container
    ->get('file_system');

  // Create $this->nodeCount nodes.
  $this
    ->drupalLogin($this->adminUser);
  for ($i = 1; $i <= $this->nodeCount; $i++) {

    // Create node.
    $title = $random
      ->name();
    $image = current($this
      ->drupalGetTestFiles('image'));
    $edit = [
      'title[0][value]' => $title,
      'files[field_image_0]' => $this->fileSystem
        ->realpath($image->uri),
    ];
    $this
      ->drupalPostForm('node/add/article', $edit, t('Save'));
    $this
      ->drupalPostForm(NULL, [
      'field_image[0][alt]' => $title,
    ], t('Save'));
    $this->nodes[$i] = $this
      ->drupalGetNodeByTitle($title);
    $path_alias = $this->pathAliasStorage
      ->create([
      'path' => '/node/' . $this->nodes[$i]
        ->id(),
      'alias' => "/content/" . $title,
    ]);
    $path_alias
      ->save();
  }
  $this
    ->drupalLogout();
}