1
0
mirror of https://github.com/flarum/core.git synced 2025-07-24 02:01:19 +02:00
Files
php-flarum/php-packages/testing/tests/tests/integration/TestCaseTest.php
Alexander Skvortsov 8fd1cc4f0d TestCase Config method (#13)
Similarly to `settings`, this allows setting/overriding config prior to application boot.
2021-04-14 16:27:59 -04:00

130 lines
3.4 KiB
PHP

<?php
/*
* This file is part of Flarum.
*
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
*/
namespace Flarum\Testing\Tests\integration;
use Flarum\Extend;
use Flarum\Foundation\Config;
use Flarum\Settings\SettingsRepositoryInterface;
use Flarum\Testing\integration\TestCase;
use Flarum\User\User;
class TestCaseTest extends TestCase
{
/**
* @test
*/
public function admin_user_created_as_part_of_default_state()
{
$this->app();
$this->assertEquals(1, User::query()->count());
$user = User::find(1);
$this->assertEquals('admin', $user->username);
$this->assertEquals('admin@machine.local', $user->email);
$this->assertTrue($user->isAdmin());
}
/**
* @test
*/
public function can_add_settings_via_method()
{
$this->setting('hello', 'world');
$this->setting('display_name_driver', 'something_other_than_username');
$settings = $this->app()->getContainer()->make(SettingsRepositoryInterface::class);
$this->assertEquals('world', $settings->get('hello'));
$this->assertEquals('something_other_than_username', $settings->get('display_name_driver'));
}
/**
* @test
*/
public function settings_cleaned_up_from_previous_method()
{
$settings = $this->app()->getContainer()->make(SettingsRepositoryInterface::class);
$this->assertEquals(null, $settings->get('hello'));
$this->assertEquals(null, $settings->get('display_name_driver'));
}
/**
* @test
*/
public function can_add_config_via_method()
{
$this->config('hello', 'world');
$this->config('url', 'https://flarum.org');
$this->config('level1.level2', 'value');
$config = $this->app()->getContainer()->make(Config::class);
$this->assertEquals('world', $config['hello']);
$this->assertEquals('https://flarum.org', $config['url']);
$this->assertEquals('value', $config['level1']['level2']);
}
/**
* @test
*/
public function config_cleaned_up_from_previous_method()
{
$config = $this->app()->getContainer()->make(Config::class);
$this->assertEquals(null, $config['hello']);
$this->assertEquals('http://localhost', $config['url']);
$this->assertFalse(isset($config['level1']['level2']));
}
/**
* @test
*/
public function current_extension_not_applied_by_default()
{
$response = $this->send(
$this->request('GET', '/')
);
$this->assertStringNotContainsString('notARealSetting', $response->getBody()->getContents());
}
/**
* @test
*/
public function current_extension_applied_if_specified()
{
$this->extension('flarum-testing-tests');
$response = $this->send(
$this->request('GET', '/')
);
$this->assertStringContainsString('notARealSetting', $response->getBody()->getContents());
}
/**
* @test
*/
public function can_apply_extenders()
{
$this->extend(
(new Extend\Settings)->serializeToForum('notARealSetting', 'not.a.real.setting')
);
$response = $this->send(
$this->request('GET', '/')
);
$this->assertStringContainsString('notARealSetting', $response->getBody()->getContents());
}
}