2019-09-11 07:32:47 +02:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-09-14 13:11:46 +02:00
|
|
|
*
|
2022-06-21 11:57:17 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-09-14 13:11:46 +02:00
|
|
|
*/
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2019-09-11 07:32:47 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
2019-11-24 07:37:53 +01:00
|
|
|
use App\Utils\Traits\ClientGroupSettingsSaver;
|
2019-09-11 07:32:47 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\MockAccountData;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
2019-09-12 06:45:13 +02:00
|
|
|
* @coversDefaultClass App\Models\Client
|
2019-09-11 07:32:47 +02:00
|
|
|
*/
|
|
|
|
class GroupSettingsTest extends TestCase
|
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
use MockAccountData;
|
2019-09-11 07:32:47 +02:00
|
|
|
use DatabaseTransactions;
|
2019-11-24 07:37:53 +01:00
|
|
|
use ClientGroupSettingsSaver;
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2019-09-11 07:32:47 +02:00
|
|
|
{
|
2020-03-21 06:37:30 +01:00
|
|
|
parent::setUp();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->makeTestData();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->company_settings = CompanySettings::defaults();
|
|
|
|
$this->client_settings = ClientSettings::buildClientSettings($this->company_settings, ClientSettings::defaults());
|
|
|
|
}
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testCompanyDefaults()
|
|
|
|
{
|
|
|
|
$this->company_settings->timezone_id = 'fluffy';
|
|
|
|
$this->company->settings = $this->company_settings;
|
|
|
|
$this->company->save();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client_settings->timezone_id = '1';
|
|
|
|
$this->client->settings = $this->client_settings;
|
|
|
|
$this->client->save();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->client->settings->timezone_id, '1');
|
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), '1');
|
|
|
|
$this->assertEquals($this->client->getMergedSettings()->timezone_id, '1');
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->company->settings->timezone_id, 'fluffy');
|
|
|
|
}
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testGroupDefaults()
|
|
|
|
{
|
|
|
|
$cs = $this->company->settings;
|
|
|
|
$cs->timezone_id = '';
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->company->settings = $cs;
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$gs = $this->client->group_settings->settings;
|
|
|
|
$gs->timezone_id = 'SPOCK';
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->settings = $gs;
|
|
|
|
$this->client->save();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$cls = $this->client->settings;
|
|
|
|
$cls->timezone_id = '';
|
|
|
|
$cls->date_format = 'sharleen';
|
|
|
|
$this->client->settings = $cls;
|
|
|
|
$this->client->save();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->company->save();
|
|
|
|
$this->client->save();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->client->group_settings->settings->timezone_id, 'SPOCK');
|
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), 'SPOCK');
|
|
|
|
$this->assertEquals($this->client->getMergedSettings()->timezone_id, 'SPOCK');
|
|
|
|
}
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testClientDefaults()
|
|
|
|
{
|
|
|
|
$cs = $this->client->company->settings;
|
|
|
|
$cs->timezone_id = null;
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->company->settings = $cs;
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$gs = $this->client->group_settings->settings;
|
|
|
|
$gs->timezone_id = null;
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->settings = $gs;
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$cls = $this->client->settings;
|
|
|
|
$cls->timezone_id = 'SCOTTY';
|
|
|
|
$cls->date_format = 'sharleen';
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->settings = $cls;
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->save();
|
|
|
|
$this->client->company->save();
|
|
|
|
$this->client->save();
|
2019-09-11 08:00:23 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->fresh();
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->client->settings->timezone_id, 'SCOTTY');
|
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), 'SCOTTY');
|
|
|
|
$this->assertEquals($this->client->getMergedSettings()->timezone_id, 'SCOTTY');
|
|
|
|
}
|
2019-09-11 07:32:47 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testClientPriority()
|
|
|
|
{
|
|
|
|
$cs = $this->client->company->settings;
|
|
|
|
$cs->timezone_id = 'COMPANY';
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->company->settings = $cs;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$gs = $this->client->group_settings->settings;
|
|
|
|
$gs->timezone_id = 'GROUP';
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->settings = $gs;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$cls = $this->client->settings;
|
|
|
|
$cls->timezone_id = 'CLIENT';
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->settings = $cls;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->save();
|
|
|
|
$this->client->company->save();
|
|
|
|
$this->client->save();
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->fresh();
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), 'CLIENT');
|
|
|
|
$this->assertEquals($this->client->getMergedSettings()->timezone_id, 'CLIENT');
|
|
|
|
}
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2019-09-12 06:45:13 +02:00
|
|
|
/**
|
|
|
|
* @covers ::getMergedSettings
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testGroupPriority()
|
|
|
|
{
|
|
|
|
$cs = $this->client->company->settings;
|
|
|
|
$cs->timezone_id = 'COMPANY';
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->company->settings = $cs;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$gs = $this->client->group_settings->settings;
|
|
|
|
$gs->timezone_id = 'GROUP';
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->settings = $gs;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$cls = $this->client->settings;
|
|
|
|
$cls->timezone_id = null;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->settings = $cls;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->save();
|
|
|
|
$this->client->company->save();
|
|
|
|
$this->client->save();
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->fresh();
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), 'GROUP');
|
|
|
|
$this->assertEquals($this->client->getMergedSettings()->timezone_id, 'GROUP');
|
|
|
|
}
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2019-09-12 06:45:13 +02:00
|
|
|
/**
|
|
|
|
* @covers ::getSetting
|
|
|
|
*/
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testCompanyFallBackPriority()
|
|
|
|
{
|
|
|
|
$cs = $this->client->company->settings;
|
|
|
|
$cs->timezone_id = 'COMPANY';
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->company->settings = $cs;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$gs = $this->client->group_settings->settings;
|
|
|
|
$gs->timezone_id = null;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->settings = $gs;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$cls = $this->client->settings;
|
|
|
|
$cls->timezone_id = null;
|
2019-09-12 04:32:46 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->settings = $cls;
|
2019-11-24 07:37:53 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->group_settings->save();
|
|
|
|
$this->client->company->save();
|
|
|
|
$this->client->save();
|
2019-11-24 07:37:53 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->client->fresh();
|
2019-11-24 07:37:53 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertEquals($this->client->getSetting('timezone_id'), 'COMPANY');
|
|
|
|
$this->assertEquals($this->client->getMergedSettings()->timezone_id, 'COMPANY');
|
|
|
|
}
|
2019-11-24 07:37:53 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testDiscardingUnsetProperties()
|
|
|
|
{
|
|
|
|
$this->settings = $this->company->settings;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertTrue($this->validateSettings($this->settings));
|
2019-11-24 07:37:53 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$new_settings = $this->saveSettings($this->settings, $this->client);
|
|
|
|
}
|
|
|
|
}
|