1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Fixes for tests

This commit is contained in:
David Bomba 2019-04-24 20:01:40 +10:00
parent e37c6912b1
commit d8f5d10b58
25 changed files with 124 additions and 59 deletions

View File

@ -93,10 +93,11 @@ class ClientSettings extends BaseSettings
'show_currency_symbol' => NULL,
'show_currency_code' => NULL,
'inclusive_taxes' => NULL,
'custom_taxes1' => NULL,
'custom_taxes2' => NULL,
'lock_sent_invoices' => NULL,
'invoice_email_list' => NULL,
'custom_taxes1' => NULL,
'custom_taxes2' => NULL,
'auto_bill' => NULL,
];
}
@ -116,8 +117,10 @@ class ClientSettings extends BaseSettings
foreach($client_settings as $key => $value)
{
if(!isset($client_settings->{$key}) && property_exists($company_settings, $key))
if(!isset($client_settings->{$key}) && property_exists($company_settings, $key)) {
Log::error('settings ' . $key .' to '. $company_settings->{$key});
$client_settings->{$key} = $company_settings->{$key};
}
}

View File

@ -103,14 +103,14 @@ class CompanySettings extends BaseSettings
'start_of_week' => config('ninja.i18n.start_of_week'),
'financial_year_start' => config('ninja.i18n.financial_year_start'),
'default_task_rate' => 0,
'send_reminders' => 1,
'show_tasks_in_portal' => 1,
'show_currency_symbol' => 1,
'show_currency_code' => 0,
'inclusive_taxes' => 1,
'custom_taxes1' => 0,
'custom_taxes2' => 0,
'lock_sent_invoices' => 0,
'send_reminders' => 'TRUE',
'show_tasks_in_portal' => 'TRUE',
'show_currency_symbol' => 'TRUE',
'show_currency_code' => 'FALSE',
'inclusive_taxes' => 'TRUE',
'custom_taxes1' => 'FALSE',
'custom_taxes2' => 'FALSE',
'lock_sent_invoices' => 'TRUE',
'translations' => (object) [],
];

View File

@ -19,7 +19,7 @@ class ClientFactory
$client->paid_to_date = 0;
$client->country_id = 4;
$client->is_deleted = 0;
$client->settings = ClientSettings::defaults();
$client->settings = new ClientSettings(ClientSettings::defaults());
$client_contact = ClientContactFactory::create($company_id, $user_id);
$client->contacts->add($client_contact);

View File

@ -26,7 +26,7 @@ class InvoiceFactory
$invoice->partial_due_date = null;
$invoice->is_deleted = false;
$invoice->line_items = json_encode([]);
$invoice->settings = ClientSettings::buildClientSettings(CompanySettings::defaults(), ClientSettings::defaults()); //todo need to embed the settings here
$invoice->settings = ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())); //todo need to embed the settings here
$invoice->backup = json_encode([]);
$invoice->tax_name1 = '';
$invoice->tax_rate1 = 0;

View File

