You are here

public function WeightTest::setUp in Weight 8.3

Overrides BrowserTestBase::setUp

File

tests/src/FunctionalJavascript/WeightTest.php, line 83

Class

WeightTest
Test basic functionality of weight.

Namespace

Drupal\Tests\weight\FunctionalJavascript

Code

public function setUp() {
  parent::setUp();
  $this->adminUser = $this
    ->drupalCreateUser([
    'administer content types',
    'administer node fields',
    'administer node display',
  ]);

  // Create an article content type that we will use for testing.
  $type = $this->container
    ->get('entity_type.manager')
    ->getStorage('node_type')
    ->create([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $type
    ->save();
  $this->container
    ->get('router.builder')
    ->rebuild();
  $fieldStorage = FieldStorageConfig::create([
    'field_name' => static::$fieldName,
    'entity_type' => 'node',
    'type' => static::$fieldType,
  ]);
  $fieldStorage
    ->save();
  $field = FieldConfig::create([
    'field_storage' => $fieldStorage,
    'bundle' => 'article',
    'required' => FALSE,
  ]);
  $field
    ->save();
  $nodes[] = [
    'type' => 'article',
    'title' => 'Article 1',
    'field_weight' => -20,
  ];
  $nodes[] = [
    'type' => 'article',
    'title' => 'Article 2',
    'field_weight' => -19,
  ];
  $nodes[] = [
    'type' => 'article',
    'title' => 'Article 3',
    'field_weight' => -18,
  ];
  $nodes[] = [
    'type' => 'article',
    'title' => 'Article 4',
    'field_weight' => -17,
  ];

  // Create nodes.
  foreach ($nodes as $n) {
    $node = $this
      ->drupalCreateNode($n);
    $node
      ->save();
    $this->nodes[] = $node;
  }
  ViewTestData::createTestViews(get_class($this), [
    'weight_test_views',
  ]);
}