2020-04-21 07:16:45 +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
|
|
|
|
2020-04-21 07:16:45 +02:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\DataMapper\CompanySettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Http\Requests\Company\UpdateCompanyRequest
|
|
|
|
*/
|
|
|
|
class CompanySettingsSaveableTest extends TestCase
|
|
|
|
{
|
2022-06-21 12:00:57 +02:00
|
|
|
protected function setUp() :void
|
2020-04-21 07:16:45 +02:00
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSettingsSaverWithFreePlan()
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$filtered = $this->filterSaver(CompanySettings::defaults());
|
2020-04-21 07:16:45 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertTrue(property_exists($filtered, 'timezone_id'));
|
2020-04-21 07:16:45 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertTrue(property_exists(CompanySettings::defaults(), 'timezone_id'));
|
2020-04-21 07:16:45 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertTrue(property_exists(CompanySettings::defaults(), 'auto_archive_invoice'));
|
2020-04-21 07:16:45 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$this->assertFalse(property_exists($filtered, 'auto_archive_invoice'));
|
2020-04-21 07:16:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function filterSaver($settings)
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$saveable_cast = CompanySettings::$free_plan_casts;
|
2020-04-21 07:16:45 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
foreach ($settings as $key => $value) {
|
|
|
|
if (! array_key_exists($key, $saveable_cast)) {
|
2020-04-21 07:16:45 +02:00
|
|
|
unset($settings->{$key});
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|
2020-04-21 07:16:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $settings;
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|