Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions apps/updatenotification/tests/ResetTokenBackgroundJobTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -65,13 +65,11 @@ public function testRunWithNotExpiredToken() {

public function testRunWithExpiredToken() {
$this->timeFactory
->expects($this->at(0))
->method('getTime')
->willReturn(1455131633);
$this->timeFactory
->expects($this->at(1))
->method('getTime')
->willReturn(1455045234);
->willReturnOnConsecutiveCalls(
1455131633,
1455045234
);
$this->config
->expects($this->once())
->method('getAppValue')
Expand Down
38 changes: 22 additions & 16 deletions apps/updatenotification/tests/Settings/AdminTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -29,20 +29,26 @@
*/
namespace OCA\UpdateNotification\Tests\Settings;

use OC\User\Backend;
use OCA\UpdateNotification\Settings\Admin;
use OCA\UpdateNotification\UpdateChecker;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IDateTimeFormatter;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IUserManager;
use OCP\L10N\IFactory;
use OCP\L10N\ILanguageIterator;
use OCP\Support\Subscription\IRegistry;
use OCP\User\Backend\ICountUsersBackend;
use OCP\UserInterface;
use OCP\Util;
use Test\TestCase;
use OCP\IUserManager;
use Psr\Log\LoggerInterface;
use Test\TestCase;

interface UserInterfaceAwareICountUsersBackend extends UserInterface, ICountUsersBackend {
}

class AdminTest extends TestCase {
/** @var IFactory|\PHPUnit\Framework\MockObject\MockObject */
Expand DownExpand Up@@ -77,21 +83,21 @@ protected function setUp(): void {
$this->logger = $this->createMock(LoggerInterface::class);

$this->admin = new Admin(
$this->config,
$this->updateChecker,
$this->groupManager,
$this->dateTimeFormatter,
$this->l10nFactory,
$this->config,
$this->updateChecker,
$this->groupManager,
$this->dateTimeFormatter,
$this->l10nFactory,
$this->subscriptionRegistry,
$this->userManager,
$this->logger
);
}

public function testGetFormWithUpdate() {
$backend1 = $this->createMock(UserInterface::class);
$backend2 = $this->createMock(UserInterface::class);
$backend3 = $this->createMock(UserInterface::class);
$backend1 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend2 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend3 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
Expand DownExpand Up@@ -213,9 +219,9 @@ public function testGetFormWithUpdate() {
}

public function testGetFormWithUpdateAndChangedUpdateServer() {
$backend1 = $this->createMock(UserInterface::class);
$backend2 = $this->createMock(UserInterface::class);
$backend3 = $this->createMock(UserInterface::class);
$backend1 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend2 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend3 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
Expand DownExpand Up@@ -337,9 +343,9 @@ public function testGetFormWithUpdateAndChangedUpdateServer() {
}

public function testGetFormWithUpdateAndCustomersUpdateServer() {
$backend1 = $this->createMock(UserInterface::class);
$backend2 = $this->createMock(UserInterface::class);
$backend3 = $this->createMock(UserInterface::class);
$backend1 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend2 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend3 = $this->createMock(UserInterfaceAwareICountUsersBackend::class);
$backend1
->expects($this->once())
->method('implementsActions')
Expand Down
4 changes: 3 additions & 1 deletion lib/private/Encryption/Util.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -37,6 +37,7 @@
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use OCP\IUser;
use OCP\App\IAppManager;

class Util {
public const HEADER_START = 'HBEGIN';
Expand DownExpand Up@@ -299,7 +300,8 @@ public function getUserWithAccessToMountPoint($users, $groups) {
* @return boolean
*/
public function isSystemWideMountPoint($path, $uid) {
if (\OCP\App::isEnabled("files_external")) {
$appManager = \OC::$server->get(IAppManager::class);
Comment thread
nickvergessen marked this conversation as resolved.
if ($appManager->isEnabledForUser('files_external', null)) {
/** @var GlobalStoragesService $storageService */
$storageService = \OC::$server->get(GlobalStoragesService::class);
$storages = $storageService->getAllStorages();
Expand Down
33 changes: 26 additions & 7 deletions tests/lib/Encryption/UtilTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,8 +4,7 @@

use OC\Encryption\Util;
use OC\Files\View;
use OCA\Files_External\Lib\StorageConfig;
use OCA\Files_External\Service\GlobalStoragesService;
use OCP\App\IAppManager;
use OCP\Encryption\IEncryptionModule;
use OCP\IConfig;
use Test\TestCase;
Expand DownExpand Up@@ -40,11 +39,11 @@ protected function setUp(): void {
->disableOriginalConstructor()
->getMock();

$this->userManager = $this->getMockBuilder('OC\User\Manager')
$this->userManager = $this->getMockBuilder(\OC\User\Manager::class)
->disableOriginalConstructor()
->getMock();

$this->groupManager = $this->getMockBuilder('OC\Group\Manager')
$this->groupManager = $this->getMockBuilder(\OC\Group\Manager::class)
->disableOriginalConstructor()
->getMock();

Expand DownExpand Up@@ -207,6 +206,15 @@ public function dataTestIsSystemWideMountPoint() {
* @dataProvider dataTestIsSystemWideMountPoint
*/
public function testIsSystemWideMountPoint($expectedResult, $expectationText, $applicableUsers, $applicableGroups, $mountPointName = '/mp') {
$appManager = $this->createMock(IAppManager::class);
$appManager
->expects($this->once())
->method('isEnabledForUser')
->with('files_external')
->willReturn(true);

$this->overwriteService(IAppManager::class, $appManager);

$this->groupManager->method('isInGroup')
->will($this->returnValueMap([
['user1', 'group1', true], // user is only in group1
Expand All@@ -215,17 +223,28 @@ public function testIsSystemWideMountPoint($expectedResult, $expectationText, $a

$storages = [];

$storageConfig = $this->createMock(StorageConfig::class);
// StorageConfig
$storageConfig = $this->getMockBuilder('OCA\\Files_External\\Lib\\StorageConfig')
->setMethods([
'getMountPoint',
'getApplicableUsers',
'getApplicableGroups',
])
->getMock();
$storageConfig->method('getMountPoint')->willReturn($mountPointName);
$storageConfig->method('getApplicableUsers')->willReturn($applicableUsers);
$storageConfig->method('getApplicableGroups')->willReturn($applicableGroups);
$storages[] = $storageConfig;

$storagesServiceMock = $this->createMock(GlobalStoragesService::class);
$storagesServiceMock = $this->getMockBuilder('OCA\\Files_External\\Service\\GlobalStoragesService')
->setMethods([
'getAllStorages',
])
->getMock();
$storagesServiceMock->expects($this->atLeastOnce())->method('getAllStorages')
->willReturn($storages);

$this->overwriteService(GlobalStoragesService::class, $storagesServiceMock);
$this->overwriteService('OCA\\Files_External\\Service\\GlobalStoragesService', $storagesServiceMock);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why for core class you went from string to ::class and for files-external classes you go the other way around?

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because core classes are fine. This class might not be loaded as the test is in core and the app is not force enabled nor default enabled

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe some day... owncloud/core#25422


$this->assertEquals($expectedResult, $this->util->isSystemWideMountPoint('/files/mp', 'user1'), 'Test case: ' . $expectationText);
}
Expand Down
7 changes: 5 additions & 2 deletions tests/lib/Files/Node/FolderTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -105,11 +105,14 @@ public function testGet() {
->method('getUser')
->willReturn($this->user);

$expected = $this->createMock(Node::class);
$root->method('get')
->with('/bar/foo/asd');
->with('/bar/foo/asd')
->willReturn($expected);

$node = new Folder($root, $view, '/bar/foo');
$node->get('asd');
$return = $node->get('asd');
self::assertEquals($expected, $return);
}

public function testNodeExists() {
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit-autotest.xml
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,6 +2,8 @@
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="bootstrap.php"
verbose="true"
failOnRisky="true"
failOnWarning="true"
backupGlobals="false"
timeoutForSmallTests="900"
timeoutForMediumTests="900"
Expand Down