Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/gallery.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOlivier Paroz <github@oparoz.com>2016-06-11 05:25:44 +0300
committerOlivier Paroz <github@oparoz.com>2016-06-11 05:25:44 +0300
commit62cff93230586833fc95821728b72ab1f118da53 (patch)
tree6a15f2edaaf15e0e8bf2c9863cdc49be52d5d046 /tests
parent1e3500e0cf49d87a45d0ab0809da58320e240ef9 (diff)
Various fixes and cleanup for Share 2.0
Diffstat (limited to 'tests')
-rw-r--r--tests/api/DownloadWithTokenCest.php6
-rw-r--r--tests/integration/GalleryIntegrationTest.php9
-rw-r--r--tests/unit/middleware/EnvCheckMiddlewareTest.php87
3 files changed, 33 insertions, 69 deletions
diff --git a/tests/api/DownloadWithTokenCest.php b/tests/api/DownloadWithTokenCest.php
index 610bd1f9..1cf1b711 100644
--- a/tests/api/DownloadWithTokenCest.php
+++ b/tests/api/DownloadWithTokenCest.php
@@ -56,7 +56,7 @@ class DownloadWithTokenCest {
}
/**
- * When a token is not valid we get an error 400, NOT 404
+ * When a token is not valid we get an error 404
*
* @param \Step\Api\TokenUser $I
*/
@@ -64,10 +64,10 @@ class DownloadWithTokenCest {
$I->am('a file owner');
$I->wantTo('insert a file in a forum');
$I->amGoingTo("send a bogus token");
- $I->expectTo("be redirected to an error 400 page");
+ $I->expectTo("be redirected to an error 404 page");
$I->haveHttpHeader('Accept', $this->browserHeader);
$I->sendGET($this->apiUrl . '1AmaW1cK3d70k3N');
- $I->seeResponseCodeIs(400);
+ $I->seeResponseCodeIs(404);
$I->seeHttpHeader('Content-type', 'text/html; charset=UTF-8');
}
diff --git a/tests/integration/GalleryIntegrationTest.php b/tests/integration/GalleryIntegrationTest.php
index 086a5736..5fb98a9e 100644
--- a/tests/integration/GalleryIntegrationTest.php
+++ b/tests/integration/GalleryIntegrationTest.php
@@ -14,6 +14,8 @@ namespace OCA\Gallery\Tests\Integration;
use Helper\CoreTestCase;
+use OC\Share20\Manager;
+
use OCP\Share;
use OCP\Files\Node;
use OCP\Files\Folder;
@@ -39,6 +41,8 @@ abstract class GalleryIntegrationTest extends \Codeception\TestCase\Test {
protected $container;
/** @var IServerContainer */
protected $server;
+ /** @var Manager */
+ protected $shareManager;
/** @var Folder|null */
protected $userFolder;
/** @var string */
@@ -85,6 +89,7 @@ abstract class GalleryIntegrationTest extends \Codeception\TestCase\Test {
$app = new Gallery();
$this->container = $app->getContainer();
$this->server = $this->container->getServer();
+ $this->shareManager = $this->server->getShareManager();
$setupData = $this->getModule('\Helper\DataSetup');
$this->userId = $setupData->userId;
@@ -125,9 +130,9 @@ abstract class GalleryIntegrationTest extends \Codeception\TestCase\Test {
* @return Environment
*/
protected function setTokenBasedEnv($token) {
- $linkItem = Share::getShareByToken($token, false);
+ $share = $this->shareManager->getShareByToken($token);
$environment = $this->instantiateEnvironment();
- $environment->setTokenBasedEnv($linkItem);
+ $environment->setTokenBasedEnv($share);
return $environment;
}
diff --git a/tests/unit/middleware/EnvCheckMiddlewareTest.php b/tests/unit/middleware/EnvCheckMiddlewareTest.php
index 7e67d67c..6421b9dc 100644
--- a/tests/unit/middleware/EnvCheckMiddlewareTest.php
+++ b/tests/unit/middleware/EnvCheckMiddlewareTest.php
@@ -16,12 +16,12 @@ use OC\AppFramework\Utility\ControllerMethodReflector;
use Helper\CoreTestCase;
use OCP\IRequest;
-use OCP\Notification\IManager;
use OCP\Security\IHasher;
use OCP\ISession;
use OCP\ILogger;
use OCP\IURLGenerator;
use OCP\Share;
+use OCP\Share\IManager;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
@@ -66,7 +66,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
public $sharedFolderToken;
/** @var string */
public $passwordForFolderShare;
- /** @var OCP\Share|IManager */
+ /** @var IManager */
private $shareManager;
/**
@@ -110,8 +110,8 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
$this->environment,
$this->reflector,
$this->urlGenerator,
- $this->logger,
- $this->shareManager
+ $this->shareManager,
+ $this->logger
);
/**
@@ -153,7 +153,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
/**
* @PublicPage
*
- * @expectedException \OCP\Files\NotFoundException
+ * @expectedException \OCA\Gallery\Middleware\CheckException
*/
public function testBeforeControllerWithPublicNotationAndInvalidToken() {
$this->reflector->reflect(__CLASS__, __FUNCTION__);
@@ -231,7 +231,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
$share = $this->newShare();
$share->setId(12345);
$this->mockSessionExists($share->getId());
- $this->mockSessionWithLinkItemId($share->getId());
+ $this->mockSessionWithShareId($share->getId());
self::invokePrivate($this->middleware, 'checkSession', [$share]);
}
@@ -248,7 +248,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
}
/**
- * Ids of linkItem do not match
+ * Ids of shares do not match
*
* @expectedException \OCA\Gallery\Middleware\CheckException
*/
@@ -256,7 +256,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
$share = $this->newShare();
$share->setId(12345);
$this->mockSessionExists(true);
- $this->mockSessionWithLinkItemId(99999);
+ $this->mockSessionWithShareId(99999);
self::invokePrivate($this->middleware, 'checkSession', [$share]);
}
@@ -394,7 +394,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
$share->setId(12345)
->setSharedWith('Empyrion Galactic Survival');
$this->mockSessionExists($share->getId());
- $this->mockSessionWithLinkItemId($share->getId());
+ $this->mockSessionWithShareId($share->getId());
self::invokePrivate($this->middleware, 'checkAuthorisation', [$share, $password]);
}
@@ -416,79 +416,38 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
self::invokePrivate($this->middleware, 'checkItemType', [$share]);
}
- public function testCheckLinkItemIsValidWithValidLinkItem() {
+ public function testCheckShareIsValidWithValidShare() {
$share = $this->newShare();
$share->setId(12345)
->setShareOwner('tester')
->setTarget('folder1');
$token = 'aaaabbbbccccdddd';
- self::invokePrivate($this->middleware, 'checkLinkItemIsValid', [$share, $token]);
+ self::invokePrivate($this->middleware, 'checkShareIsValid', [$share, $token]);
}
/**
* @expectedException \OCA\Gallery\Middleware\CheckException
*/
- public function testCheckLinkItemIsValidWithMissingOwner() {
+ public function testCheckShareIsValidWithMissingOwner() {
$share = $this->newShare();
$share->setId(12345)
->setTarget('folder1');
$token = 'aaaabbbbccccdddd';
- self::invokePrivate($this->middleware, 'checkLinkItemIsValid', [$share, $token]);
+ self::invokePrivate($this->middleware, 'checkShareIsValid', [$share, $token]);
}
/**
* @expectedException \OCA\Gallery\Middleware\CheckException
*/
- public function testCheckLinkItemIsValidWithMissingSource() {
+ public function testCheckShareIsValidWithMissingSource() {
$share = $this->newShare();
$share->setId(12345)
->setShareOwner('tester');
$token = 'aaaabbbbccccdddd';
- self::invokePrivate($this->middleware, 'checkLinkItemIsValid', [$share, $token]);
- }
-
- /**
- * @return array
- */
- public function providesItemTypes() {
- return [
- ['file'],
- ['folder']
- ];
- }
-
- /**
- * @dataProvider providesItemTypes
- *
- * @param string $type
- */
- public function testCheckLinkItemExistsWithValidLinkItem($type) {
- $share = $this->newShare();
- $share->setNodeType($type);
-
- self::invokePrivate($this->middleware, 'checkLinkItemExists', [$share]);
- }
-
- /**
- * @expectedException \OCA\Gallery\Middleware\CheckException
- */
- public function testCheckLinkItemExistsWithEmptyLinkItem() {
- $share = false;
-
- self::invokePrivate($this->middleware, 'checkLinkItemExists', [$share]);
- }
-
- /**
- * @expectedException InvalidArgumentException
- */
- public function testCheckLinkItemExistsWithWeirdLinkItem() {
- $share = $this->newShare();
- $share->setNodeType('cheese');
-
- self::invokePrivate($this->middleware, 'checkLinkItemExists', [$share]);
+ self::invokePrivate($this->middleware, 'checkShareIsValid', [$share, $token]);
}
public function testAfterExceptionWithCheckExceptionAndHtmlAcceptAnd401Code() {
@@ -529,7 +488,7 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
$response =
$this->middleware->afterException(
- $this->controller, 'checkLinkItemIsValid', $exception
+ $this->controller, 'checkShareIsValid', $exception
);
$this->assertEquals($template, $response);
@@ -543,31 +502,31 @@ class EnvCheckMiddlewareTest extends \Codeception\TestCase\Test {
$code = Http::STATUS_NOT_FOUND;
$exception = new EnvironmentException($message, $code);
- $this->middleware->afterException($this->controller, 'checkLinkItemIsValid', $exception);
+ $this->middleware->afterException($this->controller, 'checkShareIsValid', $exception);
}
/**
* Mocks ISession->exists('public_link_authenticated')
*
- * @param int $linkItemId
+ * @param int $shareId
*/
- private function mockSessionExists($linkItemId) {
+ private function mockSessionExists($shareId) {
$this->session->expects($this->once())
->method('exists')
->with('public_link_authenticated')
- ->willReturn($linkItemId);
+ ->willReturn($shareId);
}
/**
* Mocks ISession->get('public_link_authenticated')
*
- * @param int $linkItemId
+ * @param int $shareId
*/
- private function mockSessionWithLinkItemId($linkItemId) {
+ private function mockSessionWithShareId($shareId) {
$this->session->expects($this->once())
->method('get')
->with('public_link_authenticated')
- ->willReturn($linkItemId);
+ ->willReturn($shareId);
}
private function mockHtml401Response() {