You are here

public function FeatureContext::checkFilesPrivateForUser in Open Social 8.4

Same name and namespace in other branches
  1. 8.9 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  2. 8.3 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  3. 8.5 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  4. 8.6 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  5. 8.7 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  6. 8.8 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  7. 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  8. 10.0.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  9. 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
  10. 10.2.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()

Checks if correct amount of uploaded files by user are private.

@Then /User "(?P<username>[^"]+)" should have uploaded "(?P<private>[^"]+)" private files and "(?P<public>[^"]+)" public files$/

File

tests/behat/features/bootstrap/FeatureContext.php, line 650

Class

FeatureContext
Defines application features from the specific context.

Namespace

Drupal\social\Behat

Code

public function checkFilesPrivateForUser($username, $private, $public) {
  $query = \Drupal::entityQuery('user')
    ->condition('name', $username);
  $uid = $query
    ->execute();
  if (!empty($uid) && count($uid) === 1) {
    $uid = reset($uid);
    if ($uid) {
      $private_query = \Drupal::database()
        ->select('file_managed', 'fm');
      $private_query
        ->addField('fm', 'fid');
      $private_query
        ->condition('fm.uid', $uid, '=');
      $private_query
        ->condition('fm.uri', 'private://%', 'LIKE');
      $private_count = count($private_query
        ->execute()
        ->fetchAllAssoc('fid'));
      $public_query = \Drupal::database()
        ->select('file_managed', 'fm');
      $public_query
        ->addField('fm', 'fid');
      $public_query
        ->condition('fm.uid', $uid, '=');
      $public_query
        ->condition('fm.uri', 'public://%', 'LIKE');
      $public_count = count($public_query
        ->execute()
        ->fetchAllAssoc('fid'));
      Assert::assertEquals($private, $private_count, sprintf("Private count was not '%s', instead '%s' private files found.", $private, $private_count));
      Assert::assertEquals($public, $public_count, sprintf("Public count was not '%s', instead '%s' public files found.", $public, $public_count));
    }
  }
  else {
    throw new \Exception(sprintf("User '%s' does not exist.", $username));
  }
}