2015-09-28 22:09:13 +08:00
|
|
|
<?php
|
2016-02-26 11:09:39 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of Flarum.
|
|
|
|
*
|
|
|
|
* (c) Toby Zerner <toby.zerner@gmail.com>
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2018-03-04 07:04:43 +08:00
|
|
|
namespace Flarum\Tests\Settings;
|
2015-09-28 22:09:13 +08:00
|
|
|
|
Major refactor and improvements
- Reorganised all namespaces and class names for consistency and structure. Following PSR bylaws (Abstract prefix, Interface/Trait suffix).
- Move models into root of Core, because writing `use Flarum\Core\Discussion` is nice. Namespace the rest by type. (Namespacing by entity was too arbitrary.)
- Moved some non-domain stuff out of Core: Database, Formatter, Settings.
- Renamed config table and all references to "settings" for consistency.
- Remove Core class and add url()/isInstalled()/inDebugMode() as instance methods of Foundation\Application.
- Cleanup, docblocking, etc.
- Improvements to HTTP architecture
- API and forum/admin Actions are now actually all the same thing (simple PSR-7 Request handlers), renamed to Controllers.
- Upgrade to tobscure/json-api 0.2 branch.
- Where possible, moved generic functionality to tobscure/json-api (e.g. pagination links). I'm quite happy with the backend balance now re: #262
- Improvements to other architecture
- Use Illuminate's Auth\Access\Gate interface/implementation instead of our old Locked trait. We still use events to actually determine the permissions though. Our Policy classes are actually glorified event subscribers.
- Extract model validation into Core\Validator classes.
- Make post visibility permission stuff much more efficient and DRY.
- Renamed Flarum\Event classes for consistency. ref #246
- `Configure` prefix for events dedicated to configuring an object.
- `Get` prefix for events whose listeners should return something.
- `Prepare` prefix when a variable is passed by reference so it can be modified.
- `Scope` prefix when a query builder is passed.
- Miscellaneous improvements/bug-fixes. I'm easily distracted!
- Increase default height of post composer.
- Improve post stream redraw flickering in Safari by keying loading post placeholders with their IDs. ref #451
- Use a PHP JavaScript minification library for minifying TextFormatter's JavaScript, instead of ClosureCompilerService (can't rely on external service!)
- Use UrlGenerator properly in various places. closes #123
- Make Api\Client return Response object. closes #128
- Allow extensions to specify custom icon images.
- Allow external API/admin URLs to be optionally specified in config.php. If the value or "url" is an array, we look for the corresponding path inside. Otherwise, we append the path to the base URL, using the corresponding value in "paths" if present. closes #244
2015-10-08 11:58:02 +08:00
|
|
|
use Flarum\Settings\MemoryCacheSettingsRepository;
|
2015-10-19 12:28:47 +08:00
|
|
|
use Flarum\Settings\SettingsRepositoryInterface;
|
2018-03-04 07:01:49 +08:00
|
|
|
use Flarum\Tests\Test\TestCase;
|
2015-09-28 22:09:13 +08:00
|
|
|
use Mockery as m;
|
|
|
|
|
|
|
|
class MemoryCacheSettingsRepositoryTest extends TestCase
|
|
|
|
{
|
|
|
|
private $baseRepository;
|
|
|
|
private $repository;
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2015-10-27 20:50:11 +08:00
|
|
|
$this->baseRepository = m::mock(SettingsRepositoryInterface::class);
|
2015-09-28 22:09:13 +08:00
|
|
|
$this->repository = new MemoryCacheSettingsRepository($this->baseRepository);
|
|
|
|
}
|
2016-02-26 11:09:39 +08:00
|
|
|
|
2015-09-28 22:09:13 +08:00
|
|
|
public function test_it_should_return_all_settings_when_not_cached()
|
|
|
|
{
|
|
|
|
$this->baseRepository->shouldReceive('all')->once()->andReturn(['key' => 'value']);
|
|
|
|
|
|
|
|
$this->assertEquals(['key' => 'value'], $this->repository->all());
|
|
|
|
$this->assertEquals(['key' => 'value'], $this->repository->all()); // Assert twice to ensure we hit the cache
|
|
|
|
}
|
|
|
|
|
|
|
|
public function test_it_should_retrieve_a_specific_value()
|
|
|
|
{
|
|
|
|
$this->baseRepository->shouldReceive('all')->once()->andReturn(['key1' => 'value1', 'key2' => 'value2']);
|
|
|
|
|
|
|
|
$this->assertEquals('value2', $this->repository->get('key2'));
|
|
|
|
$this->assertEquals('value2', $this->repository->get('key2')); // Assert twice to ensure we hit the cache
|
|
|
|
}
|
2016-02-26 11:09:39 +08:00
|
|
|
|
2015-09-28 22:09:13 +08:00
|
|
|
public function test_it_should_set_a_key_value_pair()
|
|
|
|
{
|
|
|
|
$this->baseRepository->shouldReceive('set')->once();
|
|
|
|
|
|
|
|
$this->repository->set('key', 'value');
|
|
|
|
|
|
|
|
$this->assertEquals('value', $this->repository->get('key'));
|
|
|
|
}
|
|
|
|
}
|