From: ArthurHoaro Date: Sat, 12 Sep 2020 10:14:18 +0000 (+0200) Subject: Merge pull request #1552 from ArthurHoaro/feature/better-initializer X-Git-Tag: v0.12.0-beta-1~17 X-Git-Url: https://git.immae.eu/?p=github%2Fshaarli%2FShaarli.git;a=commitdiff_plain;h=6128ab6a55430a2b705be31ff417c0c552a0db1f;hp=da7acb98302b99ec729bcde3e3c9f4bb164a1b34 Merge pull request #1552 from ArthurHoaro/feature/better-initializer --- diff --git a/application/bookmark/BookmarkFileService.php b/application/bookmark/BookmarkFileService.php index e3a61146..c9ec2609 100644 --- a/application/bookmark/BookmarkFileService.php +++ b/application/bookmark/BookmarkFileService.php @@ -362,7 +362,9 @@ class BookmarkFileService implements BookmarkServiceInterface */ public function filterDay($request) { - return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request); + $visibility = $this->isLoggedIn ? BookmarkFilter::$ALL : BookmarkFilter::$PUBLIC; + + return $this->bookmarkFilter->filter(BookmarkFilter::$FILTER_DAY, $request, false, $visibility); } /** diff --git a/application/bookmark/BookmarkFilter.php b/application/bookmark/BookmarkFilter.php index 797a36b8..6636bbfe 100644 --- a/application/bookmark/BookmarkFilter.php +++ b/application/bookmark/BookmarkFilter.php @@ -115,7 +115,7 @@ class BookmarkFilter return $this->filterTags($request, $casesensitive, $visibility); } case self::$FILTER_DAY: - return $this->filterDay($request); + return $this->filterDay($request, $visibility); default: return $this->noFilter($visibility); } @@ -425,21 +425,26 @@ class BookmarkFilter * print_r($mydb->filterDay('20120125')); * * @param string $day day to filter. - * + * @param string $visibility return only all/private/public bookmarks. + * @return array all link matching given day. * * @throws Exception if date format is invalid. */ - public function filterDay($day) + public function filterDay($day, $visibility) { if (!checkDateFormat('Ymd', $day)) { throw new Exception('Invalid date format'); } $filtered = []; - foreach ($this->bookmarks as $key => $l) { - if ($l->getCreated()->format('Ymd') == $day) { - $filtered[$key] = $l; + foreach ($this->bookmarks as $key => $bookmark) { + if ($visibility === static::$PUBLIC && $bookmark->isPrivate()) { + continue; + } + + if ($bookmark->getCreated()->format('Ymd') == $day) { + $filtered[$key] = $bookmark; } } diff --git a/application/front/controller/admin/ShaarliAdminController.php b/application/front/controller/admin/ShaarliAdminController.php index 3b5939bb..c26c9cbe 100644 --- a/application/front/controller/admin/ShaarliAdminController.php +++ b/application/front/controller/admin/ShaarliAdminController.php @@ -4,9 +4,7 @@ declare(strict_types=1); namespace Shaarli\Front\Controller\Admin; -use Shaarli\Container\ShaarliContainer; use Shaarli\Front\Controller\Visitor\ShaarliVisitorController; -use Shaarli\Front\Exception\UnauthorizedException; use Shaarli\Front\Exception\WrongTokenException; use Shaarli\Security\SessionManager; use Slim\Http\Request; diff --git a/application/front/controller/visitor/FeedController.php b/application/front/controller/visitor/FeedController.php index da2848c2..8d8b546a 100644 --- a/application/front/controller/visitor/FeedController.php +++ b/application/front/controller/visitor/FeedController.php @@ -46,10 +46,10 @@ class FeedController extends ShaarliVisitorController $data = $this->container->feedBuilder->buildData($feedType, $request->getParams()); - $this->executePageHooks('render_feed', $data, $feedType); + $this->executePageHooks('render_feed', $data, 'feed.' . $feedType); $this->assignAllView($data); - $content = $this->render('feed.'. $feedType); + $content = $this->render('feed.' . $feedType); $cache->cache($content); diff --git a/application/front/controller/visitor/ShaarliVisitorController.php b/application/front/controller/visitor/ShaarliVisitorController.php index f17c8ed3..cd27455b 100644 --- a/application/front/controller/visitor/ShaarliVisitorController.php +++ b/application/front/controller/visitor/ShaarliVisitorController.php @@ -78,16 +78,14 @@ abstract class ShaarliVisitorController 'footer', ]; + $parameters = $this->buildPluginParameters($template); + foreach ($common_hooks as $name) { $pluginData = []; $this->container->pluginManager->executeHooks( 'render_' . $name, $pluginData, - [ - 'target' => $template, - 'loggedin' => $this->container->loginManager->isLoggedIn(), - 'basePath' => $this->container->basePath, - ] + $parameters ); $this->assignView('plugins_' . $name, $pluginData); } @@ -95,19 +93,23 @@ abstract class ShaarliVisitorController protected function executePageHooks(string $hook, array &$data, string $template = null): void { - $params = [ - 'target' => $template, - 'loggedin' => $this->container->loginManager->isLoggedIn(), - 'basePath' => $this->container->basePath, - ]; - $this->container->pluginManager->executeHooks( $hook, $data, - $params + $this->buildPluginParameters($template) ); } + protected function buildPluginParameters(?string $template): array + { + return [ + 'target' => $template, + 'loggedin' => $this->container->loginManager->isLoggedIn(), + 'basePath' => $this->container->basePath, + 'bookmarkService' => $this->container->bookmarkService + ]; + } + /** * Simple helper which prepend the base path to redirect path. * diff --git a/application/legacy/LegacyController.php b/application/legacy/LegacyController.php index e16dd0f4..826604e7 100644 --- a/application/legacy/LegacyController.php +++ b/application/legacy/LegacyController.php @@ -39,13 +39,23 @@ class LegacyController extends ShaarliVisitorController /** Legacy route: ?post= */ public function post(Request $request, Response $response): Response { - $parameters = count($request->getQueryParams()) > 0 ? '?' . http_build_query($request->getQueryParams()) : ''; $route = '/admin/shaare'; + $buildParameters = function (?array $parameters, bool $encode) { + if ($encode) { + $parameters = array_map('urlencode', $parameters); + } + + return count($parameters) > 0 ? '?' . http_build_query($parameters) : ''; + }; + if (!$this->container->loginManager->isLoggedIn()) { + $parameters = $buildParameters($request->getQueryParams(), true); return $this->redirect($response, '/login?returnurl='. $this->getBasePath() . $route . $parameters); } + $parameters = $buildParameters($request->getQueryParams(), false); + return $this->redirect($response, $route . $parameters); } diff --git a/application/legacy/LegacyRouter.php b/application/legacy/LegacyRouter.php index cea99154..0449c7e1 100644 --- a/application/legacy/LegacyRouter.php +++ b/application/legacy/LegacyRouter.php @@ -17,15 +17,15 @@ class LegacyRouter public static $PAGE_PICWALL = 'picwall'; - public static $PAGE_TAGCLOUD = 'tagcloud'; + public static $PAGE_TAGCLOUD = 'tag.cloud'; - public static $PAGE_TAGLIST = 'taglist'; + public static $PAGE_TAGLIST = 'tag.list'; public static $PAGE_DAILY = 'daily'; - public static $PAGE_FEED_ATOM = 'atom'; + public static $PAGE_FEED_ATOM = 'feed.atom'; - public static $PAGE_FEED_RSS = 'rss'; + public static $PAGE_FEED_RSS = 'feed.rss'; public static $PAGE_TOOLS = 'tools'; @@ -37,7 +37,7 @@ class LegacyRouter public static $PAGE_ADDLINK = 'addlink'; - public static $PAGE_EDITLINK = 'edit_link'; + public static $PAGE_EDITLINK = 'editlink'; public static $PAGE_DELETELINK = 'delete_link'; @@ -60,128 +60,4 @@ class LegacyRouter public static $PAGE_THUMBS_UPDATE = 'thumbs_update'; public static $GET_TOKEN = 'token'; - - /** - * Reproducing renderPage() if hell, to avoid regression. - * - * This highlights how bad this needs to be rewrite, - * but let's focus on plugins for now. - * - * @param string $query $_SERVER['QUERY_STRING']. - * @param array $get $_SERVER['GET']. - * @param bool $loggedIn true if authenticated user. - * - * @return string page found. - */ - public static function findPage($query, $get, $loggedIn) - { - $loggedIn = ($loggedIn === true) ? true : false; - - if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) { - return self::$PAGE_LINKLIST; - } - - if (startsWith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) { - return self::$PAGE_LOGIN; - } - - if (startsWith($query, 'do=' . self::$PAGE_PICWALL)) { - return self::$PAGE_PICWALL; - } - - if (startsWith($query, 'do=' . self::$PAGE_TAGCLOUD)) { - return self::$PAGE_TAGCLOUD; - } - - if (startsWith($query, 'do=' . self::$PAGE_TAGLIST)) { - return self::$PAGE_TAGLIST; - } - - if (startsWith($query, 'do=' . self::$PAGE_OPENSEARCH)) { - return self::$PAGE_OPENSEARCH; - } - - if (startsWith($query, 'do=' . self::$PAGE_DAILY)) { - return self::$PAGE_DAILY; - } - - if (startsWith($query, 'do=' . self::$PAGE_FEED_ATOM)) { - return self::$PAGE_FEED_ATOM; - } - - if (startsWith($query, 'do=' . self::$PAGE_FEED_RSS)) { - return self::$PAGE_FEED_RSS; - } - - if (startsWith($query, 'do=' . self::$PAGE_THUMBS_UPDATE)) { - return self::$PAGE_THUMBS_UPDATE; - } - - if (startsWith($query, 'do=' . self::$AJAX_THUMB_UPDATE)) { - return self::$AJAX_THUMB_UPDATE; - } - - // At this point, only loggedin pages. - if (!$loggedIn) { - return self::$PAGE_LINKLIST; - } - - if (startsWith($query, 'do=' . self::$PAGE_TOOLS)) { - return self::$PAGE_TOOLS; - } - - if (startsWith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) { - return self::$PAGE_CHANGEPASSWORD; - } - - if (startsWith($query, 'do=' . self::$PAGE_CONFIGURE)) { - return self::$PAGE_CONFIGURE; - } - - if (startsWith($query, 'do=' . self::$PAGE_CHANGETAG)) { - return self::$PAGE_CHANGETAG; - } - - if (startsWith($query, 'do=' . self::$PAGE_ADDLINK)) { - return self::$PAGE_ADDLINK; - } - - if (isset($get['edit_link']) || isset($get['post'])) { - return self::$PAGE_EDITLINK; - } - - if (isset($get['delete_link'])) { - return self::$PAGE_DELETELINK; - } - - if (isset($get[self::$PAGE_CHANGE_VISIBILITY])) { - return self::$PAGE_CHANGE_VISIBILITY; - } - - if (startsWith($query, 'do=' . self::$PAGE_PINLINK)) { - return self::$PAGE_PINLINK; - } - - if (startsWith($query, 'do=' . self::$PAGE_EXPORT)) { - return self::$PAGE_EXPORT; - } - - if (startsWith($query, 'do=' . self::$PAGE_IMPORT)) { - return self::$PAGE_IMPORT; - } - - if (startsWith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) { - return self::$PAGE_PLUGINSADMIN; - } - - if (startsWith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) { - return self::$PAGE_SAVE_PLUGINSADMIN; - } - - if (startsWith($query, 'do=' . self::$GET_TOKEN)) { - return self::$GET_TOKEN; - } - - return self::$PAGE_LINKLIST; - } } diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php index 2d93cb3a..7881e3be 100644 --- a/application/plugin/PluginManager.php +++ b/application/plugin/PluginManager.php @@ -112,6 +112,10 @@ class PluginManager $data['_BASE_PATH_'] = $params['basePath']; } + if (isset($params['bookmarkService'])) { + $data['_BOOKMARK_SERVICE_'] = $params['bookmarkService']; + } + foreach ($this->loadedPlugins as $plugin) { $hookFunction = $this->buildHookName($hook, $plugin); diff --git a/doc/md/Plugin-System.md b/doc/md/Plugin-System.md index f264e873..87a2638d 100644 --- a/doc/md/Plugin-System.md +++ b/doc/md/Plugin-System.md @@ -73,6 +73,26 @@ Every hook function has a `$data` parameter. Its content differs for each hooks. return $data; +#### Special data + +Special additional data are passed to every hook through the +`$data` parameter to give you access to additional context, and services. + +Complete list: + + * `_PAGE_` (string): if the current hook is used to render a template, its name is passed through this additional parameter. + * `_LOGGEDIN_` (bool): whether the user is logged in or not. + * `_BASE_PATH_` (string): if Shaarli instance is hosted under a subfolder, contains the subfolder path to `index.php` (e.g. `https://domain.tld/shaarli/` -> `/shaarli/`). + * `_BOOKMARK_SERVICE_` (`BookmarkServiceInterface`): bookmark service instance, for advanced usage. + +Example: + +```php +if ($data['_PAGE_'] === TemplatePage::LINKLIST && $data['LOGGEDIN'] === true) { + // Do something for logged in users when the link list is rendered +} +``` + #### Filling templates placeholder Template placeholders are displayed in template in specific places. @@ -95,7 +115,7 @@ When a page is displayed, every variable send to the template engine is passed t The data contained by this array can be altered before template rendering. -For exemple, in linklist, it is possible to alter every title: +For example, in linklist, it is possible to alter every title: ```php // mind the reference if you want $data to be altered @@ -156,8 +176,7 @@ Allow plugin to add content in page headers. `$data` is an array containing: -- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.). -- `_LOGGEDIN_`: true if user is logged in, false otherwise. + - [Special data](#special-data) ##### Template placeholders @@ -185,8 +204,7 @@ Allow plugin to include their own CSS files. `$data` is an array containing: -- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.). -- `_LOGGEDIN_`: true if user is logged in, false otherwise. + - [Special data](#special-data) ##### Template placeholders @@ -208,8 +226,7 @@ Allow plugin to add content in page footer and include their own JS files. `$data` is an array containing: -- `_PAGE_`: current target page (eg: `linklist`, `picwall`, etc.). -- `_LOGGEDIN_`: true if user is logged in, false otherwise. + - [Special data](#special-data) ##### Template placeholders @@ -236,8 +253,8 @@ It allows to add content at the begining and end of the page, after every link d `$data` is an array containing: -- `_LOGGEDIN_`: true if user is logged in, false otherwise. -- All templates data, including links. + - All templates data, including links. + - [Special data](#special-data) ##### Template placeholders @@ -271,7 +288,8 @@ Allow to add fields in the form, or display elements. `$data` is an array containing: -- All templates data. + - All templates data. + - [Special data](#special-data) ##### Template placeholders @@ -293,7 +311,8 @@ Allow to add content at the end of the page. `$data` is an array containing: -- All templates data. + - All templates data. + - [Special data](#special-data) ##### Template placeholders @@ -315,8 +334,8 @@ Allow to add content at the top and bottom of the page. `$data` is an array containing: -- `_LOGGEDIN_`: true if user is logged in, false otherwise. -- All templates data. + - All templates data. + - [Special data](#special-data) ##### Template placeholders @@ -339,8 +358,8 @@ Allow to add content at the top and bottom of the page. `$data` is an array containing: -- `_LOGGEDIN_`: true if user is logged in, false otherwise. -- All templates data. + - All templates data. + - [Special data](#special-data) ##### Template placeholders @@ -368,8 +387,8 @@ Allow to add content at the top and bottom of the page. `$data` is an array containing: -- `_LOGGEDIN_`: true if user is logged in, false otherwise. -- All templates data. + - All templates data. + - [Special data](#special-data) ##### Template placeholders @@ -394,8 +413,8 @@ Allow to add content at the top and bottom of the page, the bottom of each link `$data` is an array containing: -- `_LOGGEDIN_`: true if user is logged in, false otherwise. -- All templates data, including links. + - All templates data, including links. + - [Special data](#special-data) ##### Template placeholders @@ -420,9 +439,8 @@ Allow to add tags in the feed, either in the header or for each items. Items (li `$data` is an array containing: -- `_LOGGEDIN_`: true if user is logged in, false otherwise. -- `_PAGE_`: containing either `rss` or `atom`. -- All templates data, including links. + - All templates data, including links. + - [Special data](#special-data) ##### Template placeholders @@ -456,6 +474,8 @@ Allow to alter the link being saved in the datastore. - created - updated +Also [special data](#special-data). + #### delete_link @@ -465,7 +485,7 @@ Allow to execute any action before the link is actually removed from the datasto ##### Data -`$data` is an array containing the link being saved: +`$data` is an array containing the link being deleted: - id - title @@ -477,6 +497,7 @@ Allow to execute any action before the link is actually removed from the datasto - created - updated +Also [special data](#special-data). #### save_plugin_parameters @@ -492,6 +513,7 @@ For example it is used to update the CSS file of the `default_colors` plugins. So if the plugin has a parameter called `MYPLUGIN_PARAMETER`, the array will contain an entry with `MYPLUGIN_PARAMETER` as a key. +Also [special data](#special-data). ## Guide for template designer diff --git a/package.json b/package.json index f3d9b51e..dc2b2872 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "eslint-plugin-import": "^2.8.0", "extract-text-webpack-plugin": "^3.0.2", "file-loader": "^1.1.6", - "node-sass": "^4.12.0", + "node-sass": "^4.13.1", "sass-lint": "^1.12.1", "sass-loader": "^6.0.6", "style-loader": "^0.19.1", diff --git a/plugins/qrcode/qrcode.php b/plugins/qrcode/qrcode.php index 3b5dae34..56ae47b3 100644 --- a/plugins/qrcode/qrcode.php +++ b/plugins/qrcode/qrcode.php @@ -42,7 +42,7 @@ function hook_qrcode_render_linklist($data) function hook_qrcode_render_footer($data) { if ($data['_PAGE_'] == TemplatePage::LINKLIST) { - $data['js_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js'; + $data['js_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/shaarli-qrcode.js'; } return $data; @@ -58,7 +58,7 @@ function hook_qrcode_render_footer($data) function hook_qrcode_render_includes($data) { if ($data['_PAGE_'] == TemplatePage::LINKLIST) { - $data['css_files'][] = PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css'; + $data['css_files'][] = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.css'; } return $data; diff --git a/tests/bookmark/BookmarkFileServiceTest.php b/tests/bookmark/BookmarkFileServiceTest.php index a91f374f..a4ec1013 100644 --- a/tests/bookmark/BookmarkFileServiceTest.php +++ b/tests/bookmark/BookmarkFileServiceTest.php @@ -1065,6 +1065,36 @@ class BookmarkFileServiceTest extends TestCase $this->assertEquals($expected, $tags, var_export($tags, true)); } + /** + * Test filterDay while logged in + */ + public function testFilterDayLoggedIn(): void + { + $bookmarks = $this->privateLinkDB->filterDay('20121206'); + $expectedIds = [4, 9, 1, 0]; + + static::assertCount(4, $bookmarks); + foreach ($bookmarks as $bookmark) { + $i = ($i ?? -1) + 1; + static::assertSame($expectedIds[$i], $bookmark->getId()); + } + } + + /** + * Test filterDay while logged out + */ + public function testFilterDayLoggedOut(): void + { + $bookmarks = $this->publicLinkDB->filterDay('20121206'); + $expectedIds = [4, 9, 1]; + + static::assertCount(3, $bookmarks); + foreach ($bookmarks as $bookmark) { + $i = ($i ?? -1) + 1; + static::assertSame($expectedIds[$i], $bookmark->getId()); + } + } + /** * Allows to test LinkDB's private methods * diff --git a/tests/bookmark/BookmarkFilterTest.php b/tests/bookmark/BookmarkFilterTest.php index d4c71cb9..91e139c2 100644 --- a/tests/bookmark/BookmarkFilterTest.php +++ b/tests/bookmark/BookmarkFilterTest.php @@ -6,7 +6,6 @@ use Exception; use PHPUnit\Framework\TestCase; use ReferenceLinkDB; use Shaarli\Config\ConfigManager; -use Shaarli\Formatter\FormatterFactory; use Shaarli\History; /** @@ -36,7 +35,7 @@ class BookmarkFilterTest extends TestCase /** * Instantiate linkFilter with ReferenceLinkDB data. */ - public static function setUpBeforeClass() + public static function setUpBeforeClass(): void { $conf = new ConfigManager('tests/utils/config/configJson'); $conf->set('resource.datastore', self::$testDatastore); @@ -189,6 +188,17 @@ class BookmarkFilterTest extends TestCase ); } + /** + * Return bookmarks for a given day + */ + public function testFilterDayRestrictedVisibility(): void + { + $this->assertEquals( + 3, + count(self::$linkFilter->filter(BookmarkFilter::$FILTER_DAY, '20121206', false, BookmarkFilter::$PUBLIC)) + ); + } + /** * 404 - day not found */ diff --git a/tests/front/controller/visitor/FeedControllerTest.php b/tests/front/controller/visitor/FeedControllerTest.php index fb417e2a..0a6b577f 100644 --- a/tests/front/controller/visitor/FeedControllerTest.php +++ b/tests/front/controller/visitor/FeedControllerTest.php @@ -52,7 +52,7 @@ class FeedControllerTest extends TestCase static::assertSame('data', $data['content']); static::assertArrayHasKey('loggedin', $param); - static::assertSame('rss', $param['target']); + static::assertSame('feed.rss', $param['target']); }) ; @@ -91,7 +91,7 @@ class FeedControllerTest extends TestCase static::assertSame('data', $data['content']); static::assertArrayHasKey('loggedin', $param); - static::assertSame('atom', $param['target']); + static::assertSame('feed.atom', $param['target']); }) ; @@ -131,7 +131,7 @@ class FeedControllerTest extends TestCase static::assertSame('data', $data['content']); static::assertArrayHasKey('loggedin', $param); - static::assertSame('atom', $param['target']); + static::assertSame('feed.atom', $param['target']); }) ; diff --git a/tests/legacy/LegacyRouterTest.php b/tests/legacy/LegacyRouterTest.php deleted file mode 100644 index c2019ca7..00000000 --- a/tests/legacy/LegacyRouterTest.php +++ /dev/null @@ -1,512 +0,0 @@ -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/yarn.lock b/yarn.lock index df647950..a7ddcfd3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3432,10 +3432,10 @@ lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.10: - version "4.17.19" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" - integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== +lodash@^4.0.0, lodash@^4.17.11, lodash@^4.17.15, lodash@^4.17.4, lodash@^4.3.0, lodash@~4.17.10: + version "4.17.20" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" + integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== longest@^1.0.1: version "1.0.1" @@ -3787,10 +3787,10 @@ node-pre-gyp@^0.12.0: semver "^5.3.0" tar "^4" -node-sass@^4.12.0: - version "4.12.0" - resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.12.0.tgz#0914f531932380114a30cc5fa4fa63233a25f017" - integrity sha512-A1Iv4oN+Iel6EPv77/HddXErL2a+gZ4uBeZUy+a8O35CFYTXhgA8MgLCWBtwpGZdCvTvQ9d+bQxX/QC36GDPpQ== +node-sass@^4.13.1: + version "4.13.1" + resolved "https://registry.yarnpkg.com/node-sass/-/node-sass-4.13.1.tgz#9db5689696bb2eec2c32b98bfea4c7a2e992d0a3" + integrity sha512-TTWFx+ZhyDx1Biiez2nB0L3YrCZ/8oHagaDalbuBSlqXgUPsdkUSzJsVxeDO9LtPB49+Fh3WQl3slABo6AotNw== dependencies: async-foreach "^0.1.3" chalk "^1.1.1" @@ -3799,7 +3799,7 @@ node-sass@^4.12.0: get-stdin "^4.0.1" glob "^7.0.3" in-publish "^2.0.0" - lodash "^4.17.11" + lodash "^4.17.15" meow "^3.7.0" mkdirp "^0.5.1" nan "^2.13.2"