'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' => [],
];
namespace Shaarli\Feed;
use DateTime;
+use PHPUnit\Framework\TestCase;
use ReferenceLinkDB;
use Shaarli\Bookmark\Bookmark;
use Shaarli\Bookmark\BookmarkFileService;
*
* Unit tests for FeedBuilder.
*/
-class FeedBuilderTest extends \PHPUnit\Framework\TestCase
+class FeedBuilderTest extends TestCase
{
/**
* @var string locale Basque (Spain).
/**
* 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);
'SERVER_NAME' => 'host.tld',
'SERVER_PORT' => '80',
'SCRIPT_NAME' => '/index.php',
- 'REQUEST_URI' => '/index.php?do=feed',
+ 'REQUEST_URI' => '/feed/atom',
);
}
$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']));
'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,
$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']
);
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;
}
use Slim\Http\Request;
use Slim\Http\Response;
-class ToolsControllerTestControllerTest extends TestCase
+class ToolsControllerTest extends TestCase
{
use FrontAdminControllerMockHelper;
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']);
}
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']);
}
}
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']);
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']);
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']);
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']);
}
$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';
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']);
}
}
$result->getHeader('Content-Type')[0]
);
static::assertSame('opensearch', (string) $result->getBody());
- static::assertSame('http://shaarli', $assignedVariables['serverurl']);
+ static::assertSame('http://shaarli/subfolder/', $assignedVariables['serverurl']);
}
}