You are here

public function S3fsDrushTest::testDrushCopyLocalNewerFilesOnly in S3 File System 4.0.x

Same name and namespace in other branches
  1. 8.3 tests/src/Functional/S3fsDrushTest.php \Drupal\Tests\s3fs\Functional\S3fsDrushTest::testDrushCopyLocalNewerFilesOnly()

Test drush s3fs:copy-local --scheme=public --condition=newer.

File

tests/src/Functional/S3fsDrushTest.php, line 122

Class

S3fsDrushTest
S3 File System Tests.

Namespace

Drupal\Tests\s3fs\Functional

Code

public function testDrushCopyLocalNewerFilesOnly() {
  touch('public://drush/test_file1.txt', '1400000000');
  $values = [
    [
      'uri' => 'public://drush/test_file1.txt',
      'filesize' => '18750',
      'timestamp' => date('U', 1500000000),
      'dir' => '0',
      'version' => '',
    ],
    [
      'uri' => 'public://drush/test_file2.txt',
      'filesize' => '18750',
      'timestamp' => date('U', 1500000000),
      'dir' => '0',
      'version' => '',
    ],
  ];
  $query = $this->connection
    ->insert('s3fs_file')
    ->fields([
    'uri',
    'filesize',
    'timestamp',
    'dir',
    'version',
  ]);
  foreach ($values as $record) {
    $query
      ->values($record);
  }
  $query
    ->execute();
  $this
    ->drush('s3fs:copy-local', [], [
    'scheme' => 'public',
    'condition' => 'newer',
  ]);
  $records = $this->connection
    ->select('s3fs_file', 's')
    ->fields('s', [
    'uri',
    'timestamp',
  ])
    ->condition('dir', 0, '=')
    ->condition('uri', '%' . $this->connection
    ->escapeLike('/drush/') . '%', 'LIKE')
    ->execute()
    ->fetchAllAssoc('uri', \PDO::FETCH_ASSOC);
  $this
    ->assertEquals('1500000000', $records['public://drush/test_file1.txt']['timestamp']);
  $this
    ->assertGreaterThan('1500000000', $records['public://drush/test_file2.txt']['timestamp']);
}