aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-09-03 14:52:34 +0200
committerArthurHoaro <arthur@hoa.ro>2020-09-12 21:39:01 +0200
commitb93cfeba7b5ddb8b20d805017404e73eafd68c95 (patch)
treec99dfd008bc9f5869358b95916831e4f82a62d7f /tests
parent650a5f09cbeb1c1bef19810c6cc504c06d5b7e87 (diff)
downloadShaarli-b93cfeba7b5ddb8b20d805017404e73eafd68c95.tar.gz
Shaarli-b93cfeba7b5ddb8b20d805017404e73eafd68c95.tar.zst
Shaarli-b93cfeba7b5ddb8b20d805017404e73eafd68c95.zip
Fix subfolder configuration in unit tests
Diffstat (limited to 'tests')
-rw-r--r--tests/feed/FeedBuilderTest.php13
-rw-r--r--tests/front/controller/admin/ExportControllerTest.php2
-rw-r--r--tests/front/controller/admin/ToolsControllerTest.php6
-rw-r--r--tests/front/controller/visitor/DailyControllerTest.php12
-rw-r--r--tests/front/controller/visitor/FrontControllerMockHelper.php3
-rw-r--r--tests/front/controller/visitor/InstallControllerTest.php35
-rw-r--r--tests/front/controller/visitor/OpenSearchControllerTest.php2
7 files changed, 54 insertions, 19 deletions
diff --git a/tests/feed/FeedBuilderTest.php b/tests/feed/FeedBuilderTest.php
index fe37d5f2..5dfe73aa 100644
--- a/tests/feed/FeedBuilderTest.php
+++ b/tests/feed/FeedBuilderTest.php
@@ -3,6 +3,7 @@
3namespace Shaarli\Feed; 3namespace Shaarli\Feed;
4 4
5use DateTime; 5use DateTime;
6use PHPUnit\Framework\TestCase;
6use ReferenceLinkDB; 7use ReferenceLinkDB;
7use Shaarli\Bookmark\Bookmark; 8use Shaarli\Bookmark\Bookmark;
8use Shaarli\Bookmark\BookmarkFileService; 9use Shaarli\Bookmark\BookmarkFileService;
@@ -16,7 +17,7 @@ use Shaarli\History;
16 * 17 *
17 * Unit tests for FeedBuilder. 18 * Unit tests for FeedBuilder.
18 */ 19 */
19class FeedBuilderTest extends \PHPUnit\Framework\TestCase 20class FeedBuilderTest extends TestCase
20{ 21{
21 /** 22 /**
22 * @var string locale Basque (Spain). 23 * @var string locale Basque (Spain).
@@ -44,7 +45,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
44 /** 45 /**
45 * Called before every test method. 46 * Called before every test method.
46 */ 47 */
47 public static function setUpBeforeClass() 48 public static function setUpBeforeClass(): void
48 { 49 {
49 $conf = new ConfigManager('tests/utils/config/configJson'); 50 $conf = new ConfigManager('tests/utils/config/configJson');
50 $conf->set('resource.datastore', self::$testDatastore); 51 $conf->set('resource.datastore', self::$testDatastore);
@@ -60,7 +61,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
60 'SERVER_NAME' => 'host.tld', 61 'SERVER_NAME' => 'host.tld',
61 'SERVER_PORT' => '80', 62 'SERVER_PORT' => '80',
62 'SCRIPT_NAME' => '/index.php', 63 'SCRIPT_NAME' => '/index.php',
63 'REQUEST_URI' => '/index.php?do=feed', 64 'REQUEST_URI' => '/feed/atom',
64 ); 65 );
65 } 66 }
66 67
@@ -81,7 +82,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
81 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']); 82 $this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
82 $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']); 83 $this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']);
83 $this->assertEquals(true, $data['show_dates']); 84 $this->assertEquals(true, $data['show_dates']);
84 $this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']); 85 $this->assertEquals('http://host.tld/feed/atom', $data['self_link']);
85 $this->assertEquals('http://host.tld/', $data['index_url']); 86 $this->assertEquals('http://host.tld/', $data['index_url']);
86 $this->assertFalse($data['usepermalinks']); 87 $this->assertFalse($data['usepermalinks']);
87 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links'])); 88 $this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
@@ -253,7 +254,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
253 'SERVER_NAME' => 'host.tld', 254 'SERVER_NAME' => 'host.tld',
254 'SERVER_PORT' => '8080', 255 'SERVER_PORT' => '8080',
255 'SCRIPT_NAME' => '/~user/shaarli/index.php', 256 'SCRIPT_NAME' => '/~user/shaarli/index.php',
256 'REQUEST_URI' => '/~user/shaarli/index.php?do=feed', 257 'REQUEST_URI' => '/~user/shaarli/feed/atom',
257 ); 258 );
258 $feedBuilder = new FeedBuilder( 259 $feedBuilder = new FeedBuilder(
259 self::$bookmarkService, 260 self::$bookmarkService,
@@ -265,7 +266,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
265 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null); 266 $data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
266 267
267 $this->assertEquals( 268 $this->assertEquals(
268 'http://host.tld:8080/~user/shaarli/index.php?do=feed', 269 'http://host.tld:8080/~user/shaarli/feed/atom',
269 $data['self_link'] 270 $data['self_link']
270 ); 271 );
271 272
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
84 static::assertInstanceOf(BookmarkRawFormatter::class, $formatter); 84 static::assertInstanceOf(BookmarkRawFormatter::class, $formatter);
85 static::assertSame($parameters['selection'], $selection); 85 static::assertSame($parameters['selection'], $selection);
86 static::assertTrue($prependNoteUrl); 86 static::assertTrue($prependNoteUrl);
87 static::assertSame('http://shaarli', $indexUrl); 87 static::assertSame('http://shaarli/subfolder/', $indexUrl);
88 88
89 return $bookmarks; 89 return $bookmarks;
90 } 90 }
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;
8use Slim\Http\Request; 8use Slim\Http\Request;
9use Slim\Http\Response; 9use Slim\Http\Response;
10 10
11class ToolsControllerTestControllerTest extends TestCase 11class ToolsControllerTest extends TestCase
12{ 12{
13 use FrontAdminControllerMockHelper; 13 use FrontAdminControllerMockHelper;
14 14
@@ -41,7 +41,7 @@ class ToolsControllerTestControllerTest extends TestCase
41 41
42 static::assertSame(200, $result->getStatusCode()); 42 static::assertSame(200, $result->getStatusCode());
43 static::assertSame('tools', (string) $result->getBody()); 43 static::assertSame('tools', (string) $result->getBody());
44 static::assertSame('https://shaarli', $assignedVariables['pageabsaddr']); 44 static::assertSame('https://shaarli/', $assignedVariables['pageabsaddr']);
45 static::assertTrue($assignedVariables['sslenabled']); 45 static::assertTrue($assignedVariables['sslenabled']);
46 } 46 }
47 47
@@ -63,7 +63,7 @@ class ToolsControllerTestControllerTest extends TestCase
63 63
64 static::assertSame(200, $result->getStatusCode()); 64 static::assertSame(200, $result->getStatusCode());
65 static::assertSame('tools', (string) $result->getBody()); 65 static::assertSame('tools', (string) $result->getBody());
66 static::assertSame('http://shaarli', $assignedVariables['pageabsaddr']); 66 static::assertSame('http://shaarli/', $assignedVariables['pageabsaddr']);
67 static::assertFalse($assignedVariables['sslenabled']); 67 static::assertFalse($assignedVariables['sslenabled']);
68 } 68 }
69} 69}
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
392 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); 392 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
393 static::assertSame('dailyrss', (string) $result->getBody()); 393 static::assertSame('dailyrss', (string) $result->getBody());
394 static::assertSame('Shaarli', $assignedVariables['title']); 394 static::assertSame('Shaarli', $assignedVariables['title']);
395 static::assertSame('http://shaarli', $assignedVariables['index_url']); 395 static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']);
396 static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); 396 static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']);
397 static::assertFalse($assignedVariables['hide_timestamps']); 397 static::assertFalse($assignedVariables['hide_timestamps']);
398 static::assertCount(2, $assignedVariables['days']); 398 static::assertCount(2, $assignedVariables['days']);
399 399
@@ -402,7 +402,7 @@ class DailyControllerTest extends TestCase
402 static::assertEquals($dates[0], $day['date']); 402 static::assertEquals($dates[0], $day['date']);
403 static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']); 403 static::assertSame($dates[0]->format(\DateTime::RSS), $day['date_rss']);
404 static::assertSame(format_date($dates[0], false), $day['date_human']); 404 static::assertSame(format_date($dates[0], false), $day['date_human']);
405 static::assertSame('http://shaarli/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']); 405 static::assertSame('http://shaarli/subfolder/daily?day='. $dates[0]->format('Ymd'), $day['absolute_url']);
406 static::assertCount(1, $day['links']); 406 static::assertCount(1, $day['links']);
407 static::assertSame(1, $day['links'][0]['id']); 407 static::assertSame(1, $day['links'][0]['id']);
408 static::assertSame('http://domain.tld/1', $day['links'][0]['url']); 408 static::assertSame('http://domain.tld/1', $day['links'][0]['url']);
@@ -413,7 +413,7 @@ class DailyControllerTest extends TestCase
413 static::assertEquals($dates[1], $day['date']); 413 static::assertEquals($dates[1], $day['date']);
414 static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']); 414 static::assertSame($dates[1]->format(\DateTime::RSS), $day['date_rss']);
415 static::assertSame(format_date($dates[1], false), $day['date_human']); 415 static::assertSame(format_date($dates[1], false), $day['date_human']);
416 static::assertSame('http://shaarli/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']); 416 static::assertSame('http://shaarli/subfolder/daily?day='. $dates[1]->format('Ymd'), $day['absolute_url']);
417 static::assertCount(2, $day['links']); 417 static::assertCount(2, $day['links']);
418 418
419 static::assertSame(2, $day['links'][0]['id']); 419 static::assertSame(2, $day['links'][0]['id']);
@@ -468,8 +468,8 @@ class DailyControllerTest extends TestCase
468 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]); 468 static::assertStringContainsString('application/rss', $result->getHeader('Content-Type')[0]);
469 static::assertSame('dailyrss', (string) $result->getBody()); 469 static::assertSame('dailyrss', (string) $result->getBody());
470 static::assertSame('Shaarli', $assignedVariables['title']); 470 static::assertSame('Shaarli', $assignedVariables['title']);
471 static::assertSame('http://shaarli', $assignedVariables['index_url']); 471 static::assertSame('http://shaarli/subfolder/', $assignedVariables['index_url']);
472 static::assertSame('http://shaarli/daily-rss', $assignedVariables['page_url']); 472 static::assertSame('http://shaarli/subfolder/daily-rss', $assignedVariables['page_url']);
473 static::assertFalse($assignedVariables['hide_timestamps']); 473 static::assertFalse($assignedVariables['hide_timestamps']);
474 static::assertCount(0, $assignedVariables['days']); 474 static::assertCount(0, $assignedVariables['days']);
475 } 475 }
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
79 $this->container->environment = [ 79 $this->container->environment = [
80 'SERVER_NAME' => 'shaarli', 80 'SERVER_NAME' => 'shaarli',
81 'SERVER_PORT' => '80', 81 'SERVER_PORT' => '80',
82 'REQUEST_URI' => '/daily-rss', 82 'REQUEST_URI' => '/subfolder/daily-rss',
83 'REMOTE_ADDR' => '1.2.3.4', 83 'REMOTE_ADDR' => '1.2.3.4',
84 'SCRIPT_NAME' => '/subfolder/index.php',
84 ]; 85 ];
85 86
86 $this->container->basePath = '/subfolder'; 87 $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
257 static::assertSame('/subfolder/login', $result->getHeader('location')[0]); 257 static::assertSame('/subfolder/login', $result->getHeader('location')[0]);
258 258
259 static::assertSame('UTC', $confSettings['general.timezone']); 259 static::assertSame('UTC', $confSettings['general.timezone']);
260 static::assertSame('Shared bookmarks on http://shaarli', $confSettings['general.title']); 260 static::assertSame('Shared bookmarks on http://shaarli/subfolder/', $confSettings['general.title']);
261 }
262
263 /**
264 * Same test as testSaveInstallDefaultValues() but for an instance install in root directory.
265 */
266 public function testSaveInstallDefaultValuesWithoutSubfolder(): void
267 {
268 $confSettings = [];
269
270 $this->container->environment = [
271 'SERVER_NAME' => 'shaarli',
272 'SERVER_PORT' => '80',
273 'REQUEST_URI' => '/install',
274 'REMOTE_ADDR' => '1.2.3.4',
275 'SCRIPT_NAME' => '/index.php',
276 ];
277
278 $this->container->basePath = '';
279
280 $request = $this->createMock(Request::class);
281 $response = new Response();
282
283 $this->container->conf->method('set')->willReturnCallback(function (string $key, $value) use (&$confSettings) {
284 $confSettings[$key] = $value;
285 });
286
287 $result = $this->controller->save($request, $response);
288
289 static::assertSame(302, $result->getStatusCode());
290 static::assertSame('/login', $result->getHeader('location')[0]);
291
292 static::assertSame('UTC', $confSettings['general.timezone']);
293 static::assertSame('Shared bookmarks on http://shaarli/', $confSettings['general.title']);
261 } 294 }
262} 295}
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
39 $result->getHeader('Content-Type')[0] 39 $result->getHeader('Content-Type')[0]
40 ); 40 );
41 static::assertSame('opensearch', (string) $result->getBody()); 41 static::assertSame('opensearch', (string) $result->getBody());
42 static::assertSame('http://shaarli', $assignedVariables['serverurl']); 42 static::assertSame('http://shaarli/subfolder/', $assignedVariables['serverurl']);
43 } 43 }
44} 44}