]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Util/BaseURLTest.php
Merge pull request #8261 from MrPetovan/task/8251-use-about-for-pdesc
[friendica.git] / tests / src / Util / BaseURLTest.php
index ee88bd980461d95f90caf7d6a8b9fd0f16a27276..12fcf8858b516025461d1714f011c84c00dcd8fc 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 namespace Friendica\Test\src\Util;
 
-use Friendica\Core\Config\Configuration;
+use Friendica\App\BaseURL;
+use Friendica\Core\Config\IConfig;
 use Friendica\Test\MockedTest;
-use Friendica\Util\BaseURL;
 
 class BaseURLTest extends MockedTest
 {
@@ -173,24 +173,32 @@ class BaseURLTest extends MockedTest
         */
        public function testCheck($server, $input, $assert)
        {
-               $configMock = \Mockery::mock(Configuration::class);
+               $configMock = \Mockery::mock(IConfig::class);
                $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']);
                $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']);
                $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
                $configMock->shouldReceive('get')->with('system', 'url')->andReturn($input['url']);
 
+               // If we don't have an urlPath as an input, we assert it, we will save it to the DB for the next time
                if (!isset($input['urlPath']) && isset($assert['urlPath'])) {
                        $configMock->shouldReceive('set')->with('system', 'urlpath', $assert['urlPath'])->once();
                }
 
+               // If we don't have the ssl_policy as an input, we assert it, we will save it to the DB for the next time
                if (!isset($input['sslPolicy']) && isset($assert['sslPolicy'])) {
                        $configMock->shouldReceive('set')->with('system', 'ssl_policy', $assert['sslPolicy'])->once();
                }
 
-               if (!isset($input['hostname']) && !empty($assert['hostname'])) {
+               // If we don't have the hostname as an input, we assert it, we will save it to the DB for the next time
+               if (empty($input['hostname']) && !empty($assert['hostname'])) {
                        $configMock->shouldReceive('set')->with('config', 'hostname', $assert['hostname'])->once();
                }
 
+               // If we don't have an URL at first, but we assert it, we will save it to the DB for the next time
+               if (empty($input['url']) && !empty($assert['url'])) {
+                       $configMock->shouldReceive('set')->with('system', 'url', $assert['url'])->once();
+               }
+
                $baseUrl = new BaseURL($configMock, $server);
 
                $this->assertEquals($assert['hostname'], $baseUrl->getHostname());
@@ -287,7 +295,7 @@ class BaseURLTest extends MockedTest
         */
        public function testSave($input, $save, $url)
        {
-               $configMock = \Mockery::mock(Configuration::class);
+               $configMock = \Mockery::mock(IConfig::class);
                $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']);
                $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']);
                $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
@@ -325,7 +333,7 @@ class BaseURLTest extends MockedTest
         */
        public function testSaveByUrl($input, $save, $url)
        {
-               $configMock = \Mockery::mock(Configuration::class);
+               $configMock = \Mockery::mock(IConfig::class);
                $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn($input['hostname']);
                $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn($input['urlPath']);
                $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($input['sslPolicy']);
@@ -401,7 +409,7 @@ class BaseURLTest extends MockedTest
         */
        public function testGetURL($sslPolicy, $ssl, $url, $assert)
        {
-               $configMock = \Mockery::mock(Configuration::class);
+               $configMock = \Mockery::mock(IConfig::class);
                $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local');
                $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test');
                $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($sslPolicy);
@@ -459,7 +467,7 @@ class BaseURLTest extends MockedTest
         */
        public function testCheckRedirectHTTPS($server, $forceSSL, $sslPolicy, $url, $redirect)
        {
-               $configMock = \Mockery::mock(Configuration::class);
+               $configMock = \Mockery::mock(IConfig::class);
                $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local');
                $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test');
                $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn($sslPolicy);
@@ -495,7 +503,7 @@ class BaseURLTest extends MockedTest
         */
        public function testWrongSave($fail)
        {
-               $configMock = \Mockery::mock(Configuration::class);
+               $configMock = \Mockery::mock(IConfig::class);
                $configMock->shouldReceive('get')->with('config', 'hostname')->andReturn('friendica.local');
                $configMock->shouldReceive('get')->with('system', 'urlpath')->andReturn('new/test');
                $configMock->shouldReceive('get')->with('system', 'ssl_policy')->andReturn(BaseURL::DEFAULT_SSL_SCHEME);