public function FeatureContext::checkFilesPrivateForUser in Open Social 8.4
Same name and namespace in other branches
- 8.9 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 8.3 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 8.5 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 8.6 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 8.7 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 8.8 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 10.0.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::checkFilesPrivateForUser()
- 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\BehatCode
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));
}
}