You are here

public function ViewsBulkOperationsDataServiceTest::setUp in Views Bulk Operations (VBO) 8

Same name and namespace in other branches
  1. 8.3 tests/src/Kernel/ViewsBulkOperationsDataServiceTest.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsDataServiceTest::setUp()
  2. 8.2 tests/src/Kernel/ViewsBulkOperationsDataServiceTest.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsDataServiceTest::setUp()
  3. 4.0.x tests/src/Kernel/ViewsBulkOperationsDataServiceTest.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsDataServiceTest::setUp()

Overrides KernelTestBase::setUp

File

tests/src/Kernel/ViewsBulkOperationsDataServiceTest.php, line 64

Class

ViewsBulkOperationsDataServiceTest
@coversDefaultClass \Drupal\views_bulk_operations\Service\ViewsBulkOperationsViewData @group views_bulk_operations

Namespace

Drupal\Tests\views_bulk_operations\Kernel

Code

public function setUp() {
  parent::setUp();
  $this
    ->installConfig([
    'filter',
    'views_bulk_operations_test',
    'language',
  ]);
  $this
    ->installEntitySchema('user');
  $this
    ->installEntitySchema('node');
  $this
    ->installSchema('node', 'node_access');
  $languages = [
    'pl',
    'es',
    'it',
    'fr',
    'de',
  ];
  $count_languages = count($languages);
  for ($i = 0; $i < $count_languages; $i++) {
    $language = ConfigurableLanguage::createFromLangcode($languages[$i]);
    $language
      ->save();
  }
  $type = NodeType::create([
    'type' => 'page',
    'name' => 'page',
  ]);
  $type
    ->save();
  \Drupal::service('content_translation.manager')
    ->setEnabled('node', 'page', TRUE);
  \Drupal::entityManager()
    ->clearCachedDefinitions();

  // Create some test nodes with translations.
  $this->testNodesData = [];
  $time = REQUEST_TIME;
  for ($i = 0; $i < 10; $i++) {
    $time -= $i;
    $title = 'Title ' . $i;
    $node = $this
      ->drupalCreateNode([
      'type' => 'page',
      'title' => $title,
      'sticky' => FALSE,
      'created' => $time,
      'changed' => $time,
    ]);
    $this->testNodesData[$node
      ->id()]['en'] = $title;
    $this->resultsCount++;
    $langcode = $languages[rand(0, $count_languages - 1)];
    $title = 'Translated title ' . $langcode . ' ' . $i;
    $translation = $node
      ->addTranslation($langcode, [
      'title' => $title,
    ]);
    $translation
      ->save();
    $this->testNodesData[$node
      ->id()][$langcode] = $title;
    $this->resultsCount++;
  }

  // Initialize the tested service.
  $this->vboDataService = $this->container
    ->get('views_bulk_operations.data');
}