You are here

public function ViewsDataExportBatchTest::testBatchCreation in Views data export 8

Test VDE SQL views with batch.

File

tests/src/Functional/ViewsDataExportBatchTest.php, line 80

Class

ViewsDataExportBatchTest
Tests views data export with batch.

Namespace

Drupal\Tests\views_data_export\Functional

Code

public function testBatchCreation() {

  // By this view we fetch page with link present.
  $this
    ->drupalGet('views_data_export/test_1');
  $link = $this
    ->getSession()
    ->getPage()
    ->findLink('here');
  $path_to_file = $link
    ->getAttribute('href');
  $this
    ->drupalGet($path_to_file);
  $this
    ->assertEquals(200, $this
    ->getSession()
    ->getStatusCode(), 'File was not created');

  // By this view we obtain file right after batch process finished.
  // @todo - make separate FunctionalJavascript test to check automatic fetching.
  $this
    ->drupalGet('views_data_export/test_2');
  $this
    ->assertSession()
    ->pageTextContainsOnce('automatically downloaded');

  // By this view's batch finished we must be redirected to /admin and fetch
  // csv with 3 rows only.
  $this
    ->drupalGet('views_data_export/test_3');
  $this
    ->assertEquals(parse_url($this
    ->getSession()
    ->getCurrentUrl(), PHP_URL_PATH), $_SERVER['REQUEST_URI'] . 'admin', 'User is not redirected to /admin page as expected');
  $link = $this
    ->getSession()
    ->getPage()
    ->findLink('here');
  $path_to_file = $link
    ->getAttribute('href');
  $path_to_file = parse_url($path_to_file, PHP_URL_PATH);
  $path_to_file = str_replace($_SERVER['REQUEST_URI'] . 'system/files', 'private:/', $path_to_file);
  $res3 = $this
    ->readCsv(file_get_contents($path_to_file));
  $this
    ->assertEquals(3, count($res3), 'Count of exported nodes is wrong.');

  // Testing search api index's view.
  $this
    ->indexItems('database_search_index');
  $this
    ->drupalGet('views_data_export/test_search_api');
  $link = $this
    ->getSession()
    ->getPage()
    ->findLink('here');
  $path_to_file = $link
    ->getAttribute('href');
  $path_to_file = parse_url($path_to_file, PHP_URL_PATH);
  $path_to_file = str_replace($_SERVER['REQUEST_URI'] . 'system/files', 'private:/', $path_to_file);
  $res4 = $this
    ->readCsv(file_get_contents($path_to_file));
  $this
    ->assertEquals(8, count($res4), 'Count of exported test entities is wrong.');
}