2019-02-17 11:34:46 +01:00
|
|
|
<?php
|
2020-09-14 13:11:46 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-02-17 11:34:46 +01:00
|
|
|
namespace Tests\Unit;
|
|
|
|
|
|
|
|
use App\DataMapper\ClientSettings;
|
|
|
|
use App\DataMapper\CompanySettings;
|
2019-04-24 12:01:40 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
2019-02-17 11:34:46 +01:00
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @test
|
|
|
|
* @covers App\DataMapper\BaseSettings
|
|
|
|
*/
|
|
|
|
class BaseSettingsTest extends TestCase
|
|
|
|
{
|
2019-04-24 12:01:40 +02:00
|
|
|
public function setUp() :void
|
2019-02-17 11:34:46 +01: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->settings = ClientSettings::defaults();
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testPropertyNamesExist()
|
|
|
|
{
|
|
|
|
$blank_object = new \stdClass;
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$updated_object = $this->migrate($blank_object);
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertTrue(property_exists($updated_object, 'size_id'));
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function testPropertyNamesNotExist()
|
|
|
|
{
|
|
|
|
$blank_object = new \stdClass;
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$updated_object = $this->migrate($blank_object);
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
$this->assertFalse(property_exists($updated_object, 'non_existent_prop'));
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
public function migrate(\stdClass $object) : \stdClass
|
|
|
|
{
|
|
|
|
foreach ($this->settings as $property => $value) {
|
2020-09-06 11:38:10 +02:00
|
|
|
if (! property_exists($object, $property)) {
|
2020-03-21 06:37:30 +01:00
|
|
|
$object->{$property} = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
2019-02-17 11:34:46 +01:00
|
|
|
}
|