From 6c50a6ccceecf54850e62c312ab2397b84d89ab4 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 18 Jan 2020 17:50:11 +0100 Subject: Render login page through Slim controller --- tests/container/ContainerBuilderTest.php | 49 ++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/container/ContainerBuilderTest.php (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php new file mode 100644 index 00000000..9b97ed6d --- /dev/null +++ b/tests/container/ContainerBuilderTest.php @@ -0,0 +1,49 @@ +conf = new ConfigManager('tests/utils/config/configJson'); + $this->sessionManager = $this->createMock(SessionManager::class); + $this->loginManager = $this->createMock(LoginManager::class); + + $this->containerBuilder = new ContainerBuilder($this->conf, $this->sessionManager, $this->loginManager); + } + + public function testBuildContainer(): void + { + $container = $this->containerBuilder->build(); + + static::assertInstanceOf(ConfigManager::class, $container->conf); + static::assertInstanceOf(SessionManager::class, $container->sessionManager); + static::assertInstanceOf(LoginManager::class, $container->loginManager); + static::assertInstanceOf(History::class, $container->history); + static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); + static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); + } +} -- cgit v1.2.3 From 485b168a9677d160b0c0426e4f282b9bd0c632c1 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sun, 26 Jan 2020 11:15:15 +0100 Subject: Process picwall rendering through Slim controller + UT --- tests/container/ContainerBuilderTest.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index 9b97ed6d..cc2eb37f 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -7,6 +7,7 @@ namespace Shaarli\Container; use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; +use Shaarli\Formatter\FormatterFactory; use Shaarli\History; use Shaarli\Render\PageBuilder; use Shaarli\Security\LoginManager; @@ -30,7 +31,9 @@ class ContainerBuilderTest extends TestCase { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->sessionManager = $this->createMock(SessionManager::class); + $this->loginManager = $this->createMock(LoginManager::class); + $this->loginManager->method('isLoggedIn')->willReturn(true); $this->containerBuilder = new ContainerBuilder($this->conf, $this->sessionManager, $this->loginManager); } @@ -45,5 +48,6 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(History::class, $container->history); static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); + static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); } } -- cgit v1.2.3 From 8e47af2b3620c920116ec056173277c039163ec1 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 23 Jan 2020 21:52:03 +0100 Subject: Process logout through Slim controller --- tests/container/ContainerBuilderTest.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index cc2eb37f..65647249 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -10,6 +10,7 @@ use Shaarli\Config\ConfigManager; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; use Shaarli\Render\PageBuilder; +use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; @@ -35,7 +36,12 @@ class ContainerBuilderTest extends TestCase $this->loginManager = $this->createMock(LoginManager::class); $this->loginManager->method('isLoggedIn')->willReturn(true); - $this->containerBuilder = new ContainerBuilder($this->conf, $this->sessionManager, $this->loginManager); + $this->containerBuilder = new ContainerBuilder( + $this->conf, + $this->sessionManager, + $this->loginManager, + 'UT web path' + ); } public function testBuildContainer(): void @@ -45,9 +51,11 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(ConfigManager::class, $container->conf); static::assertInstanceOf(SessionManager::class, $container->sessionManager); static::assertInstanceOf(LoginManager::class, $container->loginManager); + static::assertSame('UT web path', $container->webPath); static::assertInstanceOf(History::class, $container->history); static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); + static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); } } -- cgit v1.2.3 From dd09ec52b20b4a548ecf5c847627575e506e3a50 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Wed, 20 May 2020 12:43:40 +0200 Subject: Refactor front controller tests to create container mock using a trait --- tests/container/ShaarliTestContainer.php | 38 ++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/container/ShaarliTestContainer.php (limited to 'tests/container') diff --git a/tests/container/ShaarliTestContainer.php b/tests/container/ShaarliTestContainer.php new file mode 100644 index 00000000..53197ae6 --- /dev/null +++ b/tests/container/ShaarliTestContainer.php @@ -0,0 +1,38 @@ + Date: Sat, 6 Jun 2020 14:01:03 +0200 Subject: Handle shaare creation/edition/deletion through Slim controllers --- tests/container/ShaarliTestContainer.php | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'tests/container') diff --git a/tests/container/ShaarliTestContainer.php b/tests/container/ShaarliTestContainer.php index 53197ae6..7dbe914c 100644 --- a/tests/container/ShaarliTestContainer.php +++ b/tests/container/ShaarliTestContainer.php @@ -10,11 +10,13 @@ use Shaarli\Config\ConfigManager; use Shaarli\Feed\FeedBuilder; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; +use Shaarli\Http\HttpAccess; use Shaarli\Plugin\PluginManager; use Shaarli\Render\PageBuilder; use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\Thumbnailer; /** * Test helper allowing auto-completion for MockObjects. @@ -31,6 +33,8 @@ use Shaarli\Security\SessionManager; * @property MockObject|FormatterFactory $formatterFactory * @property MockObject|PageCacheManager $pageCacheManager * @property MockObject|FeedBuilder $feedBuilder + * @property MockObject|Thumbnailer $thumbnailer + * @property MockObject|HttpAccess $httpAccess */ class ShaarliTestContainer extends ShaarliContainer { -- cgit v1.2.3 From 9c75f877935fa6adec951a4d8d32b328aaab314f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 13 Jun 2020 13:08:01 +0200 Subject: Use multi-level routes for existing controllers instead of 1 level everywhere Also prefix most admin routes with /admin/ --- tests/container/ContainerBuilderTest.php | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index 65647249..db533f37 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -7,12 +7,16 @@ namespace Shaarli\Container; use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; +use Shaarli\Feed\FeedBuilder; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; +use Shaarli\Http\HttpAccess; +use Shaarli\Plugin\PluginManager; use Shaarli\Render\PageBuilder; use Shaarli\Render\PageCacheManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\Thumbnailer; class ContainerBuilderTest extends TestCase { @@ -39,8 +43,7 @@ class ContainerBuilderTest extends TestCase $this->containerBuilder = new ContainerBuilder( $this->conf, $this->sessionManager, - $this->loginManager, - 'UT web path' + $this->loginManager ); } @@ -51,11 +54,17 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(ConfigManager::class, $container->conf); static::assertInstanceOf(SessionManager::class, $container->sessionManager); static::assertInstanceOf(LoginManager::class, $container->loginManager); - static::assertSame('UT web path', $container->webPath); static::assertInstanceOf(History::class, $container->history); static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); + static::assertInstanceOf(PluginManager::class, $container->pluginManager); static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); + static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); + static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); + static::assertInstanceOf(HttpAccess::class, $container->httpAccess); + + // Set by the middleware + static::assertNull($container->basePath); } } -- cgit v1.2.3 From c4ad3d4f061d05a01db25aa54dda830ba776792d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 7 Jul 2020 10:15:56 +0200 Subject: Process Shaarli install through Slim controller --- tests/container/ContainerBuilderTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index db533f37..fa77bf31 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -11,12 +11,15 @@ use Shaarli\Feed\FeedBuilder; use Shaarli\Formatter\FormatterFactory; use Shaarli\History; use Shaarli\Http\HttpAccess; +use Shaarli\Netscape\NetscapeBookmarkUtils; use Shaarli\Plugin\PluginManager; use Shaarli\Render\PageBuilder; use Shaarli\Render\PageCacheManager; +use Shaarli\Security\CookieManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; use Shaarli\Thumbnailer; +use Shaarli\Updater\Updater; class ContainerBuilderTest extends TestCase { @@ -32,10 +35,14 @@ class ContainerBuilderTest extends TestCase /** @var ContainerBuilder */ protected $containerBuilder; + /** @var CookieManager */ + protected $cookieManager; + public function setUp(): void { $this->conf = new ConfigManager('tests/utils/config/configJson'); $this->sessionManager = $this->createMock(SessionManager::class); + $this->cookieManager = $this->createMock(CookieManager::class); $this->loginManager = $this->createMock(LoginManager::class); $this->loginManager->method('isLoggedIn')->willReturn(true); @@ -43,6 +50,7 @@ class ContainerBuilderTest extends TestCase $this->containerBuilder = new ContainerBuilder( $this->conf, $this->sessionManager, + $this->cookieManager, $this->loginManager ); } @@ -53,6 +61,7 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(ConfigManager::class, $container->conf); static::assertInstanceOf(SessionManager::class, $container->sessionManager); + static::assertInstanceOf(CookieManager::class, $container->cookieManager); static::assertInstanceOf(LoginManager::class, $container->loginManager); static::assertInstanceOf(History::class, $container->history); static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); @@ -63,6 +72,8 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); static::assertInstanceOf(HttpAccess::class, $container->httpAccess); + static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils); + static::assertInstanceOf(Updater::class, $container->updater); // Set by the middleware static::assertNull($container->basePath); -- cgit v1.2.3 From 7e3dc0ba98bf019c2804e5c74fb6061b16fb712f Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 27 Aug 2020 12:04:36 +0200 Subject: Better handling of plugin incompatibility If a PHP is raised while executing plugin hook, Shaarli will display an error instead of rendering the error page (or just ending in fatal error for default hooks). Also added phpErrorHandler which is handled differently that regular errorHandler by Slim.: --- tests/container/ContainerBuilderTest.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index fa77bf31..c08010ae 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -9,6 +9,7 @@ use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; use Shaarli\Feed\FeedBuilder; use Shaarli\Formatter\FormatterFactory; +use Shaarli\Front\Controller\Visitor\ErrorController; use Shaarli\History; use Shaarli\Http\HttpAccess; use Shaarli\Netscape\NetscapeBookmarkUtils; @@ -20,6 +21,7 @@ use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; use Shaarli\Thumbnailer; use Shaarli\Updater\Updater; +use Slim\Http\Environment; class ContainerBuilderTest extends TestCase { @@ -59,20 +61,23 @@ class ContainerBuilderTest extends TestCase { $container = $this->containerBuilder->build(); - static::assertInstanceOf(ConfigManager::class, $container->conf); - static::assertInstanceOf(SessionManager::class, $container->sessionManager); + static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); static::assertInstanceOf(CookieManager::class, $container->cookieManager); - static::assertInstanceOf(LoginManager::class, $container->loginManager); + static::assertInstanceOf(ConfigManager::class, $container->conf); + static::assertInstanceOf(ErrorController::class, $container->errorHandler); + static::assertInstanceOf(Environment::class, $container->environment); + static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); + static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); static::assertInstanceOf(History::class, $container->history); - static::assertInstanceOf(BookmarkServiceInterface::class, $container->bookmarkService); + static::assertInstanceOf(HttpAccess::class, $container->httpAccess); + static::assertInstanceOf(LoginManager::class, $container->loginManager); + static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils); static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); - static::assertInstanceOf(PluginManager::class, $container->pluginManager); - static::assertInstanceOf(FormatterFactory::class, $container->formatterFactory); static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); - static::assertInstanceOf(FeedBuilder::class, $container->feedBuilder); + static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler); + static::assertInstanceOf(PluginManager::class, $container->pluginManager); + static::assertInstanceOf(SessionManager::class, $container->sessionManager); static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); - static::assertInstanceOf(HttpAccess::class, $container->httpAccess); - static::assertInstanceOf(NetscapeBookmarkUtils::class, $container->netscapeBookmarkUtils); static::assertInstanceOf(Updater::class, $container->updater); // Set by the middleware -- cgit v1.2.3 From d52ab0b1e99aa0c494f389092dce1e926296032d Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Sat, 12 Sep 2020 12:42:19 +0200 Subject: Properly handle 404 errors Use 404 template instead of default Slim error page if the route is not found. Fixes #827 --- tests/container/ContainerBuilderTest.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index c08010ae..2047a63a 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -10,6 +10,7 @@ use Shaarli\Config\ConfigManager; use Shaarli\Feed\FeedBuilder; use Shaarli\Formatter\FormatterFactory; use Shaarli\Front\Controller\Visitor\ErrorController; +use Shaarli\Front\Controller\Visitor\ErrorNotFoundController; use Shaarli\History; use Shaarli\Http\HttpAccess; use Shaarli\Netscape\NetscapeBookmarkUtils; @@ -75,6 +76,7 @@ class ContainerBuilderTest extends TestCase static::assertInstanceOf(PageBuilder::class, $container->pageBuilder); static::assertInstanceOf(PageCacheManager::class, $container->pageCacheManager); static::assertInstanceOf(ErrorController::class, $container->phpErrorHandler); + static::assertInstanceOf(ErrorNotFoundController::class, $container->notFoundHandler); static::assertInstanceOf(PluginManager::class, $container->pluginManager); static::assertInstanceOf(SessionManager::class, $container->sessionManager); static::assertInstanceOf(Thumbnailer::class, $container->thumbnailer); -- cgit v1.2.3 From a5a9cf23acd1248585173aa32757d9720b5f2d62 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Tue, 29 Sep 2020 14:41:40 +0200 Subject: Compatibility with PHPUnit 9 --- tests/container/ContainerBuilderTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/container') diff --git a/tests/container/ContainerBuilderTest.php b/tests/container/ContainerBuilderTest.php index 2047a63a..5d52daef 100644 --- a/tests/container/ContainerBuilderTest.php +++ b/tests/container/ContainerBuilderTest.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace Shaarli\Container; -use PHPUnit\Framework\TestCase; use Shaarli\Bookmark\BookmarkServiceInterface; use Shaarli\Config\ConfigManager; use Shaarli\Feed\FeedBuilder; @@ -20,6 +19,7 @@ use Shaarli\Render\PageCacheManager; use Shaarli\Security\CookieManager; use Shaarli\Security\LoginManager; use Shaarli\Security\SessionManager; +use Shaarli\TestCase; use Shaarli\Thumbnailer; use Shaarli\Updater\Updater; use Slim\Http\Environment; -- cgit v1.2.3