2019-07-03 00:42:47 +02:00
|
|
|
<?php
|
2020-02-09 15:45:36 +01:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (C) 2020, Friendica
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
2019-07-03 00:42:47 +02:00
|
|
|
|
|
|
|
namespace Friendica\Test\src\Core\Config;
|
|
|
|
|
2020-01-19 21:29:36 +01:00
|
|
|
use Friendica\Core\Config\PreloadConfig;
|
2019-07-03 00:42:47 +02:00
|
|
|
|
2020-01-19 22:38:33 +01:00
|
|
|
class PreloadConfigTest extends ConfigTest
|
2019-07-03 00:42:47 +02:00
|
|
|
{
|
|
|
|
public function getInstance()
|
|
|
|
{
|
2020-01-19 21:29:36 +01:00
|
|
|
return new PreloadConfig($this->configCache, $this->configModel);
|
2019-07-03 00:42:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataConfigLoad
|
|
|
|
*/
|
|
|
|
public function testSetUp(array $data)
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('load')
|
|
|
|
->andReturn($data)
|
|
|
|
->once();
|
|
|
|
|
|
|
|
parent::testSetUp($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataConfigLoad
|
|
|
|
*/
|
|
|
|
public function testLoad(array $data, array $possibleCats, array $load)
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(true)
|
|
|
|
->once();
|
|
|
|
|
|
|
|
$this->configModel->shouldReceive('load')
|
|
|
|
->andReturn($data)
|
|
|
|
->once();
|
|
|
|
|
|
|
|
parent::testLoad($data, $possibleCats, $load);
|
|
|
|
|
|
|
|
// Assert that every category is loaded everytime
|
|
|
|
foreach ($data as $cat => $values) {
|
|
|
|
$this->assertConfig($cat, $values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataDoubleLoad
|
|
|
|
*/
|
|
|
|
public function testCacheLoadDouble(array $data1, array $data2, array $expect)
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(true)
|
|
|
|
->once();
|
|
|
|
|
|
|
|
$this->configModel->shouldReceive('load')
|
|
|
|
->andReturn($data1)
|
|
|
|
->once();
|
|
|
|
|
|
|
|
parent::testCacheLoadDouble($data1, $data2, $expect);
|
|
|
|
|
|
|
|
// Assert that every category is loaded everytime and is NOT overwritten
|
|
|
|
foreach ($data1 as $cat => $values) {
|
|
|
|
$this->assertConfig($cat, $values);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataTests
|
|
|
|
*/
|
|
|
|
public function testSetGetWithDB($data)
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(true)
|
|
|
|
->times(2);
|
|
|
|
|
|
|
|
$this->configModel->shouldReceive('load')->andReturn(['config' => []])->once();
|
|
|
|
|
|
|
|
parent::testSetGetWithDB($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataTests
|
|
|
|
*/
|
|
|
|
public function testGetWithRefresh($data)
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(true)
|
|
|
|
->times(2);
|
|
|
|
|
|
|
|
// constructor loading
|
|
|
|
$this->configModel->shouldReceive('load')
|
|
|
|
->andReturn(['config' => []])
|
|
|
|
->once();
|
|
|
|
|
|
|
|
// mocking one get
|
|
|
|
$this->configModel->shouldReceive('get')
|
|
|
|
->with('test', 'it')
|
|
|
|
->andReturn($data)
|
|
|
|
->once();
|
|
|
|
|
|
|
|
parent::testGetWithRefresh($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function testGetWrongWithoutDB()
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(false)
|
|
|
|
->times(2);
|
|
|
|
|
|
|
|
parent::testGetWrongWithoutDB();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @dataProvider dataTests
|
|
|
|
*/
|
|
|
|
public function testDeleteWithoutDB($data)
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(false)
|
|
|
|
->times(2);
|
|
|
|
|
|
|
|
parent::testDeleteWithoutDB($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeleteWithDB()
|
|
|
|
{
|
|
|
|
$this->configModel->shouldReceive('isConnected')
|
|
|
|
->andReturn(true)
|
|
|
|
->times(5);
|
|
|
|
|
|
|
|
// constructor loading
|
|
|
|
$this->configModel->shouldReceive('load')
|
|
|
|
->andReturn(['config' => []])
|
|
|
|
->once();
|
|
|
|
|
|
|
|
parent::testDeleteWithDB();
|
|
|
|
}
|
|
|
|
}
|