Tests for client presenter using new settings object for company meta data

This commit is contained in:
David Bomba 2019-10-05 11:48:00 +10:00
parent 70fe64ed96
commit 305eea7fc8
5 changed files with 115 additions and 3 deletions

View File

@ -151,7 +151,6 @@ class CompanySettings extends BaseSettings
public $require_invoice_signature = false;
public $require_quote_signature = false;
/* Company Meta data that we can use to build sub companies*/
public $name;

View File

@ -230,7 +230,7 @@ class Client extends BaseModel
return $this->company->settings->{$setting};
}
throw new \Exception("Settings corrupted", 1);

View File

@ -11,6 +11,8 @@
namespace App\Models\Presenters;
use App\Models\Country;
/**
* Class ClientPresenter
* @package App\Models\Presenters
@ -94,4 +96,62 @@ class ClientPresenter extends EntityPresenter
{
return $this->entity->website ?: '';
}
/**
* Calculated company data fields
* using settings
*/
public function company_name()
{
$settings = $this->entity->getMergedSettings();
return $settings->name ?: ctrans('texts.untitled_account');
}
public function company_address()
{
$settings = $this->entity->getMergedSettings();
$str = '';
if ($settings->address1) {
$str .= e($settings->address1) . '<br/>';
}
if ($settings->address2) {
$str .= e($settings->address2) . '<br/>';
}
if ($cityState = $this->getCityState()) {
$str .= e($cityState) . '<br/>';
}
if ($country = Country::find($settings->country_id)) {
$str .= e($country->name) . '<br/>';
}
return $str;
}
public function getCityState()
{
$settings = $this->entity->getMergedSettings();
$country = false;
if($settings->country_id)
$country = Country::find($settings->country_id);
$swap = $country && $country->swap_postal_code;
$city = e($settings->city ?: '');
$state = e($settings->state ?: '');
$postalCode = e($settings->postal_code ?: '');
if ($city || $state || $postalCode) {
return $this->cityStateZip($city, $state, $postalCode, $swap);
} else {
return false;
}
}
}

View File

@ -28,7 +28,7 @@ class CompanyPresenter extends EntityPresenter
public function logo()
{
return strlen($this->entity->logo > 0) ? $this->entity->logo : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png';
return strlen($this->entity->getLogo() > 0) ? $this->entity->getLogo() : 'https://www.invoiceninja.com/wp-content/uploads/2019/01/InvoiceNinja-Logo-Round-300x300.png';
}
public function address()

View File

@ -0,0 +1,53 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\URL;
use Tests\MockAccountData;
use Tests\TestCase;
/**
* @test
* @covers App\Models\Presenters\ClientPresenter
*/
class ClientPresenterTest extends TestCase
{
use MockAccountData;
use DatabaseTransactions;
public function setUp() :void
{
parent::setUp();
$this->makeTestData();
}
public function testCompanyName()
{
$settings = $this->client->company->settings;
$settings->name = 'test';
$this->client->company->settings = $settings;
$this->client->company->save();
$this->client->getSetting('name');
$merged_settings = $this->client->getMergedSettings();
$name = $this->client->present()->company_name();
$this->assertEquals('test', $merged_settings->name);
$this->assertEquals('test', $name);
}
public function testCompanyAddress()
{
$this->assertNotNull($this->client->present()->company_address());
}
}