Some unit tests for the Environment class
This commit is contained in:
parent
55f7c9e7de
commit
468f17a74a
|
@ -1 +1 @@
|
|||
Subproject commit c6989653fecda04b9114718025c089ba073cd463
|
||||
Subproject commit 70f0094d04dca8d5f5dd06498dd4f8c6fb268df7
|
|
@ -18,11 +18,11 @@ use OCP\Files\Node;
|
|||
use OCA\Gallery\Tests\Integration\GalleryIntegrationTest;
|
||||
|
||||
/**
|
||||
* Class EnvironmentTest
|
||||
* Class EnvironmentSetupTest
|
||||
*
|
||||
* @package OCA\Gallery\Tests\Integration
|
||||
*/
|
||||
class EnvironmentTest extends GalleryIntegrationTest {
|
||||
class EnvironmentSetupTest extends GalleryIntegrationTest {
|
||||
|
||||
/**
|
||||
* Tests is setting up the environment using a normal user works
|
||||
|
@ -65,15 +65,24 @@ class EnvironmentTest extends GalleryIntegrationTest {
|
|||
$this->assertEquals($sharedFolderId, $result->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* We can't get the folder if we're given a file token
|
||||
*
|
||||
* @expects EnvironmentException
|
||||
*/
|
||||
public function testGetSharedNodeAsATokenUserWhenGivenFileToken() {
|
||||
$environment = $this->setTokenBasedEnv($this->sharedFileToken);
|
||||
|
||||
$environment->getSharedNode();
|
||||
$sharedFileId = $this->sharedFile->getId();
|
||||
$result = $environment->getSharedNode();
|
||||
|
||||
$this->assertEquals($sharedFileId, $result->getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* We can't get the virtual root if we're given a file token
|
||||
*
|
||||
* @expectedException \OCA\Gallery\Environment\NotFoundEnvException
|
||||
*/
|
||||
public function testGetVirtualRootFolderAsATokenUserWhenGivenFileToken() {
|
||||
$environment = $this->setTokenBasedEnv($this->sharedFileToken);
|
||||
|
||||
$environment->getVirtualRootFolder();
|
||||
}
|
||||
|
||||
public function testGetVirtualRootFolderAsALoggedInUser() {
|
|
@ -0,0 +1,104 @@
|
|||
<?php
|
||||
/**
|
||||
* ownCloud - gallery
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3 or
|
||||
* later. See the COPYING file.
|
||||
*
|
||||
* @author Olivier Paroz <owncloud@interfasys.ch>
|
||||
*
|
||||
* @copyright Olivier Paroz 2015
|
||||
*/
|
||||
|
||||
namespace OCA\Gallery\Environment;
|
||||
|
||||
use OCP\IServerContainer;
|
||||
use OCP\IUserManager;
|
||||
use OCP\ILogger;
|
||||
use OCP\Files\IRootFolder;
|
||||
use OCP\Files\Folder;
|
||||
|
||||
use OCP\AppFramework\IAppContainer;
|
||||
|
||||
use OCA\Gallery\AppInfo\Application;
|
||||
|
||||
/**
|
||||
* Class Environment
|
||||
*
|
||||
* @package OCA\Gallery\Environment
|
||||
*/
|
||||
class EnvironmentTest extends \Test\TestCase {
|
||||
|
||||
/** @var IAppContainer */
|
||||
private $container;
|
||||
/** @var string */
|
||||
private $appName = 'gallery';
|
||||
/** @var IRootFolder */
|
||||
private $rootFolder;
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IServerContainer */
|
||||
private $serverContainer;
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var Environment */
|
||||
private $environment;
|
||||
|
||||
/**
|
||||
* Test set up
|
||||
*/
|
||||
public function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$app = new Application();
|
||||
$this->container = $app->getContainer();
|
||||
$this->rootFolder = $this->container->getServer()
|
||||
->getRootFolder();
|
||||
$this->userManager = $this->getMockBuilder('\OCP\IUserManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->serverContainer = $this->getMockBuilder('OCP\IServerContainer')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->logger = $this->getMockBuilder('\OCP\ILogger')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OCA\Gallery\Environment\NotFoundEnvException
|
||||
*/
|
||||
public function testGetNodeFromUserFolderWithNullUser() {
|
||||
$userId = 'user';
|
||||
$userFolder = null;
|
||||
$this->mockSetEnvironment($userId, $userFolder);
|
||||
$this->environment->getNodeFromUserFolder('anypath');
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \OCA\Gallery\Environment\NotFoundEnvException
|
||||
*/
|
||||
public function testGetDisplayName() {
|
||||
$userId = null;
|
||||
$userFolder = null;
|
||||
$this->mockSetEnvironment($userId, $userFolder);
|
||||
$this->environment->getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userId
|
||||
* @param $userFolder
|
||||
*/
|
||||
private function mockSetEnvironment($userId, $userFolder) {
|
||||
$this->environment = new Environment(
|
||||
$this->appName,
|
||||
$userId,
|
||||
$userFolder,
|
||||
$this->userManager,
|
||||
$this->serverContainer,
|
||||
$this->logger
|
||||
);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue