public function FeatureContext::openAndCheckFilesPrivateForUser in Open Social 8.4
Same name and namespace in other branches
- 8.9 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 8.3 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 8.5 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 8.6 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 8.7 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 8.8 tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 10.3.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 10.0.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 10.1.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
- 10.2.x tests/behat/features/bootstrap/FeatureContext.php \Drupal\social\Behat\FeatureContext::openAndCheckFilesPrivateForUser()
Opens the files uploaded by a given user.
@Then /I open and check the access of the files uploaded by "(?P<username>[^"]+)" and I expect access "(?P<access>[^"]+)"$/
File
- tests/
behat/ features/ bootstrap/ FeatureContext.php, line 688
Class
- FeatureContext
- Defines application features from the specific context.
Namespace
Drupal\social\BehatCode
public function openAndCheckFilesPrivateForUser($username, $access) {
$allowed_access = array(
'0' => 'denied',
'1' => 'allowed',
);
if (!in_array($access, $allowed_access)) {
throw new \InvalidArgumentException(sprintf('This access option is not allowed: "%s"', $access));
}
$expected_access = 0;
if ($access == 'allowed') {
$expected_access = 1;
}
$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_files = $private_query
->execute()
->fetchAllAssoc('fid');
foreach ($private_files as $fid => $file) {
$this
->openFileAndExpectAccess($fid, $expected_access);
}
}
}
else {
throw new \Exception(sprintf("User '%s' does not exist.", $username));
}
}