Fix PageControllerTest
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
parent
186915b4ea
commit
bef5857efa
|
@ -118,7 +118,7 @@ class PageController extends Controller {
|
||||||
* @param string $token
|
* @param string $token
|
||||||
* @param null|string $filename
|
* @param null|string $filename
|
||||||
*
|
*
|
||||||
* @return TemplateResponse|ImageResponse|RedirectResponse
|
* @return PublicTemplateResponse|ImageResponse|RedirectResponse
|
||||||
*/
|
*/
|
||||||
public function publicIndex($token, $filename) {
|
public function publicIndex($token, $filename) {
|
||||||
$node = $this->environment->getSharedNode();
|
$node = $this->environment->getSharedNode();
|
||||||
|
|
|
@ -13,7 +13,11 @@
|
||||||
|
|
||||||
namespace OCA\Gallery\Tests\Controller;
|
namespace OCA\Gallery\Tests\Controller;
|
||||||
|
|
||||||
|
use OCP\AppFramework\Http\Template\ExternalShareMenuAction;
|
||||||
|
use OCP\AppFramework\Http\Template\LinkMenuAction;
|
||||||
|
use OCP\AppFramework\Http\Template\SimpleMenuAction;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IL10N;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
|
|
||||||
|
@ -44,6 +48,8 @@ class PageControllerTest extends \Test\TestCase {
|
||||||
protected $controller;
|
protected $controller;
|
||||||
/** @var EventDispatcherInterface */
|
/** @var EventDispatcherInterface */
|
||||||
protected $dispatcher;
|
protected $dispatcher;
|
||||||
|
/** @var IL10N */
|
||||||
|
private $l10n;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test set up
|
* Test set up
|
||||||
|
@ -51,18 +57,11 @@ class PageControllerTest extends \Test\TestCase {
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->request = $this->getMockBuilder('\OCP\IRequest')
|
$this->request = $this->createMock(IRequest::class);
|
||||||
->disableOriginalConstructor()
|
$this->environment = $this->createMock(Environment::class);
|
||||||
->getMock();
|
$this->urlGenerator = $this->createMock(IURLGenerator::class);
|
||||||
$this->environment = $this->getMockBuilder('\OCA\Gallery\Environment\Environment')
|
$this->appConfig = $this->createMock(IConfig::class);
|
||||||
->disableOriginalConstructor()
|
$this->l10n = $this->createMock(IL10N::class);
|
||||||
->getMock();
|
|
||||||
$this->urlGenerator = $this->getMockBuilder('\OCP\IURLGenerator')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->appConfig = $this->getMockBuilder('\OCP\IConfig')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
|
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);
|
||||||
$this->controller = new PageController(
|
$this->controller = new PageController(
|
||||||
$this->appName,
|
$this->appName,
|
||||||
|
@ -70,7 +69,8 @@ class PageControllerTest extends \Test\TestCase {
|
||||||
$this->environment,
|
$this->environment,
|
||||||
$this->urlGenerator,
|
$this->urlGenerator,
|
||||||
$this->appConfig,
|
$this->appConfig,
|
||||||
$this->dispatcher
|
$this->dispatcher,
|
||||||
|
$this->l10n
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,15 +154,28 @@ class PageControllerTest extends \Test\TestCase {
|
||||||
$this->mockGetDisplayName($displayName);
|
$this->mockGetDisplayName($displayName);
|
||||||
$this->mockGetSharePassword($password);
|
$this->mockGetSharePassword($password);
|
||||||
$this->mockGetAppValue($server2ServerSharingEnabled);
|
$this->mockGetAppValue($server2ServerSharingEnabled);
|
||||||
|
$this->mockGetUserId('user1');
|
||||||
|
$this->mockL10N();
|
||||||
|
|
||||||
$template = new TemplateResponse($this->appName, 'public', $params, 'public');
|
$template = new Http\Template\PublicTemplateResponse($this->appName, 'public', $params);
|
||||||
|
|
||||||
$response = $this->controller->publicIndex($token, null);
|
$response = $this->controller->publicIndex($token, 'filename.txt');
|
||||||
|
|
||||||
$this->assertEquals($params, $response->getParams());
|
$this->assertEquals($params, $response->getParams());
|
||||||
$this->assertEquals('public', $response->getTemplateName());
|
$this->assertEquals('public', $response->getTemplateName());
|
||||||
$this->assertTrue($response instanceof TemplateResponse);
|
$this->assertTrue($response instanceof Http\Template\PublicTemplateResponse);
|
||||||
$this->assertEquals($template->getStatus(), $response->getStatus());
|
$this->assertEquals($template->getStatus(), $response->getStatus());
|
||||||
|
$this->assertEquals($albumName, $response->getHeaderTitle());
|
||||||
|
$this->assertEquals('shared by ' . $displayName, $response->getHeaderDetails());
|
||||||
|
|
||||||
|
$actions = [
|
||||||
|
new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download-white', '', 0),
|
||||||
|
new SimpleMenuAction('download', $this->l10n->t('Download'), 'icon-download', '', 10),
|
||||||
|
new LinkMenuAction($this->l10n->t('Direct link'), 'icon-public', ''),
|
||||||
|
new ExternalShareMenuAction($this->l10n->t('Add to your Nextcloud'), 'icon-external', 'user1', $displayName, $albumName)
|
||||||
|
];
|
||||||
|
$this->assertEquals($actions[0], $response->getPrimaryAction());
|
||||||
|
$this->assertEquals(array_slice($actions, 1), $response->getOtherActions());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testPublicIndexWithFileToken() {
|
public function testPublicIndexWithFileToken() {
|
||||||
|
@ -238,6 +251,12 @@ class PageControllerTest extends \Test\TestCase {
|
||||||
->willReturn($status);
|
->willReturn($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function mockGetUserId($userId) {
|
||||||
|
$this->environment->expects($this->once())
|
||||||
|
->method('getUserId')
|
||||||
|
->willReturn($userId);
|
||||||
|
}
|
||||||
|
|
||||||
private function mockUrlToDownloadPage($token, $fileId, $filename, $url) {
|
private function mockUrlToDownloadPage($token, $fileId, $filename, $url) {
|
||||||
$this->urlGenerator->expects($this->once())
|
$this->urlGenerator->expects($this->once())
|
||||||
->method('linkToRoute')
|
->method('linkToRoute')
|
||||||
|
@ -286,4 +305,12 @@ class PageControllerTest extends \Test\TestCase {
|
||||||
->with('files', 'ajax/upload.php')
|
->with('files', 'ajax/upload.php')
|
||||||
->willReturn($url);
|
->willReturn($url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function mockL10N() {
|
||||||
|
$this->l10n->expects($this->any())
|
||||||
|
->method('t')
|
||||||
|
->will($this->returnCallback(function($text, $params) {
|
||||||
|
return vsprintf($text, $params);
|
||||||
|
}));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue