From b93cfeba7b5ddb8b20d805017404e73eafd68c95 Mon Sep 17 00:00:00 2001 From: ArthurHoaro Date: Thu, 3 Sep 2020 14:52:34 +0200 Subject: Fix subfolder configuration in unit tests --- .../controller/admin/ExportControllerTest.php | 2 +- .../front/controller/admin/ToolsControllerTest.php | 6 ++-- .../controller/visitor/DailyControllerTest.php | 12 ++++---- .../visitor/FrontControllerMockHelper.php | 3 +- .../controller/visitor/InstallControllerTest.php | 35 +++++++++++++++++++++- .../visitor/OpenSearchControllerTest.php | 2 +- 6 files changed, 47 insertions(+), 13 deletions(-) (limited to 'tests/front') diff --git a/tests/front/controller/admin/ExportControllerTest.php b/tests/front/controller/admin/ExportControllerTest.php index 50d9e378..12d26f4a 100644 --- a/tests/front/controller/admin/ExportControllerTest.php +++ b/tests/front/controller/admin/ExportControllerTest.php @@ -84,7 +84,7 @@ class ExportControllerTest extends TestCase static::assertInstanceOf(BookmarkRawFormatter::class, $formatter); static::assertSame($parameters['selection'], $selection); static::assertTrue($prependNoteUrl); - static::assertSame('http://shaarli', $indexUrl); + static::assertSame('http://shaarli/subfolder/', $indexUrl); return $bookmarks; } diff --git a/tests/front/controller/admin/ToolsControllerTest.php b/tests/front/controller/admin/ToolsControllerTest.php index fc756f0f..39144d2f 100644 --- a/tests/front/controller/admin/ToolsControllerTest.php +++ b/tests/front/controller/admin/ToolsControllerTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use Slim\Http\Request; use Slim\Http\Response; -class ToolsControllerTestControllerTest extends TestCase +class ToolsControllerTest extends TestCase { use FrontAdminControllerMockHelper; @@ -41,7 +41,7 @@ class ToolsControllerTestControllerTest extends TestCase static::assertSame(200, $result->getStatusCode()); static::assertSame('tools', (string) $result->getBody()); - static::assertSame('https://shaarli', $assignedVariables['pageabsaddr']); + static::assertSame('https://shaarli/', $assignedVariables['pageabsaddr']); static::assertTrue($assignedVariables['sslenabled']); } @@ -63,7 +63,7 @@ class ToolsControllerTestControllerTest extends TestCase static::assertSame(200, $result->getStatusCode()); static::assertSame('tools', (string) $result->getBody()); - static::assertSame('http://shaarli', $assignedVariables['pageabsaddr']); + static::assertSame('http://shaarli/', $assignedVariables['pageabsaddr']); static::assertFalse($assignedVariables['sslenabled']); } } diff --git a/tests/front/controller/visitor/DailyControllerTest.php b/tests/front/controller/visitor/DailyControllerTest.php index b802c62c..cb5b96f3 100644 --- a/tests/front/controller/visitor/DailyControllerTest.php +++ b/tests/front/controller/visitor/DailyControllerTest.php @@ -392,8 +392,8 @@ class DailyControllerTest extends TestCase static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); static::assertSame('dailyrss', (string) $result->getBody()); static::assertSame('Shaarli', $assignedVariables['title']); - static::assertSame('http://shaarli', $assignedVariables['index_url']); - static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); + static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']); + static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']); static::assertFalse($assignedVariables['hide_timestamps']); static::assertCount(2, $assignedVariables['days']); @@ -402,7 +402,7 @@ class DailyControllerTest extends TestCase static::assertEquals($dates[0], $day['date']); static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']); static::assertSame(format_date($dates[0], false), $day['date_human']); - static::assertSame('http://shaarli/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']); + static::assertSame('http://shaarli/subfolder/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']); static::assertCount(1, $day['links']); static::assertSame(1, $day['links'][0]['id']); static::assertSame('http://domain.tld/1', $day['links'][0]['url']); @@ -413,7 +413,7 @@ class DailyControllerTest extends TestCase static::assertEquals($dates[1], $day['date']); static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']); static::assertSame(format_date($dates[1], false), $day['date_human']); - static::assertSame('http://shaarli/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']); + static::assertSame('http://shaarli/subfolder/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']); static::assertCount(2, $day['links']); static::assertSame(2, $day['links'][0]['id']); @@ -468,8 +468,8 @@ class DailyControllerTest extends TestCase static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); static::assertSame('dailyrss', (string) $result->getBody()); static::assertSame('Shaarli', $assignedVariables['title']); - static::assertSame('http://shaarli', $assignedVariables['index_url']); - static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); + static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']); + static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']); static::assertFalse($assignedVariables['hide_timestamps']); static::assertCount(0, $assignedVariables['days']); } diff --git a/tests/front/controller/visitor/FrontControllerMockHelper.php b/tests/front/controller/visitor/FrontControllerMockHelper.php index e0bd4ecf..fe6ac9b0 100644 --- a/tests/front/controller/visitor/FrontControllerMockHelper.php +++ b/tests/front/controller/visitor/FrontControllerMockHelper.php @@ -79,8 +79,9 @@ trait FrontControllerMockHelper $this->container->environment = [ 'SERVER_NAME' => 'shaarli', 'SERVER_PORT' => '80', - 'REQUEST_URI' => '/daily-rss', + 'REQUEST_URI' => '/subfolder/daily-rss', 'REMOTE_ADDR' => '1.2.3.4', + 'SCRIPT_NAME' => '/subfolder/index.php', ]; $this->container->basePath = '/subfolder'; diff --git a/tests/front/controller/visitor/InstallControllerTest.php b/tests/front/controller/visitor/InstallControllerTest.php index 3b855365..994d3f33 100644 --- a/tests/front/controller/visitor/InstallControllerTest.php +++ b/tests/front/controller/visitor/InstallControllerTest.php @@ -257,6 +257,39 @@ class InstallControllerTest extends TestCase static::assertSame('/subfolder/login', $result->getHeader('location')[0]); static::assertSame('UTC', $confSettings['general.timezone']); - static::assertSame('Shared bookmarks on http://shaarli', $confSettings['general.title']); + static::assertSame('Shared bookmarks on http://shaarli/subfolder/', $confSettings['general.title']); + } + + /** + * Same test as testSaveInstallDefaultValues() but for an instance install in root directory. + */ + public function testSaveInstallDefaultValuesWithoutSubfolder(): void + { + $confSettings = []; + + $this->container->environment = [ + 'SERVER_NAME' => 'shaarli', + 'SERVER_PORT' => '80', + 'REQUEST_URI' => '/install', + 'REMOTE_ADDR' => '1.2.3.4', + 'SCRIPT_NAME' => '/index.php', + ]; + + $this->container->basePath = ''; + + $request = $this->createMock(Request::class); + $response = new Response(); + + $this->container->conf->method('set')->willReturnCallback(function (string $key, $value) use (&$confSettings) { + $confSettings[$key] = $value; + }); + + $result = $this->controller->save($request, $response); + + static::assertSame(302, $result->getStatusCode()); + static::assertSame('/login', $result->getHeader('location')[0]); + + static::assertSame('UTC', $confSettings['general.timezone']); + static::assertSame('Shared bookmarks on http://shaarli/', $confSettings['general.title']); } } diff --git a/tests/front/controller/visitor/OpenSearchControllerTest.php b/tests/front/controller/visitor/OpenSearchControllerTest.php index 5f9f5b12..9609a377 100644 --- a/tests/front/controller/visitor/OpenSearchControllerTest.php +++ b/tests/front/controller/visitor/OpenSearchControllerTest.php @@ -39,6 +39,6 @@ class OpenSearchControllerTest extends TestCase $result->getHeader('Content-Type')[0] ); static::assertSame('opensearch', (string) $result->getBody()); - static::assertSame('http://shaarli', $assignedVariables['serverurl']); + static::assertSame('http://shaarli/subfolder/', $assignedVariables['serverurl']); } } -- cgit v1.2.3