Browse Source

Check style update

Signed-off-by: Carl Schwan <carl@carlschwan.eu>
tags/v24.0.0beta1
Carl Schwan 2 years ago
parent
commit
6312c0df69
No account linked to committer's email address
49 changed files with 154 additions and 162 deletions
  1. 1
    1
      build/integration/features/bootstrap/WebDav.php
  2. 1
    1
      core/Command/Config/System/GetConfig.php
  3. 1
    1
      core/Command/Db/Migrations/ExecuteCommand.php
  4. 1
    1
      core/Command/Db/Migrations/GenerateCommand.php
  5. 1
    2
      core/Command/Upgrade.php
  6. 1
    1
      core/Command/User/Add.php
  7. 2
    2
      core/Command/User/Setting.php
  8. 1
    1
      core/Migrations/Version15000Date20180926101451.php
  9. 1
    1
      index.php
  10. 1
    1
      lib/private/Accounts/AccountManager.php
  11. 2
    2
      lib/private/AppFramework/Http/Dispatcher.php
  12. 1
    1
      lib/private/AppFramework/Http/Request.php
  13. 1
    1
      lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php
  14. 2
    2
      lib/private/BackgroundJob/JobList.php
  15. 1
    1
      lib/private/DB/Adapter.php
  16. 1
    1
      lib/private/DB/AdapterPgSql.php
  17. 1
    1
      lib/private/Files/View.php
  18. 1
    1
      lib/private/Mail/Mailer.php
  19. 1
    1
      lib/private/Memcache/Memcached.php
  20. 1
    1
      lib/private/Migration/BackgroundRepair.php
  21. 2
    2
      lib/private/Preview/MarkDown.php
  22. 1
    1
      lib/private/Preview/TXT.php
  23. 1
    1
      lib/private/Security/TrustedDomainHelper.php
  24. 1
    1
      lib/private/Setup/MySQL.php
  25. 1
    1
      lib/private/Share/Share.php
  26. 1
    1
      lib/private/Share20/DefaultShareProvider.php
  27. 1
    1
      lib/private/URLGenerator.php
  28. 1
    1
      lib/private/legacy/OC_DB.php
  29. 1
    1
      lib/private/legacy/OC_DB_StatementWrapper.php
  30. 1
    1
      lib/public/IDBConnection.php
  31. 1
    1
      ocs/providers.php
  32. 2
    2
      tests/lib/AppFramework/Db/QBMapperTest.php
  33. 8
    8
      tests/lib/AppFramework/Http/RequestTest.php
  34. 5
    5
      tests/lib/AppFramework/Middleware/CompressionMiddlewareTest.php
  35. 3
    3
      tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php
  36. 9
    9
      tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php
  37. 3
    3
      tests/lib/Avatar/UserAvatarTest.php
  38. 1
    1
      tests/lib/Cache/FileCacheTest.php
  39. 1
    2
      tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php
  40. 1
    1
      tests/lib/DateTimeFormatterTest.php
  41. 1
    1
      tests/lib/Encryption/Keys/StorageTest.php
  42. 6
    12
      tests/lib/Files/Cache/CacheTest.php
  43. 2
    2
      tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php
  44. 1
    1
      tests/lib/L10N/L10nTest.php
  45. 3
    3
      tests/lib/Mail/MessageTest.php
  46. 1
    1
      tests/lib/Security/HasherTest.php
  47. 3
    3
      tests/lib/Share20/DefaultShareProviderTest.php
  48. 62
    62
      tests/lib/Share20/ManagerTest.php
  49. 7
    7
      tests/lib/User/UserTest.php

+ 1
- 1
build/integration/features/bootstrap/WebDav.php View File

$body .= $content3."\r\n"; $body .= $content3."\r\n";
$body .= '--'.$boundary."--\r\n"; $body .= '--'.$boundary."--\r\n";


$stream = fopen('php://temp','r+');
$stream = fopen('php://temp', 'r+');
fwrite($stream, $body); fwrite($stream, $body);
rewind($stream); rewind($stream);



+ 1
- 1
core/Command/Config/System/GetConfig.php View File

