2019-09-24 06:26:51 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
2019-11-28 08:16:50 +08:00
|
|
|
* For detailed copyright and license information, please view the
|
|
|
|
* LICENSE file that was distributed with this source code.
|
2019-09-24 06:26:51 +08:00
|
|
|
*/
|
|
|
|
|
2019-11-21 07:51:11 +08:00
|
|
|
namespace Flarum\Tests\unit\Install;
|
2019-09-24 06:26:51 +08:00
|
|
|
|
|
|
|
use Flarum\Install\BaseUrl;
|
2019-11-21 07:51:11 +08:00
|
|
|
use Flarum\Tests\unit\TestCase;
|
2020-01-07 05:29:34 +08:00
|
|
|
use Laminas\Diactoros\Uri;
|
2019-09-24 06:26:51 +08:00
|
|
|
|
|
|
|
class BaseUrlTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @dataProvider urlProvider
|
|
|
|
*/
|
|
|
|
public function test_base_url_simulating_cli_installer($uri, $expected)
|
|
|
|
{
|
|
|
|
$this->assertEquals($expected, BaseUrl::fromString($uri));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider urlProvider
|
|
|
|
*/
|
|
|
|
public function test_base_url_simulating_web_installer($uri, $expected)
|
|
|
|
{
|
2019-09-24 07:00:22 +08:00
|
|
|
$uri = new Uri($uri);
|
2019-09-24 06:26:51 +08:00
|
|
|
|
2019-09-24 07:00:22 +08:00
|
|
|
$this->assertEquals($expected, BaseUrl::fromUri($uri));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider emailProvider
|
|
|
|
*/
|
|
|
|
public function test_default_email_generation($uri, $expected)
|
|
|
|
{
|
|
|
|
$this->assertEquals(
|
|
|
|
$expected,
|
|
|
|
BaseUrl::fromString($uri)->toEmail('noreply')
|
|
|
|
);
|
2019-09-24 06:26:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function urlProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['', ''],
|
|
|
|
['flarum.org', 'http://flarum.org'],
|
|
|
|
['flarum.org/', 'http://flarum.org'],
|
|
|
|
['http://flarum.org', 'http://flarum.org'],
|
|
|
|
['http://flarum.org/', 'http://flarum.org'],
|
|
|
|
['https://flarum.org', 'https://flarum.org'],
|
|
|
|
['http://flarum.org/index.php', 'http://flarum.org'],
|
|
|
|
['http://flarum.org/index.php/', 'http://flarum.org'],
|
|
|
|
['http://flarum.org/flarum', 'http://flarum.org/flarum'],
|
|
|
|
['http://flarum.org/flarum/index.php', 'http://flarum.org/flarum'],
|
|
|
|
['http://flarum.org/flarum/index.php/', 'http://flarum.org/flarum'],
|
|
|
|
['sub.flarum.org', 'http://sub.flarum.org'],
|
|
|
|
['http://sub.flarum.org', 'http://sub.flarum.org'],
|
|
|
|
];
|
|
|
|
}
|
2019-09-24 07:00:22 +08:00
|
|
|
|
|
|
|
public function emailProvider()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
['flarum.org', 'noreply@flarum.org'],
|
|
|
|
['flarum.org/', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org/', 'noreply@flarum.org'],
|
|
|
|
['https://flarum.org', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org/index.php', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org/index.php/', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org/flarum', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org/flarum/index.php', 'noreply@flarum.org'],
|
|
|
|
['http://flarum.org/flarum/index.php/', 'noreply@flarum.org'],
|
|
|
|
['sub.flarum.org', 'noreply@sub.flarum.org'],
|
|
|
|
['http://sub.flarum.org', 'noreply@sub.flarum.org'],
|
|
|
|
];
|
|
|
|
}
|
2019-09-24 06:26:51 +08:00
|
|
|
}
|