Fix subfolder configuration in unit tests

This commit is contained in:
ArthurHoaro 2020-09-03 14:52:34 +02:00
parent 650a5f09cb
commit b93cfeba7b
8 changed files with 55 additions and 20 deletions

View file

@ -132,7 +132,7 @@ public function rss(Request $request, Response $response): Response
'date' => $dayDatetime,
'date_rss' => $dayDatetime->format(DateTime::RSS),
'date_human' => format_date($dayDatetime, false, true),
'absolute_url' => $indexUrl . '/daily?day=' . $day,
'absolute_url' => $indexUrl . 'daily?day=' . $day,
'links' => [],
];

View file

@ -3,6 +3,7 @@
namespace Shaarli\Feed;
use DateTime;
use PHPUnit\Framework\TestCase;
use ReferenceLinkDB;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
@ -16,7 +17,7 @@
*
* Unit tests for FeedBuilder.
*/
class FeedBuilderTest extends \PHPUnit\Framework\TestCase
class FeedBuilderTest extends TestCase
{
/**
* @var string locale Basque (Spain).
@ -44,7 +45,7 @@ class FeedBuilderTest extends \PHPUnit\Framework\TestCase
/**
* Called before every test method.
*/
public static function setUpBeforeClass()
public static function setUpBeforeClass(): void
{
$conf = new ConfigManager('tests/utils/config/configJson');
$conf->set('resource.datastore', self::$testDatastore);
@ -60,7 +61,7 @@ public static function setUpBeforeClass()
'SERVER_NAME' => 'host.tld',
'SERVER_PORT' => '80',
'SCRIPT_NAME' => '/index.php',
'REQUEST_URI' => '/index.php?do=feed',
'REQUEST_URI' => '/feed/atom',
);
}
@ -81,7 +82,7 @@ public function testRSSBuildData()
$this->assertEquals(self::$RSS_LANGUAGE, $data['language']);
$this->assertRegExp('/Wed, 03 Aug 2016 09:30:33 \+\d{4}/', $data['last_update']);
$this->assertEquals(true, $data['show_dates']);
$this->assertEquals('http://host.tld/index.php?do=feed', $data['self_link']);
$this->assertEquals('http://host.tld/feed/atom', $data['self_link']);
$this->assertEquals('http://host.tld/', $data['index_url']);
$this->assertFalse($data['usepermalinks']);
$this->assertEquals(ReferenceLinkDB::$NB_LINKS_TOTAL, count($data['links']));
@ -253,7 +254,7 @@ public function testBuildDataServerSubdir()
'SERVER_NAME' => 'host.tld',
'SERVER_PORT' => '8080',
'SCRIPT_NAME' => '/~user/shaarli/index.php',
'REQUEST_URI' => '/~user/shaarli/index.php?do=feed',
'REQUEST_URI' => '/~user/shaarli/feed/atom',
);
$feedBuilder = new FeedBuilder(
self::$bookmarkService,
@ -265,7 +266,7 @@ public function testBuildDataServerSubdir()
$data = $feedBuilder->buildData(FeedBuilder::$FEED_ATOM, null);
$this->assertEquals(
'http://host.tld:8080/~user/shaarli/index.php?do=feed',
'http://host.tld:8080/~user/shaarli/feed/atom',
$data['self_link']
);

View file

@ -84,7 +84,7 @@ function (
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;
}

View file

@ -8,7 +8,7 @@
use Slim\Http\Request;
use Slim\Http\Response;
class ToolsControllerTestControllerTest extends TestCase
class ToolsControllerTest extends TestCase
{
use FrontAdminControllerMockHelper;
@ -41,7 +41,7 @@ public function testDefaultInvokeWithHttps(): void
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 @@ public function testDefaultInvokeWithoutHttps(): void
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']);
}
}

View file

@ -392,8 +392,8 @@ public function testValidRssControllerInvokeDefault(): void
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 @@ public function testValidRssControllerInvokeDefault(): void
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 @@ public function testValidRssControllerInvokeDefault(): void
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 @@ public function testValidRssControllerInvokeNoBookmark(): void
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']);
}

View file

@ -79,8 +79,9 @@ protected function createContainer(): void
$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';

View file

@ -257,6 +257,39 @@ public function testSaveInstallDefaultValues(): void
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']);
}
}

View file

@ -39,6 +39,6 @@ public function testOpenSearchController(): void
$result->getHeader('Content-Type')[0]
);
static::assertSame('opensearch', (string) $result->getBody());
static::assertSame('http://shaarli', $assignedVariables['serverurl']);
static::assertSame('http://shaarli/subfolder/', $assignedVariables['serverurl']);
}
}