You are here

public function ViewsDataExportGarbageCollectionTest::testExportedGarbageCollection in Views data export 7.3

Test that VDE export can only be downloaded by the user that created them.

File

tests/garbagecollection.test, line 21

Class

ViewsDataExportGarbageCollectionTest
Test class for garbage collection of VDE export data.

Code

public function testExportedGarbageCollection() {

  // Run a batched export.
  $path = 'vde_test/' . $this
    ->randomName();
  list($view, $expected) = $this
    ->getExportView($path);
  $display =& $view->display['vde_test']->handler;

  // Set this view to be batched.
  $display
    ->override_option('use_batch', 'batch');

  // Save this view so we can hit the path.
  $view
    ->save();

  // Ensure that the menu router system is rebuilt on the next page load.
  variable_set('menu_rebuild_needed', TRUE);
  $exports = $this
    ->getNumberOfStoredExports();
  $files = $this
    ->getNumberOfFiles();
  $this
    ->assertBatchedExportEqual($path, $expected, 'Batched access export matched expected output.');

  // We should have created a new export and file.
  $this
    ->assertEqual($this
    ->getNumberOfStoredExports(), $exports + 1, 'A single new batched export was created');
  $this
    ->assertEqual($this
    ->getNumberOfFiles(), $files + 1, 'A single new temporary file was created');
  $middle_timestamp = time();
  sleep(1);
  $this
    ->assertBatchedExportEqual($path, $expected, 'Batched access export matched expected output.');

  // We should have created a new export and file.
  $this
    ->assertEqual($this
    ->getNumberOfStoredExports(), $exports + 2, 'A single new batched export was created');
  $this
    ->assertEqual($this
    ->getNumberOfFiles(), $files + 2, 'A single new temporary file was created');

  // Garbage collect the first export only.
  views_data_export_garbage_collect(REQUEST_TIME - $middle_timestamp);
  $this
    ->assertEqual($this
    ->getNumberOfStoredExports(), $exports + 1, 'Garbage collection removed 1 old export');
  $this
    ->assertEqual($this
    ->getNumberOfFiles(), $files + 1, 'Garbage collection removed 1 old temporary file');
}