@ -23,7 +23,7 @@ class InvoiceItemCalc
private $line_total;
public function __construct(\stdClass $item, \stdClass $settings)
public function __construct(\stdClass $item, $settings)
{
$this->item = $item;

View File

@ -25,7 +25,7 @@ class InvoiceRepository extends BaseRepository
$invoice->save();
$invoice_calc = new InvoiceCalc($invoice);
$invoice_calc = new InvoiceCalc($invoice, $invoice->settings);
$invoice = $invoice_calc->build()->getInvoice();

View File

@ -37,12 +37,13 @@
"require-dev": {
"barryvdh/laravel-debugbar": "^3.2",
"beyondcode/laravel-dump-server": "^1.0",
"brianium/paratest": "^3.0",
"filp/whoops": "^2.0",
"fzaninotto/faker": "^1.4",
"laravel/dusk": "^4.0",
"mockery/mockery": "^1.0",
"nunomaduro/collision": "^2.0",
"phpunit/phpunit": "^7.0"
"phpunit/phpunit": "^8.0"
},
"autoload": {
"classmap": [

View File

@ -1,6 +1,7 @@
<?php
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use Faker\Generator as Faker;
$factory->define(App\Models\Client::class, function (Faker $faker) {
@ -27,6 +28,6 @@ $factory->define(App\Models\Client::class, function (Faker $faker) {
'shipping_state' => $faker->state,
'shipping_postal_code' => $faker->postcode,
'shipping_country_id' => 4,
'settings' => new ClientSettings(ClientSettings::defaults()),
'settings' => ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults())),
];
});

View File

@ -20,9 +20,6 @@
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Modules">
<directory suffix="Test.php">./Modules</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">

View File

@ -24,9 +24,7 @@ use Tests\TestCase;
class AccountTest extends TestCase
{
//use DatabaseTransactions;
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -2,6 +2,7 @@
namespace Tests\Feature;
use App\DataMapper\DefaultSettings;
use App\Models\Account;
use App\Models\Client;
use App\Models\ClientContact;
@ -25,8 +26,9 @@ use Tests\TestCase;
class ClientTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
public function setUp()
public function setUp() :void
{
parent::setUp();
@ -184,8 +186,39 @@ class ClientTest extends TestCase
public function testDefaultTimeZoneFromClientModel()
{
$user = User::all()->first();
$company = Company::all()->first();
$account = factory(\App\Models\Account::class)->create();
$company = factory(\App\Models\Company::class)->create([
'account_id' => $account->id,
]);
$account->default_company_id = $company->id;
$account->save();
$user = factory(\App\Models\User::class)->create([
'account_id' => $account->id,
'confirmation_code' => $this->createDbHash(config('database.default'))
]);
$userPermissions = collect([
'view_invoice',
'view_client',
'edit_client',
'edit_invoice',
'create_invoice',
'create_client'
]);
$userSettings = DefaultSettings::userSettings();
$user->companies()->attach($company->id, [
'account_id' => $account->id,
'is_owner' => 1,
'is_admin' => 1,
'permissions' => $userPermissions->toJson(),
'settings' => json_encode($userSettings),
'is_locked' => 0,
]);
factory(\App\Models\Client::class, 3)->create(['user_id' => $user->id, 'company_id' => $company->id])->each(function ($c) use ($user, $company){
@ -204,8 +237,11 @@ class ClientTest extends TestCase
});
$client = Client::all()->first();
$client = Client::whereUserId($user->id)->whereCompanyId($company->id)->first();
$this->assertNotNull($client);
Log::error(print_r($client,1));
/* Make sure we have a valid settings object*/
$this->assertEquals($client->getSettings()->timezone_id, 15);

View File

@ -31,10 +31,10 @@ use Tests\TestCase;
class InvitationTest extends TestCase
{
use DatabaseTransactions;
use MakesHash;
use DatabaseTransactions;
public function setUp()
public function setUp() :void
{
parent::setUp();
@ -126,7 +126,5 @@ class InvitationTest extends TestCase
$this->assertEquals($i->invoice_id, $invoice->id);
}
}

View File

@ -2,13 +2,17 @@
namespace Tests\Feature;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use App\Models\Account;
use App\Models\Client;
use App\Models\Invoice;
use App\Utils\Traits\MakesHash;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
@ -21,8 +25,9 @@ class InvoiceTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
public function setUp()
public function setUp() :void
{
parent::setUp();
@ -153,7 +158,10 @@ class InvoiceTest extends TestCase
factory(\App\Models\Invoice::class, 1)->create(['user_id' => $user->id, 'company_id' => $company->id, 'client_id' => $client->id]);
$invoice = Invoice::where('user_id',$user->id)->first();
$invoice->settings = ClientSettings::buildClientSettings(new CompanySettings($company->settings), new ClientSettings($client->getSettings()));
$invoice->save();
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $token,
@ -172,6 +180,11 @@ class InvoiceTest extends TestCase
'status_id' => Invoice::STATUS_PAID
];
$this->assertNotNull($invoice);
$this->assertNotNull($invoice->settings);
$this->assertTrue(property_exists($invoice->settings, 'custom_taxes1'));
$response = $this->withHeaders([
'X-API-SECRET' => config('ninja.api_secret'),
'X-API-TOKEN' => $token,

View File

@ -19,12 +19,9 @@ use Tests\TestCase;
*/
class LoginTest extends TestCase
{
use DatabaseTransactions;
//use UserSessionAttributes;
//use RefreshDatabase;
public function setUp()
public function setUp() :void
{
parent::setUp();
Session::start();

View File

@ -24,8 +24,9 @@ use Tests\TestCase;
class ProductTest extends TestCase
{
use MakesHash;
use DatabaseTransactions;
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -7,6 +7,7 @@ use App\Models\Account;
use App\Models\Company;
use App\Models\User;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
@ -21,10 +22,8 @@ use Tests\TestCase;
class MultiDBUserTest extends TestCase
{
//use DatabaseMigrations;
//use InteractsWithDatabase;
public function setUp()
public function setUp() :void
{
parent::setUp();
@ -118,7 +117,7 @@ class MultiDBUserTest extends TestCase
$this->expectNotToPerformAssertions(MultiDB::setDB('db-ninja-01'));
}
public function tearDown()
public function tearDown() :void
{
DB::connection('db-ninja-01')->table('users')->delete();
DB::connection('db-ninja-02')->table('users')->delete();

View File

@ -3,10 +3,11 @@
namespace Tests\Unit;
use App\Http\ValidationRules\UniqueUserRule;
use App\Models\User;
use App\Models\Account;
use App\Models\Company;
use App\Models\User;
use Illuminate\Foundation\Testing\Concerns\InteractsWithDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;
@ -17,11 +18,10 @@ use Tests\TestCase;
*/
class UniqueEmailTest extends TestCase
{
//use InteractsWithDatabase;
protected $rule;
public function setUp()
public function setUp() :void
{
parent::setUp();
@ -86,7 +86,7 @@ class UniqueEmailTest extends TestCase
}
public function tearDown()
public function tearDown() :void
{
DB::connection('db-ninja-01')->table('users')->delete();
DB::connection('db-ninja-02')->table('users')->delete();

View File

@ -4,6 +4,7 @@ namespace Tests\Unit;
use App\DataMapper\ClientSettings;
use App\DataMapper\CompanySettings;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
/**
@ -12,8 +13,8 @@ use Tests\TestCase;
*/
class BaseSettingsTest extends TestCase
{
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -16,7 +16,7 @@ class CollectionMergingTest extends TestCase
use UserSessionAttributes;
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -12,7 +12,7 @@ use Tests\TestCase;
class CompanySettingsTest extends TestCase
{
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -11,7 +11,7 @@ use Tests\TestCase;
class CompareCollectionTest extends TestCase
{
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -10,10 +10,10 @@ use Tests\TestCase;
* @test
* @covers App\DataMapper\ClientSettings
*/
class CompanyObjectTest extends TestCase
class CompareObjectTest extends TestCase
{
public function setUp()
public function setUp() :void
{
parent::setUp();
@ -51,5 +51,17 @@ class CompanyObjectTest extends TestCase
$this->assertEquals($build_client_settings->payment_terms, 7);
}
public function testDirectClientSettingsBuild()
{
$settings = ClientSettings::buildClientSettings(new CompanySettings(CompanySettings::defaults()), new ClientSettings(ClientSettings::defaults()));
$this->assertEquals($settings->timezone_id, 15);
$this->assertEquals($settings->currency_id, 1);
$this->assertEquals($settings->language_id, 1);
$this->assertEquals($settings->payment_terms, 7);
$this->assertTrue(property_exists($settings, 'invoice_email_list'));
$this->assertEquals($settings->custom_taxes1, 'FALSE');
}
}

View File

@ -4,6 +4,7 @@ namespace Tests\Unit;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceItemCalc;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
/**
@ -12,7 +13,9 @@ use Tests\TestCase;
*/
class InvoiceItemTest extends TestCase
{
public function setUp()
public function setUp() :void
{
parent::setUp();

View File

@ -5,6 +5,7 @@ namespace Tests\Unit;
use App\Factory\InvoiceFactory;
use App\Factory\InvoiceItemFactory;
use App\Helpers\Invoice\InvoiceCalc;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Tests\TestCase;
/**
@ -14,18 +15,19 @@ use Tests\TestCase;
class InvoiceTest extends TestCase
{
protected $invoice;
public $invoice;
protected $invoice_calc;
public $invoice_calc;
private $settings;
public $settings;
public function setUp()
public function setUp() :void
{
parent::setUp();
parent::setUp();
$this->invoice = InvoiceFactory::create(1,1);//stub the company and user_id
$this->invoice->line_items = $this->buildLineItems();
$this->settings = $this->invoice->settings;
@ -37,6 +39,7 @@ class InvoiceTest extends TestCase
$this->invoice_calc = new InvoiceCalc($this->invoice, $this->settings);
}
private function buildLineItems()
@ -61,6 +64,7 @@ class InvoiceTest extends TestCase
public function testInvoiceTotals()
{
$this->invoice_calc->build();
$this->assertEquals($this->invoice_calc->getSubTotal(), 20);
@ -168,6 +172,7 @@ class InvoiceTest extends TestCase
$line_items[] = $item;
$this->invoice->line_items = $line_items;
$this->settings->inclusive_taxes = true;
$this->invoice->discount = 0;
$this->invoice->custom_value1 = 0;

View File

@ -11,7 +11,7 @@ use Tests\TestCase;
class NestedCollectionTest extends TestCase
{
public function setUp()
public function setUp() :void
{
parent::setUp();