2020-04-21 07:16:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\DataMapper\CompanySettings;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\Http\Requests\Company\UpdateCompanyRequest
|
|
|
|
*/
|
|
|
|
class CompanySettingsSaveableTest extends TestCase
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
public 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
|
|
|
}
|