From 1a8ac737e52cb25a5c346232ee398f5908cee7d7 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Mon, 6 Jul 2020 08:04:35 +0200 Subject: Process main page (linklist) through Slim controller Including a bunch of improvements on the container, and helper used across new controllers. --- tests/RouterTest.php | 509 -------------------- tests/bookmark/BookmarkFileServiceTest.php | 20 +- tests/front/ShaarliMiddlewareTest.php | 130 +++++- .../visitor/BookmarkListControllerTest.php | 448 ++++++++++++++++++ tests/legacy/LegacyControllerTest.php | 99 ++++ tests/legacy/LegacyRouterTest.php | 512 +++++++++++++++++++++ tests/plugins/PluginAddlinkTest.php | 6 +- tests/plugins/PluginPlayvideosTest.php | 6 +- tests/plugins/PluginPubsubhubbubTest.php | 6 +- tests/plugins/PluginQrcodeTest.php | 4 +- tests/updater/UpdaterTest.php | 19 + 11 files changed, 1224 insertions(+), 535 deletions(-) delete mode 100644 tests/RouterTest.php create mode 100644 tests/front/controller/visitor/BookmarkListControllerTest.php create mode 100644 tests/legacy/LegacyControllerTest.php create mode 100644 tests/legacy/LegacyRouterTest.php (limited to 'tests') diff --git a/tests/RouterTest.php b/tests/RouterTest.php deleted file mode 100644 index 0cd49bb8..00000000 --- a/tests/RouterTest.php +++ /dev/null @@ -1,509 +0,0 @@ -assertEquals( - Router::$PAGE_LOGIN, - Router::findPage('do=login', array(), false) - ); - - $this->assertEquals( - Router::$PAGE_LOGIN, - Router::findPage('do=login', array(), 1) - ); - - $this->assertEquals( - Router::$PAGE_LOGIN, - Router::findPage('do=login&stuff', array(), false) - ); - } - - /** - * Test findPage: login page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageLoginInvalid() - { - $this->assertNotEquals( - Router::$PAGE_LOGIN, - Router::findPage('do=login', array(), true) - ); - - $this->assertNotEquals( - Router::$PAGE_LOGIN, - Router::findPage('do=other', array(), false) - ); - } - - /** - * Test findPage: picwall page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPagePicwallValid() - { - $this->assertEquals( - Router::$PAGE_PICWALL, - Router::findPage('do=picwall', array(), false) - ); - - $this->assertEquals( - Router::$PAGE_PICWALL, - Router::findPage('do=picwall', array(), true) - ); - } - - /** - * Test findPage: picwall page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPagePicwallInvalid() - { - $this->assertEquals( - Router::$PAGE_PICWALL, - Router::findPage('do=picwall&stuff', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_PICWALL, - Router::findPage('do=other', array(), false) - ); - } - - /** - * Test findPage: tagcloud page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageTagcloudValid() - { - $this->assertEquals( - Router::$PAGE_TAGCLOUD, - Router::findPage('do=tagcloud', array(), false) - ); - - $this->assertEquals( - Router::$PAGE_TAGCLOUD, - Router::findPage('do=tagcloud', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_TAGCLOUD, - Router::findPage('do=tagcloud&stuff', array(), false) - ); - } - - /** - * Test findPage: tagcloud page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageTagcloudInvalid() - { - $this->assertNotEquals( - Router::$PAGE_TAGCLOUD, - Router::findPage('do=other', array(), false) - ); - } - - /** - * Test findPage: linklist page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageLinklistValid() - { - $this->assertEquals( - Router::$PAGE_LINKLIST, - Router::findPage('', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_LINKLIST, - Router::findPage('whatever', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_LINKLIST, - Router::findPage('whatever', array(), false) - ); - - $this->assertEquals( - Router::$PAGE_LINKLIST, - Router::findPage('do=tools', array(), false) - ); - } - - /** - * Test findPage: tools page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageToolsValid() - { - $this->assertEquals( - Router::$PAGE_TOOLS, - Router::findPage('do=tools', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_TOOLS, - Router::findPage('do=tools&stuff', array(), true) - ); - } - - /** - * Test findPage: tools page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageToolsInvalid() - { - $this->assertNotEquals( - Router::$PAGE_TOOLS, - Router::findPage('do=tools', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_TOOLS, - Router::findPage('do=tools', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_TOOLS, - Router::findPage('do=other', array(), true) - ); - } - - /** - * Test findPage: changepasswd page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageChangepasswdValid() - { - $this->assertEquals( - Router::$PAGE_CHANGEPASSWORD, - Router::findPage('do=changepasswd', array(), true) - ); - $this->assertEquals( - Router::$PAGE_CHANGEPASSWORD, - Router::findPage('do=changepasswd&stuff', array(), true) - ); - } - - /** - * Test findPage: changepasswd page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageChangepasswdInvalid() - { - $this->assertNotEquals( - Router::$PAGE_CHANGEPASSWORD, - Router::findPage('do=changepasswd', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_CHANGEPASSWORD, - Router::findPage('do=changepasswd', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_CHANGEPASSWORD, - Router::findPage('do=other', array(), true) - ); - } - /** - * Test findPage: configure page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageConfigureValid() - { - $this->assertEquals( - Router::$PAGE_CONFIGURE, - Router::findPage('do=configure', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_CONFIGURE, - Router::findPage('do=configure&stuff', array(), true) - ); - } - - /** - * Test findPage: configure page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageConfigureInvalid() - { - $this->assertNotEquals( - Router::$PAGE_CONFIGURE, - Router::findPage('do=configure', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_CONFIGURE, - Router::findPage('do=configure', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_CONFIGURE, - Router::findPage('do=other', array(), true) - ); - } - - /** - * Test findPage: changetag page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageChangetagValid() - { - $this->assertEquals( - Router::$PAGE_CHANGETAG, - Router::findPage('do=changetag', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_CHANGETAG, - Router::findPage('do=changetag&stuff', array(), true) - ); - } - - /** - * Test findPage: changetag page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageChangetagInvalid() - { - $this->assertNotEquals( - Router::$PAGE_CHANGETAG, - Router::findPage('do=changetag', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_CHANGETAG, - Router::findPage('do=changetag', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_CHANGETAG, - Router::findPage('do=other', array(), true) - ); - } - - /** - * Test findPage: addlink page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageAddlinkValid() - { - $this->assertEquals( - Router::$PAGE_ADDLINK, - Router::findPage('do=addlink', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_ADDLINK, - Router::findPage('do=addlink&stuff', array(), true) - ); - } - - /** - * Test findPage: addlink page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageAddlinkInvalid() - { - $this->assertNotEquals( - Router::$PAGE_ADDLINK, - Router::findPage('do=addlink', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_ADDLINK, - Router::findPage('do=addlink', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_ADDLINK, - Router::findPage('do=other', array(), true) - ); - } - - /** - * Test findPage: export page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageExportValid() - { - $this->assertEquals( - Router::$PAGE_EXPORT, - Router::findPage('do=export', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_EXPORT, - Router::findPage('do=export&stuff', array(), true) - ); - } - - /** - * Test findPage: export page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageExportInvalid() - { - $this->assertNotEquals( - Router::$PAGE_EXPORT, - Router::findPage('do=export', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_EXPORT, - Router::findPage('do=export', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_EXPORT, - Router::findPage('do=other', array(), true) - ); - } - - /** - * Test findPage: import page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageImportValid() - { - $this->assertEquals( - Router::$PAGE_IMPORT, - Router::findPage('do=import', array(), true) - ); - - $this->assertEquals( - Router::$PAGE_IMPORT, - Router::findPage('do=import&stuff', array(), true) - ); - } - - /** - * Test findPage: import page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageImportInvalid() - { - $this->assertNotEquals( - Router::$PAGE_IMPORT, - Router::findPage('do=import', array(), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_IMPORT, - Router::findPage('do=import', array(), false) - ); - - $this->assertNotEquals( - Router::$PAGE_IMPORT, - Router::findPage('do=other', array(), true) - ); - } - - /** - * Test findPage: editlink page output. - * Valid: page should be return. - * - * @return void - */ - public function testFindPageEditlinkValid() - { - $this->assertEquals( - Router::$PAGE_EDITLINK, - Router::findPage('whatever', array('edit_link' => 1), true) - ); - - $this->assertEquals( - Router::$PAGE_EDITLINK, - Router::findPage('', array('edit_link' => 1), true) - ); - - - $this->assertEquals( - Router::$PAGE_EDITLINK, - Router::findPage('whatever', array('post' => 1), true) - ); - - $this->assertEquals( - Router::$PAGE_EDITLINK, - Router::findPage('whatever', array('post' => 1, 'edit_link' => 1), true) - ); - } - - /** - * Test findPage: editlink page output. - * Invalid: page shouldn't be return. - * - * @return void - */ - public function testFindPageEditlinkInvalid() - { - $this->assertNotEquals( - Router::$PAGE_EDITLINK, - Router::findPage('whatever', array('edit_link' => 1), false) - ); - - $this->assertNotEquals( - Router::$PAGE_EDITLINK, - Router::findPage('whatever', array('edit_link' => 1), 1) - ); - - $this->assertNotEquals( - Router::$PAGE_EDITLINK, - Router::findPage('whatever', array(), true) - ); - } -} diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index 5adc26aa..b19c8250 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -892,35 +892,35 @@ class BookmarkFileServiceTest extends TestCase public function testFilterHashValid() { $request = smallHash('20150310_114651'); - $this->assertEquals( - 1, - count($this->publicLinkDB->findByHash($request)) + $this->assertSame( + $request, + $this->publicLinkDB->findByHash($request)->getShortUrl() ); $request = smallHash('20150310_114633' . 8); - $this->assertEquals( - 1, - count($this->publicLinkDB->findByHash($request)) + $this->assertSame( + $request, + $this->publicLinkDB->findByHash($request)->getShortUrl() ); } /** * Test filterHash() with an invalid smallhash. - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterHashInValid1() { + $this->expectException(BookmarkNotFoundException::class); + $request = 'blabla'; $this->publicLinkDB->findByHash($request); } /** * Test filterHash() with an empty smallhash. - * - * @expectedException \Shaarli\Bookmark\Exception\BookmarkNotFoundException */ public function testFilterHashInValid() { + $this->expectException(BookmarkNotFoundException::class); + $this->publicLinkDB->findByHash(''); } diff --git a/tests/front/ShaarliMiddlewareTest.php b/tests/front/ShaarliMiddlewareTest.php index 57be1002..81ea1344 100644 --- a/tests/front/ShaarliMiddlewareTest.php +++ b/tests/front/ShaarliMiddlewareTest.php @@ -8,7 +8,11 @@ use PHPUnit\Framework\TestCase; use Shaarli\Config\ConfigManager; use Shaarli\Container\ShaarliContainer; use Shaarli\Front\Exception\LoginBannedException; +use Shaarli\Front\Exception\UnauthorizedException; use Shaarli\Render\PageBuilder; +use Shaarli\Render\PageCacheManager; +use Shaarli\Security\LoginManager; +use Shaarli\Updater\Updater; use Slim\Http\Request; use Slim\Http\Response; use Slim\Http\Uri; @@ -24,9 +28,16 @@ class ShaarliMiddlewareTest extends TestCase public function setUp(): void { $this->container = $this->createMock(ShaarliContainer::class); + + $this->container->conf = $this->createMock(ConfigManager::class); + $this->container->loginManager = $this->createMock(LoginManager::class); + $this->middleware = new ShaarliMiddleware($this->container); } + /** + * Test middleware execution with valid controller call + */ public function testMiddlewareExecution(): void { $request = $this->createMock(Request::class); @@ -49,7 +60,10 @@ class ShaarliMiddlewareTest extends TestCase static::assertSame(418, $result->getStatusCode()); } - public function testMiddlewareExecutionWithException(): void + /** + * Test middleware execution with controller throwing a known front exception + */ + public function testMiddlewareExecutionWithFrontException(): void { $request = $this->createMock(Request::class); $request->method('getUri')->willReturnCallback(function (): Uri { @@ -58,7 +72,7 @@ class ShaarliMiddlewareTest extends TestCase return $uri; }); - + $response = new Response(); $controller = function (): void { $exception = new LoginBannedException(); @@ -72,9 +86,6 @@ class ShaarliMiddlewareTest extends TestCase }); $this->container->pageBuilder = $pageBuilder; - $conf = $this->createMock(ConfigManager::class); - $this->container->conf = $conf; - /** @var Response $result */ $result = $this->middleware->__invoke($request, $response, $controller); @@ -82,4 +93,113 @@ class ShaarliMiddlewareTest extends TestCase static::assertSame(401, $result->getStatusCode()); static::assertContains('error', (string) $result->getBody()); } + + /** + * Test middleware execution with controller throwing a not authorized exception + */ + public function testMiddlewareExecutionWithUnauthorizedException(): void + { + $request = $this->createMock(Request::class); + $request->method('getUri')->willReturnCallback(function (): Uri { + $uri = $this->createMock(Uri::class); + $uri->method('getBasePath')->willReturn('/subfolder'); + + return $uri; + }); + + $response = new Response(); + $controller = function (): void { + throw new UnauthorizedException(); + }; + + /** @var Response $result */ + $result = $this->middleware->__invoke($request, $response, $controller); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame('/subfolder/login', $result->getHeader('location')[0]); + } + + /** + * Test middleware execution with controller throwing a not authorized exception + */ + public function testMiddlewareExecutionWithServerExceptionWith(): void + { + $request = $this->createMock(Request::class); + $request->method('getUri')->willReturnCallback(function (): Uri { + $uri = $this->createMock(Uri::class); + $uri->method('getBasePath')->willReturn('/subfolder'); + + return $uri; + }); + + $response = new Response(); + $controller = function (): void { + throw new \Exception(); + }; + + $parameters = []; + $this->container->pageBuilder = $this->createMock(PageBuilder::class); + $this->container->pageBuilder->method('render')->willReturnCallback(function (string $message): string { + return $message; + }); + $this->container->pageBuilder + ->method('assign') + ->willReturnCallback(function (string $key, string $value) use (&$parameters): void { + $parameters[$key] = $value; + }) + ; + + /** @var Response $result */ + $result = $this->middleware->__invoke($request, $response, $controller); + + static::assertSame(500, $result->getStatusCode()); + static::assertContains('error', (string) $result->getBody()); + static::assertSame('An unexpected error occurred.', $parameters['message']); + } + + public function testMiddlewareExecutionWithUpdates(): void + { + $request = $this->createMock(Request::class); + $request->method('getUri')->willReturnCallback(function (): Uri { + $uri = $this->createMock(Uri::class); + $uri->method('getBasePath')->willReturn('/subfolder'); + + return $uri; + }); + + $response = new Response(); + $controller = function (Request $request, Response $response): Response { + return $response->withStatus(418); // I'm a tea pot + }; + + $this->container->loginManager = $this->createMock(LoginManager::class); + $this->container->loginManager->method('isLoggedIn')->willReturn(true); + + $this->container->conf = $this->createMock(ConfigManager::class); + $this->container->conf->method('get')->willReturnCallback(function (string $key): string { + return $key; + }); + + $this->container->pageCacheManager = $this->createMock(PageCacheManager::class); + $this->container->pageCacheManager->expects(static::once())->method('invalidateCaches'); + + $this->container->updater = $this->createMock(Updater::class); + $this->container->updater + ->expects(static::once()) + ->method('update') + ->willReturn(['update123']) + ; + $this->container->updater->method('getDoneUpdates')->willReturn($updates = ['update123', 'other']); + $this->container->updater + ->expects(static::once()) + ->method('writeUpdates') + ->with('resource.updates', $updates) + ; + + /** @var Response $result */ + $result = $this->middleware->__invoke($request, $response, $controller); + + static::assertInstanceOf(Response::class, $result); + static::assertSame(418, $result->getStatusCode()); + } } diff --git a/tests/front/controller/visitor/BookmarkListControllerTest.php b/tests/front/controller/visitor/BookmarkListControllerTest.php new file mode 100644 index 00000000..5daaa2c4 --- /dev/null +++ b/tests/front/controller/visitor/BookmarkListControllerTest.php @@ -0,0 +1,448 @@ +createContainer(); + + $this->controller = new BookmarkListController($this->container); + } + + /** + * Test rendering list of bookmarks with default parameters (first page). + */ + public function testIndexDefaultFirstPage(): void + { + $assignedVariables = []; + $this->assignTemplateVars($assignedVariables); + + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->container->bookmarkService + ->expects(static::once()) + ->method('search') + ->with( + ['searchtags' => '', 'searchterm' => ''], + null, + false, + false + ) + ->willReturn([ + (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), + (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'), + (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'), + ] + ); + + $this->container->sessionManager + ->method('getSessionParameter') + ->willReturnCallback(function (string $parameter, $default = null) { + if ('LINKS_PER_PAGE' === $parameter) { + return 2; + } + + return $default; + }) + ; + + $result = $this->controller->index($request, $response); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + + static::assertSame('Shaarli', $assignedVariables['pagetitle']); + static::assertSame('?page=2', $assignedVariables['previous_page_url']); + static::assertSame('', $assignedVariables['next_page_url']); + static::assertSame(2, $assignedVariables['page_max']); + static::assertSame('', $assignedVariables['search_tags']); + static::assertSame(3, $assignedVariables['result_count']); + static::assertSame(1, $assignedVariables['page_current']); + static::assertSame('', $assignedVariables['search_term']); + static::assertNull($assignedVariables['visibility']); + static::assertCount(2, $assignedVariables['links']); + + $link = $assignedVariables['links'][0]; + + static::assertSame(1, $link['id']); + static::assertSame('http://url1.tld', $link['url']); + static::assertSame('Title 1', $link['title']); + + $link = $assignedVariables['links'][1]; + + static::assertSame(2, $link['id']); + static::assertSame('http://url2.tld', $link['url']); + static::assertSame('Title 2', $link['title']); + } + + /** + * Test rendering list of bookmarks with default parameters (second page). + */ + public function testIndexDefaultSecondPage(): void + { + $assignedVariables = []; + $this->assignTemplateVars($assignedVariables); + + $request = $this->createMock(Request::class); + $request->method('getParam')->willReturnCallback(function (string $key) { + if ('page' === $key) { + return '2'; + } + + return null; + }); + $response = new Response(); + + $this->container->bookmarkService + ->expects(static::once()) + ->method('search') + ->with( + ['searchtags' => '', 'searchterm' => ''], + null, + false, + false + ) + ->willReturn([ + (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), + (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'), + (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'), + ]) + ; + + $this->container->sessionManager + ->method('getSessionParameter') + ->willReturnCallback(function (string $parameter, $default = null) { + if ('LINKS_PER_PAGE' === $parameter) { + return 2; + } + + return $default; + }) + ; + + $result = $this->controller->index($request, $response); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + + static::assertSame('Shaarli', $assignedVariables['pagetitle']); + static::assertSame('', $assignedVariables['previous_page_url']); + static::assertSame('?page=1', $assignedVariables['next_page_url']); + static::assertSame(2, $assignedVariables['page_max']); + static::assertSame('', $assignedVariables['search_tags']); + static::assertSame(3, $assignedVariables['result_count']); + static::assertSame(2, $assignedVariables['page_current']); + static::assertSame('', $assignedVariables['search_term']); + static::assertNull($assignedVariables['visibility']); + static::assertCount(1, $assignedVariables['links']); + + $link = $assignedVariables['links'][2]; + + static::assertSame(3, $link['id']); + static::assertSame('http://url3.tld', $link['url']); + static::assertSame('Title 3', $link['title']); + } + + /** + * Test rendering list of bookmarks with filters. + */ + public function testIndexDefaultWithFilters(): void + { + $assignedVariables = []; + $this->assignTemplateVars($assignedVariables); + + $request = $this->createMock(Request::class); + $request->method('getParam')->willReturnCallback(function (string $key) { + if ('searchtags' === $key) { + return 'abc def'; + } + if ('searchterm' === $key) { + return 'ghi jkl'; + } + + return null; + }); + $response = new Response(); + + $this->container->sessionManager + ->method('getSessionParameter') + ->willReturnCallback(function (string $key, $default) { + if ('LINKS_PER_PAGE' === $key) { + return 2; + } + if ('visibility' === $key) { + return 'private'; + } + if ('untaggedonly' === $key) { + return true; + } + + return $default; + }) + ; + + $this->container->bookmarkService + ->expects(static::once()) + ->method('search') + ->with( + ['searchtags' => 'abc def', 'searchterm' => 'ghi jkl'], + 'private', + false, + true + ) + ->willReturn([ + (new Bookmark())->setId(1)->setUrl('http://url1.tld')->setTitle('Title 1'), + (new Bookmark())->setId(2)->setUrl('http://url2.tld')->setTitle('Title 2'), + (new Bookmark())->setId(3)->setUrl('http://url3.tld')->setTitle('Title 3'), + ]) + ; + + $result = $this->controller->index($request, $response); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + + static::assertSame('Search: ghi jkl [abc] [def] - Shaarli', $assignedVariables['pagetitle']); + static::assertSame('?page=2&searchterm=ghi+jkl&searchtags=abc+def', $assignedVariables['previous_page_url']); + } + + /** + * Test displaying a permalink with valid parameters + */ + public function testPermalinkValid(): void + { + $hash = 'abcdef'; + + $assignedVariables = []; + $this->assignTemplateVars($assignedVariables); + + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->container->bookmarkService + ->expects(static::once()) + ->method('findByHash') + ->with($hash) + ->willReturn((new Bookmark())->setId(123)->setTitle('Title 1')->setUrl('http://url1.tld')) + ; + + $result = $this->controller->permalink($request, $response, ['hash' => $hash]); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + + static::assertSame('Title 1 - Shaarli', $assignedVariables['pagetitle']); + static::assertCount(1, $assignedVariables['links']); + + $link = $assignedVariables['links'][0]; + + static::assertSame(123, $link['id']); + static::assertSame('http://url1.tld', $link['url']); + static::assertSame('Title 1', $link['title']); + } + + /** + * Test displaying a permalink with an unknown small hash : renders a 404 template error + */ + public function testPermalinkNotFound(): void + { + $hash = 'abcdef'; + + $assignedVariables = []; + $this->assignTemplateVars($assignedVariables); + + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->container->bookmarkService + ->expects(static::once()) + ->method('findByHash') + ->with($hash) + ->willThrowException(new BookmarkNotFoundException()) + ; + + $result = $this->controller->permalink($request, $response, ['hash' => $hash]); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('404', (string) $result->getBody()); + + static::assertSame( + 'The link you are trying to reach does not exist or has been deleted.', + $assignedVariables['error_message'] + ); + } + + /** + * Test getting link list with thumbnail updates. + * -> 2 thumbnails update, only 1 datastore write + */ + public function testThumbnailUpdateFromLinkList(): void + { + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->container->loginManager = $this->createMock(LoginManager::class); + $this->container->loginManager->method('isLoggedIn')->willReturn(true); + + $this->container->conf = $this->createMock(ConfigManager::class); + $this->container->conf + ->method('get') + ->willReturnCallback(function (string $key, $default) { + return $key === 'thumbnails.mode' ? Thumbnailer::MODE_ALL : $default; + }) + ; + + $this->container->thumbnailer = $this->createMock(Thumbnailer::class); + $this->container->thumbnailer + ->expects(static::exactly(2)) + ->method('get') + ->withConsecutive(['https://url2.tld'], ['https://url4.tld']) + ; + + $this->container->bookmarkService + ->expects(static::once()) + ->method('search') + ->willReturn([ + (new Bookmark())->setId(1)->setUrl('https://url1.tld')->setTitle('Title 1')->setThumbnail(false), + $b1 = (new Bookmark())->setId(2)->setUrl('https://url2.tld')->setTitle('Title 2'), + (new Bookmark())->setId(3)->setUrl('https://url3.tld')->setTitle('Title 3')->setThumbnail(false), + $b2 = (new Bookmark())->setId(2)->setUrl('https://url4.tld')->setTitle('Title 4'), + (new Bookmark())->setId(2)->setUrl('ftp://url5.tld', ['ftp'])->setTitle('Title 5'), + ]) + ; + $this->container->bookmarkService + ->expects(static::exactly(2)) + ->method('set') + ->withConsecutive([$b1, false], [$b2, false]) + ; + $this->container->bookmarkService->expects(static::once())->method('save'); + + $result = $this->controller->index($request, $response); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + } + + /** + * Test getting a permalink with thumbnail update. + */ + public function testThumbnailUpdateFromPermalink(): void + { + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->container->loginManager = $this->createMock(LoginManager::class); + $this->container->loginManager->method('isLoggedIn')->willReturn(true); + + $this->container->conf = $this->createMock(ConfigManager::class); + $this->container->conf + ->method('get') + ->willReturnCallback(function (string $key, $default) { + return $key === 'thumbnails.mode' ? Thumbnailer::MODE_ALL : $default; + }) + ; + + $this->container->thumbnailer = $this->createMock(Thumbnailer::class); + $this->container->thumbnailer->expects(static::once())->method('get')->withConsecutive(['https://url.tld']); + + $this->container->bookmarkService + ->expects(static::once()) + ->method('findByHash') + ->willReturn($bookmark = (new Bookmark())->setId(2)->setUrl('https://url.tld')->setTitle('Title 1')) + ; + $this->container->bookmarkService->expects(static::once())->method('set')->with($bookmark, true); + $this->container->bookmarkService->expects(static::never())->method('save'); + + $result = $this->controller->permalink($request, $response, ['hash' => 'abc']); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + } + + /** + * Trigger legacy controller in link list controller: permalink + */ + public function testLegacyControllerPermalink(): void + { + $hash = 'abcdef'; + $this->container->environment['QUERY_STRING'] = $hash; + + $request = $this->createMock(Request::class); + $response = new Response(); + + $result = $this->controller->index($request, $response); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame('/subfolder/shaare/' . $hash, $result->getHeader('location')[0]); + } + + /** + * Trigger legacy controller in link list controller: ?do= query parameter + */ + public function testLegacyControllerDoPage(): void + { + $request = $this->createMock(Request::class); + $request->method('getQueryParam')->with('do')->willReturn('picwall'); + $response = new Response(); + + $result = $this->controller->index($request, $response); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame('/subfolder/picture-wall', $result->getHeader('location')[0]); + } + + /** + * Trigger legacy controller in link list controller: ?do= query parameter with unknown legacy route + */ + public function testLegacyControllerUnknownDoPage(): void + { + $request = $this->createMock(Request::class); + $request->method('getQueryParam')->with('do')->willReturn('nope'); + $response = new Response(); + + $result = $this->controller->index($request, $response); + + static::assertSame(200, $result->getStatusCode()); + static::assertSame('linklist', (string) $result->getBody()); + } + + /** + * Trigger legacy controller in link list controller: other GET route (e.g. ?post) + */ + public function testLegacyControllerGetParameter(): void + { + $request = $this->createMock(Request::class); + $request->method('getQueryParams')->willReturn(['post' => $url = 'http://url.tld']); + $response = new Response(); + + $this->container->loginManager = $this->createMock(LoginManager::class); + $this->container->loginManager->method('isLoggedIn')->willReturn(true); + + $result = $this->controller->index($request, $response); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame( + '/subfolder/admin/shaare?post=' . urlencode($url), + $result->getHeader('location')[0] + ); + } +} diff --git a/tests/legacy/LegacyControllerTest.php b/tests/legacy/LegacyControllerTest.php new file mode 100644 index 00000000..ff4520a3 --- /dev/null +++ b/tests/legacy/LegacyControllerTest.php @@ -0,0 +1,99 @@ +createContainer(); + + $this->controller = new LegacyController($this->container); + } + + /** + * @dataProvider getProcessProvider + */ + public function testProcess(string $legacyRoute, array $queryParameters, string $slimRoute, bool $isLoggedIn): void + { + $request = $this->createMock(Request::class); + $request->method('getQueryParams')->willReturn($queryParameters); + $request + ->method('getParam') + ->willReturnCallback(function (string $key) use ($queryParameters): ?string { + return $queryParameters[$key] ?? null; + }) + ; + $response = new Response(); + + $this->container->loginManager->method('isLoggedIn')->willReturn($isLoggedIn); + + $result = $this->controller->process($request, $response, $legacyRoute); + + static::assertSame('/subfolder' . $slimRoute, $result->getHeader('location')[0]); + } + + public function testProcessNotFound(): void + { + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->expectException(UnknowLegacyRouteException::class); + + $this->controller->process($request, $response, 'nope'); + } + + /** + * @return array[] Parameters: + * - string legacyRoute + * - array queryParameters + * - string slimRoute + * - bool isLoggedIn + */ + public function getProcessProvider(): array + { + return [ + ['post', [], '/admin/shaare', true], + ['post', [], '/login', false], + ['post', ['title' => 'test'], '/admin/shaare?title=test', true], + ['post', ['title' => 'test'], '/login?title=test', false], + ['addlink', [], '/admin/add-shaare', true], + ['addlink', [], '/login', false], + ['login', [], '/login', true], + ['login', [], '/login', false], + ['logout', [], '/logout', true], + ['logout', [], '/logout', false], + ['picwall', [], '/picture-wall', false], + ['picwall', [], '/picture-wall', true], + ['tagcloud', [], '/tags/cloud', false], + ['tagcloud', [], '/tags/cloud', true], + ['taglist', [], '/tags/list', false], + ['taglist', [], '/tags/list', true], + ['daily', [], '/daily', false], + ['daily', [], '/daily', true], + ['daily', ['day' => '123456789', 'discard' => '1'], '/daily?day=123456789', false], + ['rss', [], '/feed/rss', false], + ['rss', [], '/feed/rss', true], + ['rss', ['search' => 'filter123', 'other' => 'param'], '/feed/rss?search=filter123&other=param', false], + ['atom', [], '/feed/atom', false], + ['atom', [], '/feed/atom', true], + ['atom', ['search' => 'filter123', 'other' => 'param'], '/feed/atom?search=filter123&other=param', false], + ['opensearch', [], '/open-search', false], + ['opensearch', [], '/open-search', true], + ['dailyrss', [], '/daily-rss', false], + ['dailyrss', [], '/daily-rss', true], + ]; + } +} diff --git a/tests/legacy/LegacyRouterTest.php b/tests/legacy/LegacyRouterTest.php new file mode 100644 index 00000000..c2019ca7 --- /dev/null +++ b/tests/legacy/LegacyRouterTest.php @@ -0,0 +1,512 @@ +assertEquals( + LegacyRouter::$PAGE_LOGIN, + LegacyRouter::findPage('do=login', array(), false) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_LOGIN, + LegacyRouter::findPage('do=login', array(), 1) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_LOGIN, + LegacyRouter::findPage('do=login&stuff', array(), false) + ); + } + + /** + * Test findPage: login page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageLoginInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_LOGIN, + LegacyRouter::findPage('do=login', array(), true) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_LOGIN, + LegacyRouter::findPage('do=other', array(), false) + ); + } + + /** + * Test findPage: picwall page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPagePicwallValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_PICWALL, + LegacyRouter::findPage('do=picwall', array(), false) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_PICWALL, + LegacyRouter::findPage('do=picwall', array(), true) + ); + } + + /** + * Test findPage: picwall page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPagePicwallInvalid() + { + $this->assertEquals( + LegacyRouter::$PAGE_PICWALL, + LegacyRouter::findPage('do=picwall&stuff', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_PICWALL, + LegacyRouter::findPage('do=other', array(), false) + ); + } + + /** + * Test findPage: tagcloud page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageTagcloudValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_TAGCLOUD, + LegacyRouter::findPage('do=tagcloud', array(), false) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_TAGCLOUD, + LegacyRouter::findPage('do=tagcloud', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_TAGCLOUD, + LegacyRouter::findPage('do=tagcloud&stuff', array(), false) + ); + } + + /** + * Test findPage: tagcloud page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageTagcloudInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_TAGCLOUD, + LegacyRouter::findPage('do=other', array(), false) + ); + } + + /** + * Test findPage: linklist page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageLinklistValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_LINKLIST, + LegacyRouter::findPage('', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_LINKLIST, + LegacyRouter::findPage('whatever', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_LINKLIST, + LegacyRouter::findPage('whatever', array(), false) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_LINKLIST, + LegacyRouter::findPage('do=tools', array(), false) + ); + } + + /** + * Test findPage: tools page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageToolsValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_TOOLS, + LegacyRouter::findPage('do=tools', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_TOOLS, + LegacyRouter::findPage('do=tools&stuff', array(), true) + ); + } + + /** + * Test findPage: tools page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageToolsInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_TOOLS, + LegacyRouter::findPage('do=tools', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_TOOLS, + LegacyRouter::findPage('do=tools', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_TOOLS, + LegacyRouter::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: changepasswd page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageChangepasswdValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_CHANGEPASSWORD, + LegacyRouter::findPage('do=changepasswd', array(), true) + ); + $this->assertEquals( + LegacyRouter::$PAGE_CHANGEPASSWORD, + LegacyRouter::findPage('do=changepasswd&stuff', array(), true) + ); + } + + /** + * Test findPage: changepasswd page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageChangepasswdInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_CHANGEPASSWORD, + LegacyRouter::findPage('do=changepasswd', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_CHANGEPASSWORD, + LegacyRouter::findPage('do=changepasswd', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_CHANGEPASSWORD, + LegacyRouter::findPage('do=other', array(), true) + ); + } + /** + * Test findPage: configure page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageConfigureValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_CONFIGURE, + LegacyRouter::findPage('do=configure', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_CONFIGURE, + LegacyRouter::findPage('do=configure&stuff', array(), true) + ); + } + + /** + * Test findPage: configure page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageConfigureInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_CONFIGURE, + LegacyRouter::findPage('do=configure', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_CONFIGURE, + LegacyRouter::findPage('do=configure', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_CONFIGURE, + LegacyRouter::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: changetag page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageChangetagValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_CHANGETAG, + LegacyRouter::findPage('do=changetag', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_CHANGETAG, + LegacyRouter::findPage('do=changetag&stuff', array(), true) + ); + } + + /** + * Test findPage: changetag page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageChangetagInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_CHANGETAG, + LegacyRouter::findPage('do=changetag', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_CHANGETAG, + LegacyRouter::findPage('do=changetag', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_CHANGETAG, + LegacyRouter::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: addlink page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageAddlinkValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_ADDLINK, + LegacyRouter::findPage('do=addlink', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_ADDLINK, + LegacyRouter::findPage('do=addlink&stuff', array(), true) + ); + } + + /** + * Test findPage: addlink page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageAddlinkInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_ADDLINK, + LegacyRouter::findPage('do=addlink', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_ADDLINK, + LegacyRouter::findPage('do=addlink', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_ADDLINK, + LegacyRouter::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: export page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageExportValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_EXPORT, + LegacyRouter::findPage('do=export', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_EXPORT, + LegacyRouter::findPage('do=export&stuff', array(), true) + ); + } + + /** + * Test findPage: export page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageExportInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_EXPORT, + LegacyRouter::findPage('do=export', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_EXPORT, + LegacyRouter::findPage('do=export', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_EXPORT, + LegacyRouter::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: import page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageImportValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_IMPORT, + LegacyRouter::findPage('do=import', array(), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_IMPORT, + LegacyRouter::findPage('do=import&stuff', array(), true) + ); + } + + /** + * Test findPage: import page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageImportInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_IMPORT, + LegacyRouter::findPage('do=import', array(), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_IMPORT, + LegacyRouter::findPage('do=import', array(), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_IMPORT, + LegacyRouter::findPage('do=other', array(), true) + ); + } + + /** + * Test findPage: editlink page output. + * Valid: page should be return. + * + * @return void + */ + public function testFindPageEditlinkValid() + { + $this->assertEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('whatever', array('edit_link' => 1), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('', array('edit_link' => 1), true) + ); + + + $this->assertEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('whatever', array('post' => 1), true) + ); + + $this->assertEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('whatever', array('post' => 1, 'edit_link' => 1), true) + ); + } + + /** + * Test findPage: editlink page output. + * Invalid: page shouldn't be return. + * + * @return void + */ + public function testFindPageEditlinkInvalid() + { + $this->assertNotEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('whatever', array('edit_link' => 1), false) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('whatever', array('edit_link' => 1), 1) + ); + + $this->assertNotEquals( + LegacyRouter::$PAGE_EDITLINK, + LegacyRouter::findPage('whatever', array(), true) + ); + } +} diff --git a/tests/plugins/PluginAddlinkTest.php b/tests/plugins/PluginAddlinkTest.php index d052f8b9..4018c1a8 100644 --- a/tests/plugins/PluginAddlinkTest.php +++ b/tests/plugins/PluginAddlinkTest.php @@ -2,7 +2,7 @@ namespace Shaarli\Plugin\Addlink; use Shaarli\Plugin\PluginManager; -use Shaarli\Router; +use Shaarli\Render\TemplatePage; require_once 'plugins/addlink_toolbar/addlink_toolbar.php'; @@ -26,7 +26,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase { $str = 'stuff'; $data = array($str => $str); - $data['_PAGE_'] = Router::$PAGE_LINKLIST; + $data['_PAGE_'] = TemplatePage::LINKLIST; $data['_LOGGEDIN_'] = true; $data = hook_addlink_toolbar_render_header($data); @@ -48,7 +48,7 @@ class PluginAddlinkTest extends \PHPUnit\Framework\TestCase { $str = 'stuff'; $data = array($str => $str); - $data['_PAGE_'] = Router::$PAGE_LINKLIST; + $data['_PAGE_'] = TemplatePage::LINKLIST; $data['_LOGGEDIN_'] = false; $data = hook_addlink_toolbar_render_header($data); diff --git a/tests/plugins/PluginPlayvideosTest.php b/tests/plugins/PluginPlayvideosTest.php index 51472617..b7b6ce53 100644 --- a/tests/plugins/PluginPlayvideosTest.php +++ b/tests/plugins/PluginPlayvideosTest.php @@ -6,7 +6,7 @@ namespace Shaarli\Plugin\Playvideos; */ use Shaarli\Plugin\PluginManager; -use Shaarli\Router; +use Shaarli\Render\TemplatePage; require_once 'plugins/playvideos/playvideos.php'; @@ -31,7 +31,7 @@ class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase { $str = 'stuff'; $data = array($str => $str); - $data['_PAGE_'] = Router::$PAGE_LINKLIST; + $data['_PAGE_'] = TemplatePage::LINKLIST; $data = hook_playvideos_render_header($data); $this->assertEquals($str, $data[$str]); @@ -50,7 +50,7 @@ class PluginPlayvideosTest extends \PHPUnit\Framework\TestCase { $str = 'stuff'; $data = array($str => $str); - $data['_PAGE_'] = Router::$PAGE_LINKLIST; + $data['_PAGE_'] = TemplatePage::LINKLIST; $data = hook_playvideos_render_footer($data); $this->assertEquals($str, $data[$str]); diff --git a/tests/plugins/PluginPubsubhubbubTest.php b/tests/plugins/PluginPubsubhubbubTest.php index a7bd8fc9..e66f484e 100644 --- a/tests/plugins/PluginPubsubhubbubTest.php +++ b/tests/plugins/PluginPubsubhubbubTest.php @@ -3,7 +3,7 @@ namespace Shaarli\Plugin\Pubsubhubbub; use Shaarli\Config\ConfigManager; use Shaarli\Plugin\PluginManager; -use Shaarli\Router; +use Shaarli\Render\TemplatePage; require_once 'plugins/pubsubhubbub/pubsubhubbub.php'; @@ -34,7 +34,7 @@ class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase $hub = 'http://domain.hub'; $conf = new ConfigManager(self::$configFile); $conf->set('plugins.PUBSUBHUB_URL', $hub); - $data['_PAGE_'] = Router::$PAGE_FEED_RSS; + $data['_PAGE_'] = TemplatePage::FEED_RSS; $data = hook_pubsubhubbub_render_feed($data, $conf); $expected = ''; @@ -49,7 +49,7 @@ class PluginPubsubhubbubTest extends \PHPUnit\Framework\TestCase $hub = 'http://domain.hub'; $conf = new ConfigManager(self::$configFile); $conf->set('plugins.PUBSUBHUB_URL', $hub); - $data['_PAGE_'] = Router::$PAGE_FEED_ATOM; + $data['_PAGE_'] = TemplatePage::FEED_ATOM; $data = hook_pubsubhubbub_render_feed($data, $conf); $expected = ''; diff --git a/tests/plugins/PluginQrcodeTest.php b/tests/plugins/PluginQrcodeTest.php index 0c61e14a..c9f8c733 100644 --- a/tests/plugins/PluginQrcodeTest.php +++ b/tests/plugins/PluginQrcodeTest.php @@ -6,7 +6,7 @@ namespace Shaarli\Plugin\Qrcode; */ use Shaarli\Plugin\PluginManager; -use Shaarli\Router; +use Shaarli\Render\TemplatePage; require_once 'plugins/qrcode/qrcode.php'; @@ -57,7 +57,7 @@ class PluginQrcodeTest extends \PHPUnit\Framework\TestCase { $str = 'stuff'; $data = array($str => $str); - $data['_PAGE_'] = Router::$PAGE_LINKLIST; + $data['_PAGE_'] = TemplatePage::LINKLIST; $data = hook_qrcode_render_footer($data); $this->assertEquals($str, $data[$str]); diff --git a/tests/updater/UpdaterTest.php b/tests/updater/UpdaterTest.php index c689982b..afc35aec 100644 --- a/tests/updater/UpdaterTest.php +++ b/tests/updater/UpdaterTest.php @@ -2,7 +2,10 @@ namespace Shaarli\Updater; use Exception; +use Shaarli\Bookmark\BookmarkFileService; +use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; +use Shaarli\History; require_once 'tests/updater/DummyUpdater.php'; require_once 'tests/utils/ReferenceLinkDB.php'; @@ -29,6 +32,12 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase */ protected $conf; + /** @var BookmarkServiceInterface */ + protected $bookmarkService; + + /** @var Updater */ + protected $updater; + /** * Executed before each test. */ @@ -36,6 +45,8 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase { copy('tests/utils/config/configJson.json.php', self::$configFile .'.json.php'); $this->conf = new ConfigManager(self::$configFile); + $this->bookmarkService = new BookmarkFileService($this->conf, $this->createMock(History::class), true); + $this->updater = new Updater([], $this->bookmarkService, $this->conf, true); } /** @@ -167,4 +178,12 @@ class UpdaterTest extends \PHPUnit\Framework\TestCase $updater = new DummyUpdater($updates, array(), $this->conf, true); $updater->update(); } + + public function testUpdateMethodRelativeHomeLinkRename(): void + { + $this->conf->set('general.header_link', '?'); + $this->updater->updateMethodRelativeHomeLink(); + + static::assertSame(); + } } -- cgit v1.2.3