2021-07-07 05:19:19 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2021-07-07 05:19:19 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-07-07 05:19:19 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
2024-09-16 13:13:55 +02:00
|
|
|
*
|
2021-07-07 05:19:19 +02:00
|
|
|
*/
|
|
|
|
class UrlTest extends TestCase
|
|
|
|
{
|
2024-08-22 08:57:52 +02:00
|
|
|
protected function setUp(): void
|
2021-07-07 05:19:19 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoScheme()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$url = 'google.com';
|
2021-07-07 05:19:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertEquals('https://google.com', $this->addScheme($url));
|
2021-07-07 05:19:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoSchemeAndTrailingSlash()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$url = 'google.com/';
|
2021-07-07 05:19:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertEquals('https://google.com', $this->addScheme($url));
|
2021-07-07 05:19:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testNoSchemeAndTrailingSlashAndHttp()
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
$url = 'http://google.com/';
|
2021-07-07 05:19:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$this->assertEquals('https://google.com', $this->addScheme($url));
|
2021-07-07 05:19:19 +02:00
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
private function addScheme($url, $scheme = 'https://')
|
|
|
|
{
|
|
|
|
$url = str_replace('http://', '', $url);
|
2021-07-07 05:19:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$url = parse_url($url, PHP_URL_SCHEME) === null ? $scheme.$url : $url;
|
2021-07-07 05:19:19 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
return rtrim($url, '/');
|
|
|
|
}
|
|
|
|
}
|