You are here

public function ViewsBulkOperationsDataServiceTest::testViewsbulkOperationsViewDataEntityGetter in Views Bulk Operations (VBO) 4.0.x

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

Tests the getEntityDefault() method.

@covers ::getEntityDefault

File

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

Class

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

Namespace

Drupal\Tests\views_bulk_operations\Kernel

Code

public function testViewsbulkOperationsViewDataEntityGetter() {

  // Initialize and execute the test view with all items displayed.
  $view = Views::getView('views_bulk_operations_test');
  $view
    ->setDisplay('page_1');
  $view
    ->setItemsPerPage(0);
  $view
    ->setCurrentPage(0);
  $view
    ->execute();
  $test_data = $this->testNodesData;
  foreach ($view->result as $row) {
    $entity = $this->vboDataService
      ->getEntityDefault($row, 'none', $view);
    $expected_label = $test_data[$entity
      ->id()][$entity
      ->language()
      ->getId()];
    $this
      ->assertEquals($expected_label, $entity
      ->label(), 'Title matches');
    if ($expected_label === $entity
      ->label()) {
      unset($test_data[$entity
        ->id()][$entity
        ->language()
        ->getId()]);
      if (empty($test_data[$entity
        ->id()])) {
        unset($test_data[$entity
          ->id()]);
      }
    }
  }
  $this
    ->assertEmpty($test_data, 'All created entities and their translations were returned.');
}