* @param OutputInterface $output An OutputInterface instance * @param OutputInterface $output An OutputInterface instance
* @return int 0 if everything went fine, or an error code * @return int 0 if everything went fine, or an error code
*/ */
protected function execute(InputInterface $input, OutputInterface $output) {
protected function execute(InputInterface $input, OutputInterface $output): int {
$configNames = $input->getArgument('name'); $configNames = $input->getArgument('name');
$configName = array_shift($configNames); $configName = array_shift($configNames);
$defaultValue = $input->getOption('default-value'); $defaultValue = $input->getOption('default-value');

+ 1
- 1
core/Command/Db/Migrations/ExecuteCommand.php View File

$olderVersions = $ms->getMigratedVersions(); $olderVersions = $ms->getMigratedVersions();
$olderVersions[] = '0'; $olderVersions[] = '0';
$olderVersions[] = 'prev'; $olderVersions[] = 'prev';
if (in_array($version, $olderVersions, true)) {
if (in_array($version, $olderVersions, true)) {
$output->writeln('<error>Can not go back to previous migration without debug enabled</error>'); $output->writeln('<error>Can not go back to previous migration without debug enabled</error>');
return 1; return 1;
} }

+ 1
- 1
core/Command/Db/Migrations/GenerateCommand.php View File

$appName = $input->getArgument('app'); $appName = $input->getArgument('app');
$version = $input->getArgument('version'); $version = $input->getArgument('version');


if (!preg_match('/^\d{1,16}$/',$version)) {
if (!preg_match('/^\d{1,16}$/', $version)) {
$output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>');
return 1; return 1;
} }

+ 1
- 2
core/Command/Upgrade.php View File

$output->write('<comment>Maybe an upgrade is already in process. Please check the ' $output->write('<comment>Maybe an upgrade is already in process. Please check the '
. 'logfile (data/nextcloud.log). If you want to re-run the ' . 'logfile (data/nextcloud.log). If you want to re-run the '
. 'upgrade procedure, remove the "maintenance mode" from ' . 'upgrade procedure, remove the "maintenance mode" from '
. 'config.php and call this script again.</comment>'
, true);
. 'config.php and call this script again.</comment>', true);
return self::ERROR_MAINTENANCE_MODE; return self::ERROR_MAINTENANCE_MODE;
} else { } else {
$output->writeln('<info>Nextcloud is already latest version</info>'); $output->writeln('<info>Nextcloud is already latest version</info>');

+ 1
- 1
core/Command/User/Add.php View File



$question = new Question('Confirm password: '); $question = new Question('Confirm password: ');
$question->setHidden(true); $question->setHidden(true);
$confirm = $helper->ask($input, $output,$question);
$confirm = $helper->ask($input, $output, $question);


if ($password !== $confirm) { if ($password !== $confirm) {
$output->writeln("<error>Passwords did not match!</error>"); $output->writeln("<error>Passwords did not match!</error>");

+ 2
- 2
core/Command/User/Setting.php View File

return 1; return 1;
} }


if ($app === 'settings' && in_array($key , ['email', 'display_name'])) {
if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
$user = $this->userManager->get($uid); $user = $this->userManager->get($uid);
if ($user instanceof IUser) { if ($user instanceof IUser) {
if ($key === 'email') { if ($key === 'email') {
return 1; return 1;
} }


if ($app === 'settings' && in_array($key , ['email', 'display_name'])) {
if ($app === 'settings' && in_array($key, ['email', 'display_name'])) {
$user = $this->userManager->get($uid); $user = $this->userManager->get($uid);
if ($user instanceof IUser) { if ($user instanceof IUser) {
if ($key === 'email') { if ($key === 'email') {

+ 1
- 1
core/Migrations/Version15000Date20180926101451.php View File

$schema = $schemaClosure(); $schema = $schemaClosure();


$table = $schema->getTable('authtoken'); $table = $schema->getTable('authtoken');
$table->addColumn('password_invalid','boolean', [
$table->addColumn('password_invalid', 'boolean', [
'default' => 0, 'default' => 0,
'notnull' => false, 'notnull' => false,
]); ]);

+ 1
- 1
index.php View File

* not return a webpage, so we only print the error page when html is accepted, * not return a webpage, so we only print the error page when html is accepted,
* otherwise we reply with a JSON array like the SecurityMiddleware would do. * otherwise we reply with a JSON array like the SecurityMiddleware would do.
*/ */
if (stripos($request->getHeader('Accept'),'html') === false) {
if (stripos($request->getHeader('Accept'), 'html') === false) {
http_response_code(401); http_response_code(401);
header('Content-Type: application/json; charset=utf-8'); header('Content-Type: application/json; charset=utf-8');
echo json_encode(['message' => $ex->getMessage()]); echo json_encode(['message' => $ex->getMessage()]);

+ 1
- 1
lib/private/Accounts/AccountManager.php View File

} }


// the value col is limited to 255 bytes. It is used for searches only. // the value col is limited to 255 bytes. It is used for searches only.
$value = $property['value'] ? Util::shortenMultibyteString($property['value'], 255) : '';
$value = $property['value'] ? Util::shortenMultibyteString($property['value'], 255) : '';


$query->setParameter('name', $property['name']) $query->setParameter('name', $property['name'])
->setParameter('value', $value); ->setParameter('value', $value);

+ 2
- 2
lib/private/AppFramework/Http/Dispatcher.php View File

$numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed']; $numExecuted = $databaseStatsAfter['executed'] - $databaseStatsBefore['executed'];


if ($numBuilt > 50) { if ($numBuilt > 50) {
$this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.' , [
$this->logger->debug('Controller {class}::{method} created {count} QueryBuilder objects, please check if they are created inside a loop by accident.', [
'class' => get_class($controller), 'class' => get_class($controller),
'method' => $methodName, 'method' => $methodName,
'count' => $numBuilt, 'count' => $numBuilt,
} }


if ($numExecuted > 100) { if ($numExecuted > 100) {
$this->logger->warning('Controller {class}::{method} executed {count} queries.' , [
$this->logger->warning('Controller {class}::{method} executed {count} queries.', [
'class' => get_class($controller), 'class' => get_class($controller),
'method' => $methodName, 'method' => $methodName,
'count' => $numExecuted, 'count' => $numExecuted,

+ 1
- 1
lib/private/AppFramework/Http/Request.php View File

* @return string * @return string
*/ */
public function getHeader(string $name): string { public function getHeader(string $name): string {
$name = strtoupper(str_replace('-', '_',$name));
$name = strtoupper(str_replace('-', '_', $name));
if (isset($this->server['HTTP_' . $name])) { if (isset($this->server['HTTP_' . $name])) {
return $this->server['HTTP_' . $name]; return $this->server['HTTP_' . $name];
} }

+ 1
- 1
lib/private/AppFramework/Middleware/Security/RateLimitingMiddleware.php View File

*/ */
public function afterException($controller, $methodName, \Exception $exception) { public function afterException($controller, $methodName, \Exception $exception) {
if ($exception instanceof RateLimitExceededException) { if ($exception instanceof RateLimitExceededException) {
if (stripos($this->request->getHeader('Accept'),'html') === false) {
if (stripos($this->request->getHeader('Accept'), 'html') === false) {
$response = new DataResponse([], $exception->getCode()); $response = new DataResponse([], $exception->getCode());
} else { } else {
$response = new TemplateResponse( $response = new TemplateResponse(

+ 2
- 2
lib/private/BackgroundJob/JobList.php View File

public function resetBackgroundJob(IJob $job): void { public function resetBackgroundJob(IJob $job): void {
$query = $this->connection->getQueryBuilder(); $query = $this->connection->getQueryBuilder();
$query->update('jobs') $query->update('jobs')
->set('last_run', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->set('reserved_at', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->set('last_run', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->set('reserved_at', $query->createNamedParameter(0, IQueryBuilder::PARAM_INT))
->where($query->expr()->eq('id', $query->createNamedParameter($job->getId()), IQueryBuilder::PARAM_INT)); ->where($query->expr()->eq('id', $query->createNamedParameter($job->getId()), IQueryBuilder::PARAM_INT));
$query->executeStatement(); $query->executeStatement();
} }

+ 1
- 1
lib/private/DB/Adapter.php View File

/** /**
* @throws \OCP\DB\Exception * @throws \OCP\DB\Exception
*/ */
public function insertIgnoreConflict(string $table,array $values) : int {
public function insertIgnoreConflict(string $table, array $values) : int {
try { try {
$builder = $this->conn->getQueryBuilder(); $builder = $this->conn->getQueryBuilder();
$builder->insert($table); $builder->insert($table);

+ 1
- 1
lib/private/DB/AdapterPgSql.php View File

return $statement; return $statement;
} }


public function insertIgnoreConflict(string $table,array $values) : int {
public function insertIgnoreConflict(string $table, array $values) : int {
if ($this->isPre9_5CompatMode() === true) { if ($this->isPre9_5CompatMode() === true) {
return parent::insertIgnoreConflict($table, $values); return parent::insertIgnoreConflict($table, $values);
} }

+ 1
- 1
lib/private/Files/View.php View File

if ($result && in_array('delete', $hooks) and $result) { if ($result && in_array('delete', $hooks) and $result) {
$this->removeUpdate($storage, $internalPath); $this->removeUpdate($storage, $internalPath);
} }
if ($result && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
if ($result && in_array('write', $hooks, true) && $operation !== 'fopen' && $operation !== 'touch') {
$this->writeUpdate($storage, $internalPath); $this->writeUpdate($storage, $internalPath);
} }
if ($result && in_array('touch', $hooks)) { if ($result && in_array('touch', $hooks)) {

+ 1
- 1
lib/private/Mail/Mailer.php View File

} }


[$name, $domain] = explode('@', $email, 2); [$name, $domain] = explode('@', $email, 2);
$domain = idn_to_ascii($domain, 0,INTL_IDNA_VARIANT_UTS46);
$domain = idn_to_ascii($domain, 0, INTL_IDNA_VARIANT_UTS46);
return $name.'@'.$domain; return $name.'@'.$domain;
} }



+ 1
- 1
lib/private/Memcache/Memcached.php View File

//\Memcached::OPT_BINARY_PROTOCOL => true, //\Memcached::OPT_BINARY_PROTOCOL => true,
]; ];
// by default enable igbinary serializer if available // by default enable igbinary serializer if available
/** @psalm-suppress RedundantCondition */
/** @psalm-suppress RedundantCondition */
if (\Memcached::HAVE_IGBINARY) { if (\Memcached::HAVE_IGBINARY) {
$defaultOptions[\Memcached::OPT_SERIALIZER] = $defaultOptions[\Memcached::OPT_SERIALIZER] =
\Memcached::SERIALIZER_IGBINARY; \Memcached::SERIALIZER_IGBINARY;

+ 1
- 1
lib/private/Migration/BackgroundRepair.php View File

try { try {
$repair->addStep($step); $repair->addStep($step);
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex,[
$this->logger->logException($ex, [
'app' => 'migration' 'app' => 'migration'
]); ]);



+ 2
- 2
lib/private/Preview/MarkDown.php View File

return null; return null;
} }


$content = stream_get_contents($content,3000);
$content = stream_get_contents($content, 3000);


//don't create previews of empty text files //don't create previews of empty text files
if (trim($content) === '') { if (trim($content) === '') {
// Get rid of markdown symbols that we still needed for the font size // Get rid of markdown symbols that we still needed for the font size
$line = preg_replace('/^#*\s/', '', $line); $line = preg_replace('/^#*\s/', '', $line);


$wrappedText = wordwrap($line, $wordWrap,"\n");
$wrappedText = wordwrap($line, $wordWrap, "\n");
$linesWrapped = count(explode("\n", $wrappedText)); $linesWrapped = count(explode("\n", $wrappedText));
imagettftext($image, $actualFontSize, 0, $x, $y, $textColor, $actualFontSize === $fontSize ? $fontFile : $fontFileBold, $wrappedText); imagettftext($image, $actualFontSize, 0, $x, $y, $textColor, $actualFontSize === $fontSize ? $fontFile : $fontFileBold, $wrappedText);
$nextLineStart = (int)($linesWrapped * ceil($actualFontSize * 2)); $nextLineStart = (int)($linesWrapped * ceil($actualFontSize * 2));

+ 1
- 1
lib/private/Preview/TXT.php View File

return null; return null;
} }


$content = stream_get_contents($content,3000);
$content = stream_get_contents($content, 3000);


//don't create previews of empty text files //don't create previews of empty text files
if (trim($content) === '') { if (trim($content) === '') {

+ 1
- 1
lib/private/Security/TrustedDomainHelper.php View File

return true; return true;
} }
// Reject misformed domains in any case // Reject misformed domains in any case
if (strpos($domain,'-') === 0 || strpos($domain,'..') !== false) {
if (strpos($domain, '-') === 0 || strpos($domain, '..') !== false) {
return false; return false;
} }
// Match, allowing for * wildcards // Match, allowing for * wildcards

+ 1
- 1
lib/private/Setup/MySQL.php View File

$connection->executeUpdate($query); $connection->executeUpdate($query);
} }
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->error('Database user creation failed.',[
$this->logger->error('Database user creation failed.', [
'exception' => $ex, 'exception' => $ex,
'app' => 'mysql.setup', 'app' => 'mysql.setup',
]); ]);

+ 1
- 1
lib/private/Share/Share.php View File

* @param array $parameters additional format parameters * @param array $parameters additional format parameters
* @return array format result * @return array format result
*/ */
private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE , $parameters = null) {
private static function formatResult($items, $column, $backend, $format = self::FORMAT_NONE, $parameters = null) {
if ($format === self::FORMAT_NONE) { if ($format === self::FORMAT_NONE) {
return $items; return $items;
} elseif ($format === self::FORMAT_STATUSES) { } elseif ($format === self::FORMAT_STATUSES) {

+ 1
- 1
lib/private/Share20/DefaultShareProvider.php View File

); );
} }


$qb->innerJoin('s', 'filecache' ,'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
$qb->innerJoin('s', 'filecache', 'f', $qb->expr()->eq('s.file_source', 'f.fileid'));
$qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId()))); $qb->andWhere($qb->expr()->eq('f.parent', $qb->createNamedParameter($node->getId())));


$qb->orderBy('id'); $qb->orderBy('id');

+ 1
- 1
lib/private/URLGenerator.php View File

$theme = \OC_Util::getTheme(); $theme = \OC_Util::getTheme();


//if a theme has a png but not an svg always use the png //if a theme has a png but not an svg always use the png
$basename = substr(basename($file),0,-4);
$basename = substr(basename($file), 0, -4);


$appPath = \OC_App::getAppPath($appName); $appPath = \OC_App::getAppPath($appName);



+ 1
- 1
lib/private/legacy/OC_DB.php View File

* *
* SQL query via Doctrine prepare(), needs to be execute()'d! * SQL query via Doctrine prepare(), needs to be execute()'d!
*/ */
public static function prepare($query , $limit = null, $offset = null, $isManipulation = null) {
public static function prepare($query, $limit = null, $offset = null, $isManipulation = null) {
$connection = \OC::$server->getDatabaseConnection(); $connection = \OC::$server->getDatabaseConnection();


if ($isManipulation === null) { if ($isManipulation === null) {

+ 1
- 1
lib/private/legacy/OC_DB_StatementWrapper.php View File

/** /**
* pass all other function directly to the \Doctrine\DBAL\Driver\Statement * pass all other function directly to the \Doctrine\DBAL\Driver\Statement
*/ */
public function __call($name,$arguments) {
public function __call($name, $arguments) {
return call_user_func_array([$this->statement,$name], $arguments); return call_user_func_array([$this->statement,$name], $arguments);
} }



+ 1
- 1
lib/public/IDBConnection.php View File

* @return int number of inserted rows * @return int number of inserted rows
* @since 16.0.0 * @since 16.0.0
*/ */
public function insertIgnoreConflict(string $table,array $values) : int;
public function insertIgnoreConflict(string $table, array $values) : int;


/** /**
* Insert or update a row value * Insert or update a row value

+ 1
- 1
ocs/providers.php View File



$writer = new XMLWriter(); $writer = new XMLWriter();
$writer->openURI('php://output'); $writer->openURI('php://output');
$writer->startDocument('1.0','UTF-8');
$writer->startDocument('1.0', 'UTF-8');
$writer->setIndent(true); $writer->setIndent(true);
$writer->startElement('providers'); $writer->startElement('providers');
$writer->startElement('provider'); $writer->startElement('provider');

+ 2
- 2
tests/lib/AppFramework/Db/QBMapperTest.php View File

->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();


$this->qb = $this->getMockBuilder(IQueryBuilder:: class)
$this->qb = $this->getMockBuilder(IQueryBuilder::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();


$this->expr = $this->getMockBuilder(IExpressionBuilder:: class)
$this->expr = $this->getMockBuilder(IExpressionBuilder::class)
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();



+ 8
- 8
tests/lib/AppFramework/Http/RequestTest.php View File

$this->stream $this->stream
); );


$this->assertSame('from.server.name:8080', $request->getInsecureServerHost());
$this->assertSame('from.server.name:8080', $request->getInsecureServerHost());
} }


public function testInsecureServerHostHttpHostHeader() { public function testInsecureServerHostHttpHostHeader() {
$this->stream $this->stream
); );


$this->assertSame('from.host.header:8080', $request->getInsecureServerHost());
$this->assertSame('from.host.header:8080', $request->getInsecureServerHost());
} }


public function testInsecureServerHostHttpFromForwardedHeaderSingle() { public function testInsecureServerHostHttpFromForwardedHeaderSingle() {
$this->stream $this->stream
); );


$this->assertSame('from.forwarded.host:8080', $request->getInsecureServerHost());
$this->assertSame('from.forwarded.host:8080', $request->getInsecureServerHost());
} }


public function testInsecureServerHostHttpFromForwardedHeaderStacked() { public function testInsecureServerHostHttpFromForwardedHeaderStacked() {
$this->stream $this->stream
); );


$this->assertSame('from.forwarded.host2:8080', $request->getInsecureServerHost());
$this->assertSame('from.forwarded.host2:8080', $request->getInsecureServerHost());
} }


public function testGetServerHostWithOverwriteHost() { public function testGetServerHostWithOverwriteHost() {
$this->stream $this->stream
); );


$this->assertSame('my.overwritten.host', $request->getServerHost());
$this->assertSame('my.overwritten.host', $request->getServerHost());
} }


public function testGetServerHostWithTrustedDomain() { public function testGetServerHostWithTrustedDomain() {
$this->stream $this->stream
); );


$this->assertSame('my.trusted.host', $request->getServerHost());
$this->assertSame('my.trusted.host', $request->getServerHost());
} }


public function testGetServerHostWithUntrustedDomain() { public function testGetServerHostWithUntrustedDomain() {
$this->stream $this->stream
); );


$this->assertSame('my.trusted.host', $request->getServerHost());
$this->assertSame('my.trusted.host', $request->getServerHost());
} }


public function testGetServerHostWithNoTrustedDomain() { public function testGetServerHostWithNoTrustedDomain() {
$this->stream $this->stream
); );


$this->assertSame('', $request->getServerHost());
$this->assertSame('', $request->getServerHost());
} }


/** /**

+ 5
- 5
tests/lib/AppFramework/Middleware/CompressionMiddlewareTest.php View File

->willReturn(Http::STATUS_OK); ->willReturn(Http::STATUS_OK);


$this->middleWare->beforeController($this->controller, 'myMethod'); $this->middleWare->beforeController($this->controller, 'myMethod');
$this->middleWare->afterController($this->controller,'myMethod', $response);
$this->middleWare->afterController($this->controller, 'myMethod', $response);


$output = 'myoutput'; $output = 'myoutput';
$result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output); $result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output);
->willReturn(Http::STATUS_OK); ->willReturn(Http::STATUS_OK);


$this->middleWare->beforeController($this->controller, 'myMethod'); $this->middleWare->beforeController($this->controller, 'myMethod');
$this->middleWare->afterController($this->controller,'myMethod', $response);
$this->middleWare->afterController($this->controller, 'myMethod', $response);


$output = 'myoutput'; $output = 'myoutput';
$result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output); $result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output);
->willReturn(Http::STATUS_OK); ->willReturn(Http::STATUS_OK);


$this->middleWare->beforeController($this->controller, 'myMethod'); $this->middleWare->beforeController($this->controller, 'myMethod');
$this->middleWare->afterController($this->controller,'myMethod', $response);
$this->middleWare->afterController($this->controller, 'myMethod', $response);


$output = 'myoutput'; $output = 'myoutput';
$result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output); $result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output);
$response->method('getStatus') $response->method('getStatus')
->willReturn(Http::STATUS_OK); ->willReturn(Http::STATUS_OK);
$this->middleWare->beforeController($this->controller, 'myMethod'); $this->middleWare->beforeController($this->controller, 'myMethod');
$this->middleWare->afterController($this->controller,'myMethod', $response);
$this->middleWare->afterController($this->controller, 'myMethod', $response);


$output = 'myoutput'; $output = 'myoutput';
$result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output); $result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output);
->willReturn(Http::STATUS_NOT_FOUND); ->willReturn(Http::STATUS_NOT_FOUND);


$this->middleWare->beforeController($this->controller, 'myMethod'); $this->middleWare->beforeController($this->controller, 'myMethod');
$this->middleWare->afterController($this->controller,'myMethod', $response);
$this->middleWare->afterController($this->controller, 'myMethod', $response);


$output = 'myoutput'; $output = 'myoutput';
$result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output); $result = $this->middleWare->beforeOutput($this->controller, 'myMethod', $output);

+ 3
- 3
tests/lib/AppFramework/Middleware/Security/BruteForceMiddlewareTest.php View File



/** @var Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ /** @var Controller|\PHPUnit\Framework\MockObject\MockObject $controller */
$controller = $this->createMock(Controller::class); $controller = $this->createMock(Controller::class);
$this->bruteForceMiddleware->afterController($controller, 'testMethod' ,$response);
$this->bruteForceMiddleware->afterController($controller, 'testMethod', $response);
} }


public function testAfterControllerWithAnnotationAndNotThrottledRequest() { public function testAfterControllerWithAnnotationAndNotThrottledRequest() {


/** @var Controller|\PHPUnit\Framework\MockObject\MockObject $controller */ /** @var Controller|\PHPUnit\Framework\MockObject\MockObject $controller */
$controller = $this->createMock(Controller::class); $controller = $this->createMock(Controller::class);
$this->bruteForceMiddleware->afterController($controller, 'testMethod' ,$response);
$this->bruteForceMiddleware->afterController($controller, 'testMethod', $response);
} }


public function testAfterControllerWithoutAnnotation() { public function testAfterControllerWithoutAnnotation() {
$controller = $this->createMock(Controller::class); $controller = $this->createMock(Controller::class);
/** @var Response|\PHPUnit\Framework\MockObject\MockObject $response */ /** @var Response|\PHPUnit\Framework\MockObject\MockObject $response */
$response = $this->createMock(Response::class); $response = $this->createMock(Response::class);
$this->bruteForceMiddleware->afterController($controller, 'testMethod' ,$response);
$this->bruteForceMiddleware->afterController($controller, 'testMethod', $response);
} }
} }

+ 9
- 9
tests/lib/AppFramework/Middleware/Security/SecurityMiddlewareTest.php View File

* @SubAdminRequired * @SubAdminRequired
*/ */
public function testIsNotSubAdminCheck() { public function testIsNotSubAdminCheck() {
$this->reader->reflect(__CLASS__,__FUNCTION__);
$this->reader->reflect(__CLASS__, __FUNCTION__);
$sec = $this->getMiddleware(true, false, false); $sec = $this->getMiddleware(true, false, false);


$this->expectException(SecurityException::class); $this->expectException(SecurityException::class);
* @SubAdminRequired * @SubAdminRequired
*/ */
public function testIsSubAdminCheck() { public function testIsSubAdminCheck() {
$this->reader->reflect(__CLASS__,__FUNCTION__);
$this->reader->reflect(__CLASS__, __FUNCTION__);
$sec = $this->getMiddleware(true, false, true); $sec = $this->getMiddleware(true, false, true);


$sec->beforeController($this, __METHOD__); $sec->beforeController($this, __METHOD__);
* @SubAdminRequired * @SubAdminRequired
*/ */
public function testIsSubAdminAndAdminCheck() { public function testIsSubAdminAndAdminCheck() {
$this->reader->reflect(__CLASS__,__FUNCTION__);
$this->reader->reflect(__CLASS__, __FUNCTION__);
$sec = $this->getMiddleware(true, true, true); $sec = $this->getMiddleware(true, true, true);


$sec->beforeController($this, __METHOD__); $sec->beforeController($this, __METHOD__);
new NotLoggedInException() new NotLoggedInException()
); );
$expected = new RedirectResponse('http://localhost/nextcloud/index.php/login?redirect_url=nextcloud/index.php/apps/specialapp'); $expected = new RedirectResponse('http://localhost/nextcloud/index.php/login?redirect_url=nextcloud/index.php/apps/specialapp');
$this->assertEquals($expected , $response);
$this->assertEquals($expected, $response);
} }


public function testAfterExceptionRedirectsToWebRootAfterStrictCookieFail() { public function testAfterExceptionRedirectsToWebRootAfterStrictCookieFail() {
); );


$expected = new RedirectResponse(\OC::$WEBROOT . '/'); $expected = new RedirectResponse(\OC::$WEBROOT . '/');
$this->assertEquals($expected , $response);
$this->assertEquals($expected, $response);
} }




); );
$expected = new TemplateResponse('core', '403', ['message' => $exception->getMessage()], 'guest'); $expected = new TemplateResponse('core', '403', ['message' => $exception->getMessage()], 'guest');
$expected->setStatus($exception->getCode()); $expected->setStatus($exception->getCode());
$this->assertEquals($expected , $response);
$this->assertEquals($expected, $response);
} }


public function testAfterAjaxExceptionReturnsJSONError() { public function testAfterAjaxExceptionReturnsJSONError() {
*/ */
public function testRestrictedAppLoggedInPublicPage() { public function testRestrictedAppLoggedInPublicPage() {
$middleware = $this->getMiddleware(true, false, false); $middleware = $this->getMiddleware(true, false, false);
$this->reader->reflect(__CLASS__,__FUNCTION__);
$this->reader->reflect(__CLASS__, __FUNCTION__);


$this->appManager->method('getAppPath') $this->appManager->method('getAppPath')
->with('files') ->with('files')
*/ */
public function testRestrictedAppNotLoggedInPublicPage() { public function testRestrictedAppNotLoggedInPublicPage() {
$middleware = $this->getMiddleware(false, false, false); $middleware = $this->getMiddleware(false, false, false);
$this->reader->reflect(__CLASS__,__FUNCTION__);
$this->reader->reflect(__CLASS__, __FUNCTION__);


$this->appManager->method('getAppPath') $this->appManager->method('getAppPath')
->with('files') ->with('files')
*/ */
public function testRestrictedAppLoggedIn() { public function testRestrictedAppLoggedIn() {
$middleware = $this->getMiddleware(true, false, false, false); $middleware = $this->getMiddleware(true, false, false, false);
$this->reader->reflect(__CLASS__,__FUNCTION__);
$this->reader->reflect(__CLASS__, __FUNCTION__);


$this->appManager->method('getAppPath') $this->appManager->method('getAppPath')
->with('files') ->with('files')

+ 3
- 3
tests/lib/Avatar/UserAvatarTest.php View File

} }


public function testMixPalette() { public function testMixPalette() {
$colorFrom = new \OC\Color(0,0,0);
$colorTo = new \OC\Color(6,12,18);
$colorFrom = new \OC\Color(0, 0, 0);
$colorTo = new \OC\Color(6, 12, 18);
$steps = 6; $steps = 6;
$palette = $this->invokePrivate($this->avatar, 'mixPalette', [$steps, $colorFrom, $colorTo]); $palette = $this->invokePrivate($this->avatar, 'mixPalette', [$steps, $colorFrom, $colorTo]);
foreach ($palette as $j => $color) { foreach ($palette as $j => $color) {
$incG = $colorTo->g / $steps * $j; $incG = $colorTo->g / $steps * $j;
$incB = $colorTo->b / $steps * $j; $incB = $colorTo->b / $steps * $j;
// ensure everything is equal // ensure everything is equal
$this->assertEquals($color, new \OC\Color($incR, $incG,$incB));
$this->assertEquals($color, new \OC\Color($incR, $incG, $incB));
} }
$hashToInt = $this->invokePrivate($this->avatar, 'hashToInt', ['abcdef', 18]); $hashToInt = $this->invokePrivate($this->avatar, 'hashToInt', ['abcdef', 18]);
$this->assertTrue(gettype($hashToInt) === 'integer'); $this->assertTrue(gettype($hashToInt) === 'integer');

+ 1
- 1
tests/lib/Cache/FileCacheTest.php View File

$this->storage = \OC\Files\Filesystem::getStorage('/'); $this->storage = \OC\Files\Filesystem::getStorage('/');
\OC\Files\Filesystem::clearMounts(); \OC\Files\Filesystem::clearMounts();
$storage = new \OC\Files\Storage\Temporary([]); $storage = new \OC\Files\Storage\Temporary([]);
\OC\Files\Filesystem::mount($storage,[],'/');
\OC\Files\Filesystem::mount($storage, [], '/');
$datadir = str_replace('local::', '', $storage->getId()); $datadir = str_replace('local::', '', $storage->getId());
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT.'/data/cache'); $this->datadir = $config->getSystemValue('cachedirectory', \OC::$SERVERROOT.'/data/cache');

+ 1
- 2
tests/lib/DB/QueryBuilder/ExpressionBuilderDBTest.php View File

$query->createFunction( $query->createFunction(
'(' . $query->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT) '(' . $query->expr()->castColumn('configvalue', IQueryBuilder::PARAM_INT)
. ' + 1)' . ' + 1)'
)
, IQueryBuilder::PARAM_STR
), IQueryBuilder::PARAM_STR
) )
) )
->where($query->expr()->eq('appid', $query->createNamedParameter($appId))) ->where($query->expr()->eq('appid', $query->createNamedParameter($appId)))

+ 1
- 1
tests/lib/DateTimeFormatterTest.php View File

['in 2 years', $time, $this->getTimestampAgo($time, 0, 0, 0, 0, 2)], ['in 2 years', $time, $this->getTimestampAgo($time, 0, 0, 0, 0, 2)],


// Test with compare timestamp // Test with compare timestamp
['today', $this->getTimestampAgo($time, 0, 0, 0, 0, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)],
['today', $this->getTimestampAgo($time, 0, 0, 0, 0, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)],
['yesterday', $this->getTimestampAgo($time, 30, 15, 3, 1, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)], ['yesterday', $this->getTimestampAgo($time, 30, 15, 3, 1, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)],
['4 days ago', $this->getTimestampAgo($time, 30, 15, 3, 4, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)], ['4 days ago', $this->getTimestampAgo($time, 30, 15, 3, 4, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)],
['5 months ago', $this->getTimestampAgo($time, 30, 15, 3, 155, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)], ['5 months ago', $this->getTimestampAgo($time, 30, 15, 3, 155, 1), $this->getTimestampAgo($time, 0, 0, 0, 0, 1)],

+ 1
- 1
tests/lib/Encryption/Keys/StorageTest.php View File

/** /**
* @dataProvider dataProviderCopyRename * @dataProvider dataProviderCopyRename
*/ */
public function testCopyKeys($source, $target, $systemWideMountSource, $systemWideMountTarget , $expectedSource, $expectedTarget) {
public function testCopyKeys($source, $target, $systemWideMountSource, $systemWideMountTarget, $expectedSource, $expectedTarget) {
$this->view->expects($this->any()) $this->view->expects($this->any())
->method('file_exists') ->method('file_exists')
->willReturn(true); ->willReturn(true);

+ 6
- 12
tests/lib/Files/Cache/CacheTest.php View File

$user = $this->createMock(IUser::class); $user = $this->createMock(IUser::class);


$this->assertCount(1, $this->cache->searchQuery(new SearchQuery( $this->assertCount(1, $this->cache->searchQuery(new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo')
, 10, 0, [], $user)));
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'name', 'foo'), 10, 0, [], $user)));
$this->assertCount(2, $this->cache->searchQuery(new SearchQuery( $this->assertCount(2, $this->cache->searchQuery(new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%')
, 10, 0, [], $user)));
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'name', 'foo%'), 10, 0, [], $user)));
$this->assertCount(2, $this->cache->searchQuery(new SearchQuery( $this->assertCount(2, $this->cache->searchQuery(new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'foo/file')
, 10, 0, [], $user)));
new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'mimetype', 'foo/file'), 10, 0, [], $user)));
$this->assertCount(3, $this->cache->searchQuery(new SearchQuery( $this->assertCount(3, $this->cache->searchQuery(new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'foo/%')
, 10, 0, [], $user)));
new SearchComparison(ISearchComparison::COMPARE_LIKE, 'mimetype', 'foo/%'), 10, 0, [], $user)));
$this->assertCount(1, $this->cache->searchQuery(new SearchQuery( $this->assertCount(1, $this->cache->searchQuery(new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'size', 100)
, 10, 0, [], $user)));
new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN, 'size', 100), 10, 0, [], $user)));
$this->assertCount(2, $this->cache->searchQuery(new SearchQuery( $this->assertCount(2, $this->cache->searchQuery(new SearchQuery(
new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100)
, 10, 0, [], $user)));
new SearchComparison(ISearchComparison::COMPARE_GREATER_THAN_EQUAL, 'size', 100), 10, 0, [], $user)));
} }


public function movePathProvider() { public function movePathProvider() {

+ 2
- 2
tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php View File

*/ */
public function testMove($source, $target) { public function testMove($source, $target) {
$this->initSourceAndTarget($source); $this->initSourceAndTarget($source);
$sourceId = $this->instance->getCache()->getId(ltrim('/',$source));
$sourceId = $this->instance->getCache()->getId(ltrim('/', $source));
$this->assertNotEquals(-1, $sourceId); $this->assertNotEquals(-1, $sourceId);


$this->instance->rename($source, $target); $this->instance->rename($source, $target);
$this->assertFalse($this->instance->file_exists($source), $source.' still exists'); $this->assertFalse($this->instance->file_exists($source), $source.' still exists');
$this->assertSameAsLorem($target); $this->assertSameAsLorem($target);


$targetId = $this->instance->getCache()->getId(ltrim('/',$target));
$targetId = $this->instance->getCache()->getId(ltrim('/', $target));
$this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break'); $this->assertSame($sourceId, $targetId, 'fileid must be stable on move or shares will break');
} }



+ 1
- 1
tests/lib/L10N/L10nTest.php View File



public function testRussianPluralTranslations() { public function testRussianPluralTranslations() {
$transFile = \OC::$SERVERROOT.'/tests/data/l10n/ru.json'; $transFile = \OC::$SERVERROOT.'/tests/data/l10n/ru.json';
$l = new L10N($this->getFactory(), 'test', 'ru', 'ru_UA',[$transFile]);
$l = new L10N($this->getFactory(), 'test', 'ru', 'ru_UA', [$transFile]);


$this->assertEquals('1 файл', (string)$l->n('%n file', '%n files', 1)); $this->assertEquals('1 файл', (string)$l->n('%n file', '%n files', 1));
$this->assertEquals('2 файла', (string)$l->n('%n file', '%n files', 2)); $this->assertEquals('2 файла', (string)$l->n('%n file', '%n files', 2));

+ 3
- 3
tests/lib/Mail/MessageTest.php View File

/** /**
* @dataProvider getMailAddressProvider * @dataProvider getMailAddressProvider
*/ */
public function testGetTo($swiftresult,$return) {
public function testGetTo($swiftresult, $return) {
$this->swiftMessage $this->swiftMessage
->expects($this->once()) ->expects($this->once())
->method('getTo') ->method('getTo')
/** /**
* @dataProvider getMailAddressProvider * @dataProvider getMailAddressProvider
*/ */
public function testGetCc($swiftresult,$return) {
public function testGetCc($swiftresult, $return) {
$this->swiftMessage $this->swiftMessage
->expects($this->once()) ->expects($this->once())
->method('getCc') ->method('getCc')
/** /**
* @dataProvider getMailAddressProvider * @dataProvider getMailAddressProvider
*/ */
public function testGetBcc($swiftresult,$return) {
public function testGetBcc($swiftresult, $return) {
$this->swiftMessage $this->swiftMessage
->expects($this->once()) ->expects($this->once())
->method('getBcc') ->method('getBcc')

+ 1
- 1
tests/lib/Security/HasherTest.php View File

} }




$this->assertTrue($this->hasher->verify($message, $blowfish,$newHash));
$this->assertTrue($this->hasher->verify($message, $blowfish, $newHash));
$this->assertTrue($this->hasher->verify($message, $argon2)); $this->assertTrue($this->hasher->verify($message, $argon2));


$relativePath = self::invokePrivate($this->hasher, 'splitHash', [$newHash]); $relativePath = self::invokePrivate($this->hasher, 'splitHash', [$newHash]);

+ 3
- 3
tests/lib/Share20/DefaultShareProviderTest.php View File

$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId)->willReturn([$file]); $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);


$share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_USER, null, 1 , 0);
$share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_USER, null, 1, 0);
$this->assertCount(1, $share); $this->assertCount(1, $share);


$share = $share[0]; $share = $share[0];
$this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf(); $this->rootFolder->method('getUserFolder')->with('shareOwner')->willReturnSelf();
$this->rootFolder->method('getById')->with($fileId)->willReturn([$file]); $this->rootFolder->method('getById')->with($fileId)->willReturn([$file]);


$share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_GROUP, null, 20 , 1);
$share = $this->provider->getSharedWith('sharedWith', IShare::TYPE_GROUP, null, 20, 1);
$this->assertCount(1, $share); $this->assertCount(1, $share);


$share = $share[0]; $share = $share[0];
]); ]);
$this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups); $this->groupManager->method('getUserGroupIds')->with($user)->willReturn($groups);


$share = $this->provider->getSharedWith('sharedWith', $shareType, null, 1 , 0);
$share = $this->provider->getSharedWith('sharedWith', $shareType, null, 1, 0);
$this->assertCount(0, $share); $this->assertCount(0, $share);
} }



+ 62
- 62
tests/lib/Share20/ManagerTest.php View File

->getMock(); ->getMock();


$date = new \DateTime(); $date = new \DateTime();
$date->setTime(0,0,0);
$date->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($date) $share->setExpirationDate($date)
->willReturn($storage); ->willReturn($storage);


$data = [ $data = [
[$this->createShare(null, IShare::TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
[$this->createShare(null, IShare::TYPE_USER, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
[$this->createShare(null, IShare::TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
[$this->createShare(null, IShare::TYPE_USER, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
[$this->createShare(null, IShare::TYPE_USER, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
[$this->createShare(null, IShare::TYPE_USER, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid user', true],
[$this->createShare(null, IShare::TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true], [$this->createShare(null, IShare::TYPE_GROUP, $file, null, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
[$this->createShare(null, IShare::TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true], [$this->createShare(null, IShare::TYPE_GROUP, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
[$this->createShare(null, IShare::TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true], [$this->createShare(null, IShare::TYPE_GROUP, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith is not a valid group', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, $user2, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, $group0, $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, 'foo@bar.com', $user0, $user0, 31, null, null), 'SharedWith should be empty', true],
[$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'unknown share type', true], [$this->createShare(null, -1, $file, null, $user0, $user0, 31, null, null), 'unknown share type', true],


[$this->createShare(null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'SharedBy should be set', true],
[$this->createShare(null, IShare::TYPE_USER, $file, $user2, null, $user0, 31, null, null), 'SharedBy should be set', true],
[$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true], [$this->createShare(null, IShare::TYPE_GROUP, $file, $group0, null, $user0, 31, null, null), 'SharedBy should be set', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true],
[$this->createShare(null, IShare::TYPE_LINK, $file, null, null, $user0, 31, null, null), 'SharedBy should be set', true],


[$this->createShare(null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Cannot share with yourself', true],
[$this->createShare(null, IShare::TYPE_USER, $file, $user0, $user0, $user0, 31, null, null), 'Cannot share with yourself', true],


[$this->createShare(null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true],
[$this->createShare(null, IShare::TYPE_USER, null, $user2, $user0, $user0, 31, null, null), 'Path should be set', true],
[$this->createShare(null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true], [$this->createShare(null, IShare::TYPE_GROUP, null, $group0, $user0, $user0, 31, null, null), 'Path should be set', true],
[$this->createShare(null, IShare::TYPE_LINK, null, null, $user0, $user0, 31, null, null), 'Path should be set', true],
[$this->createShare(null, IShare::TYPE_LINK, null, null, $user0, $user0, 31, null, null), 'Path should be set', true],


[$this->createShare(null, IShare::TYPE_USER, $node, $user2, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
[$this->createShare(null, IShare::TYPE_USER, $node, $user2, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
[$this->createShare(null, IShare::TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true], [$this->createShare(null, IShare::TYPE_GROUP, $node, $group0, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
[$this->createShare(null, IShare::TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
[$this->createShare(null, IShare::TYPE_LINK, $node, null, $user0, $user0, 31, null, null), 'Path should be either a file or a folder', true],
]; ];


$nonShareAble = $this->createMock(Folder::class); $nonShareAble = $this->createMock(Folder::class);
$nonShareAble->method('getStorage') $nonShareAble->method('getStorage')
->willReturn($storage); ->willReturn($storage);


$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonShareAble, $user2, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share name', true]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonShareAble, $group0, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $nonShareAble, null, $user0, $user0, 31, null, null), 'You are not allowed to share name', true];


$limitedPermssions = $this->createMock(File::class); $limitedPermssions = $this->createMock(File::class);
$limitedPermssions->method('isShareable')->willReturn(true); $limitedPermssions->method('isShareable')->willReturn(true);
$limitedPermssions->method('getStorage') $limitedPermssions->method('getStorage')
->willReturn($storage); ->willReturn($storage);


$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null), 'A share requires permissions', true];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, null, null, null), 'A share requires permissions', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, null, null, null), 'A share requires permissions', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, null, null, null), 'A share requires permissions', true];


$mount = $this->createMock(MoveableMount::class); $mount = $this->createMock(MoveableMount::class);
$limitedPermssions->method('getMountPoint')->willReturn($mount); $limitedPermssions->method('getMountPoint')->willReturn($mount);




$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $limitedPermssions, $user2, $user0, $user0, 31, null, null), 'Cannot increase permissions of path', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $limitedPermssions, $group0, $user0, $user0, 17, null, null), 'Cannot increase permissions of path', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $limitedPermssions, null, $user0, $user0, 3, null, null), 'Cannot increase permissions of path', true];


$nonMoveableMountPermssions = $this->createMock(Folder::class); $nonMoveableMountPermssions = $this->createMock(Folder::class);
$nonMoveableMountPermssions->method('isShareable')->willReturn(true); $nonMoveableMountPermssions->method('isShareable')->willReturn(true);
$nonMoveableMountPermssions->method('getStorage') $nonMoveableMountPermssions->method('getStorage')
->willReturn($storage); ->willReturn($storage);


$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $nonMoveableMountPermssions, $user2, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $nonMoveableMountPermssions, $group0, $user0, $user0, 11, null, null), 'Cannot increase permissions of path', false];


$rootFolder = $this->createMock(Folder::class); $rootFolder = $this->createMock(Folder::class);
$rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL); $rootFolder->method('getPermissions')->willReturn(\OCP\Constants::PERMISSION_ALL);
$rootFolder->method('getId')->willReturn(42); $rootFolder->method('getId')->willReturn(42);


$data[] = [$this->createShare(null, IShare::TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You cannot share your root folder', true];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $rootFolder, $user2, $user0, $user0, 30, null, null), 'You cannot share your root folder', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You cannot share your root folder', true]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $rootFolder, $group0, $user0, $user0, 2, null, null), 'You cannot share your root folder', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You cannot share your root folder', true];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $rootFolder, null, $user0, $user0, 16, null, null), 'You cannot share your root folder', true];


$allPermssions = $this->createMock(Folder::class); $allPermssions = $this->createMock(Folder::class);
$allPermssions->method('isShareable')->willReturn(true); $allPermssions->method('isShareable')->willReturn(true);
$allPermssions->method('getStorage') $allPermssions->method('getStorage')
->willReturn($storage); ->willReturn($storage);


$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 30, null, null), 'Shares need at least read permissions', true];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 30, null, null), 'Shares need at least read permissions', true];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null), 'Shares need at least read permissions', true]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 2, null, null), 'Shares need at least read permissions', true];


$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 31, null, null), null, false];
$data[] = [$this->createShare(null, IShare::TYPE_USER, $allPermssions, $user2, $user0, $user0, 31, null, null), null, false];
$data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null), null, false]; $data[] = [$this->createShare(null, IShare::TYPE_GROUP, $allPermssions, $group0, $user0, $user0, 3, null, null), null, false];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, 17, null, null), null, false];
$data[] = [$this->createShare(null, IShare::TYPE_LINK, $allPermssions, null, $user0, $user0, 17, null, null), null, false];




$remoteStorage = $this->createMock(Storage\IStorage::class); $remoteStorage = $this->createMock(Storage\IStorage::class);
} }


$expected = new \DateTime(); $expected = new \DateTime();
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);
$expected->add(new \DateInterval('P3D')); $expected->add(new \DateInterval('P3D'));


self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
} }


$expected = new \DateTime(); $expected = new \DateTime();
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);
$expected->add(new \DateInterval('P1D')); $expected->add(new \DateInterval('P1D'));


self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]); self::invokePrivate($this->manager, 'validateExpirationDateInternal', [$share]);
public function testValidateExpirationDateInternalEnforceValid($shareType) { public function testValidateExpirationDateInternalEnforceValid($shareType) {
$future = new \DateTime(); $future = new \DateTime();
$future->add(new \DateInterval('P2D')); $future->add(new \DateInterval('P2D'));
$future->setTime(1,2,3);
$future->setTime(1, 2, 3);


$expected = clone $future; $expected = clone $future;
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setShareType($shareType); $share->setShareType($shareType);
public function testValidateExpirationDateInternalNoDefault($shareType) { public function testValidateExpirationDateInternalNoDefault($shareType) {
$date = new \DateTime(); $date = new \DateTime();
$date->add(new \DateInterval('P5D')); $date->add(new \DateInterval('P5D'));
$date->setTime(1,2,3);
$date->setTime(1, 2, 3);


$expected = clone $date; $expected = clone $date;
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setShareType($shareType); $share->setShareType($shareType);


$expected = new \DateTime(); $expected = new \DateTime();
$expected->add(new \DateInterval('P3D')); $expected->add(new \DateInterval('P3D'));
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


if ($shareType === IShare::TYPE_USER) { if ($shareType === IShare::TYPE_USER) {
$this->config->method('getAppValue') $this->config->method('getAppValue')
public function testValidateExpirationDateInternalDefault($shareType) { public function testValidateExpirationDateInternalDefault($shareType) {
$future = new \DateTime(); $future = new \DateTime();
$future->add(new \DateInterval('P5D')); $future->add(new \DateInterval('P5D'));
$future->setTime(1,2,3);
$future->setTime(1, 2, 3);


$expected = clone $future; $expected = clone $future;
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setShareType($shareType); $share->setShareType($shareType);
public function testValidateExpirationDateInternalHookModification($shareType) { public function testValidateExpirationDateInternalHookModification($shareType) {
$nextWeek = new \DateTime(); $nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D')); $nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
$nextWeek->setTime(0, 0, 0);


$save = clone $nextWeek; $save = clone $nextWeek;




$nextWeek = new \DateTime(); $nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D')); $nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
$nextWeek->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setShareType($shareType); $share->setShareType($shareType);
]); ]);


$expected = new \DateTime(); $expected = new \DateTime();
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);
$expected->add(new \DateInterval('P3D')); $expected->add(new \DateInterval('P3D'));


self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
]); ]);


$expected = new \DateTime(); $expected = new \DateTime();
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);
$expected->add(new \DateInterval('P1D')); $expected->add(new \DateInterval('P1D'));


self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]); self::invokePrivate($this->manager, 'validateExpirationDateLink', [$share]);
public function testValidateExpirationDateEnforceValid() { public function testValidateExpirationDateEnforceValid() {
$future = new \DateTime(); $future = new \DateTime();
$future->add(new \DateInterval('P2D')); $future->add(new \DateInterval('P2D'));
$future->setTime(1,2,3);
$future->setTime(1, 2, 3);


$expected = clone $future; $expected = clone $future;
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($future); $share->setExpirationDate($future);
public function testValidateExpirationDateNoDefault() { public function testValidateExpirationDateNoDefault() {
$date = new \DateTime(); $date = new \DateTime();
$date->add(new \DateInterval('P5D')); $date->add(new \DateInterval('P5D'));
$date->setTime(1,2,3);
$date->setTime(1, 2, 3);


$expected = clone $date; $expected = clone $date;
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($date); $share->setExpirationDate($date);


$expected = new \DateTime(); $expected = new \DateTime();
$expected->add(new \DateInterval('P3D')); $expected->add(new \DateInterval('P3D'));
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$this->config->method('getAppValue') $this->config->method('getAppValue')
->willReturnMap([ ->willReturnMap([
public function testValidateExpirationDateDefault() { public function testValidateExpirationDateDefault() {
$future = new \DateTime(); $future = new \DateTime();
$future->add(new \DateInterval('P5D')); $future->add(new \DateInterval('P5D'));
$future->setTime(1,2,3);
$future->setTime(1, 2, 3);


$expected = clone $future; $expected = clone $future;
$expected->setTime(0,0,0);
$expected->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($future); $share->setExpirationDate($future);
public function testValidateExpirationDateHookModification() { public function testValidateExpirationDateHookModification() {
$nextWeek = new \DateTime(); $nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D')); $nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
$nextWeek->setTime(0, 0, 0);


$save = clone $nextWeek; $save = clone $nextWeek;




$nextWeek = new \DateTime(); $nextWeek = new \DateTime();
$nextWeek->add(new \DateInterval('P7D')); $nextWeek->add(new \DateInterval('P7D'));
$nextWeek->setTime(0,0,0);
$nextWeek->setTime(0, 0, 0);


$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($nextWeek); $share->setExpirationDate($nextWeek);
} }


$today = new \DateTime(); $today = new \DateTime();
$today->setTime(0,0,0);
$today->setTime(0, 0, 0);


/* /*
* Set the expiration date to today for some shares * Set the expiration date to today for some shares
->getMock(); ->getMock();


$date = new \DateTime(); $date = new \DateTime();
$date->setTime(0,0,0);
$date->setTime(0, 0, 0);
$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($date); $share->setExpirationDate($date);


->willReturn('yes'); ->willReturn('yes');


$date = new \DateTime(); $date = new \DateTime();
$date->setTime(0,0,0);
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P2D')); $date->add(new \DateInterval('P2D'));
$share = $this->manager->newShare(); $share = $this->manager->newShare();
$share->setExpirationDate($date); $share->setExpirationDate($date);
->setPermissions(15); ->setPermissions(15);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setPermissions(15); ->setPermissions(15);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setPermissions(\OCP\Constants::PERMISSION_ALL); ->setPermissions(\OCP\Constants::PERMISSION_ALL);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(false); ->setSendPasswordByTalk(false);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(false); ->setSendPasswordByTalk(false);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(false); ->setSendPasswordByTalk(false);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(false); ->setSendPasswordByTalk(false);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(false); ->setSendPasswordByTalk(false);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(false); ->setSendPasswordByTalk(false);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(true); ->setSendPasswordByTalk(true);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);
->setSendPasswordByTalk(true); ->setSendPasswordByTalk(true);


$tomorrow = new \DateTime(); $tomorrow = new \DateTime();
$tomorrow->setTime(0,0,0);
$tomorrow->setTime(0, 0, 0);
$tomorrow->add(new \DateInterval('P1D')); $tomorrow->add(new \DateInterval('P1D'));


$file = $this->createMock(File::class); $file = $this->createMock(File::class);

+ 7
- 7
tests/lib/User/UserTest.php View File

}); });


$user = new User('foo', $backend, $this->dispatcher); $user = new User('foo', $backend, $this->dispatcher);
$this->assertTrue($user->setPassword('bar',''));
$this->assertTrue($user->setPassword('bar', ''));
} }


public function testSetPasswordNotSupported() { public function testSetPasswordNotSupported() {
->willReturn(false); ->willReturn(false);


$user = new User('foo', $backend, $this->dispatcher); $user = new User('foo', $backend, $this->dispatcher);
$this->assertFalse($user->setPassword('bar',''));
$this->assertFalse($user->setPassword('bar', ''));
} }


public function testChangeAvatarSupportedYes() { public function testChangeAvatarSupportedYes() {


$backend->expects($this->once()) $backend->expects($this->once())
->method('setDisplayName') ->method('setDisplayName')
->with('foo','Foo')
->with('foo', 'Foo')
->willReturn(true); ->willReturn(true);


$user = new User('foo', $backend, $this->dispatcher); $user = new User('foo', $backend, $this->dispatcher);
$this->assertTrue($user->setDisplayName('Foo')); $this->assertTrue($user->setDisplayName('Foo'));
$this->assertEquals('Foo',$user->getDisplayName());
$this->assertEquals('Foo', $user->getDisplayName());
} }


/** /**


$user = new User('foo', $backend, $this->dispatcher); $user = new User('foo', $backend, $this->dispatcher);
$this->assertFalse($user->setDisplayName(' ')); $this->assertFalse($user->setDisplayName(' '));
$this->assertEquals('foo',$user->getDisplayName());
$this->assertEquals('foo', $user->getDisplayName());
} }


public function testSetDisplayNameNotSupported() { public function testSetDisplayNameNotSupported() {


$user = new User('foo', $backend, $this->dispatcher); $user = new User('foo', $backend, $this->dispatcher);
$this->assertFalse($user->setDisplayName('Foo')); $this->assertFalse($user->setDisplayName('Foo'));
$this->assertEquals('foo',$user->getDisplayName());
$this->assertEquals('foo', $user->getDisplayName());
} }


public function testSetPasswordHooks() { public function testSetPasswordHooks() {


$user = new User('foo', $backend, $this->dispatcher, $emitter); $user = new User('foo', $backend, $this->dispatcher, $emitter);


$user->setPassword('bar','');
$user->setPassword('bar', '');
$this->assertEquals(2, $hooksCalled); $this->assertEquals(2, $hooksCalled);
} }



Loading…
Cancel
Save