1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/tests/Unit/CollectionMergingTest.php
David Bomba eddb9adc73
Client Settings (#2668)
* Clean up Client Show

* Working on Show Client menu action

* working on client view permissions

* Finishing up Client Statement View

* Workig on client settings

* add mix manifest

* css for client settings

* Client Settings

* Working on Client Settings

* Implement StartupCheck and static seeders

* Implement cached statics in view composers

* Working on client settings

* Payment Terms

* Working on Payment Terms View Composer

* Payment Terms builder

* Client Settings

* refactor companies table

* Refactor for company settings, move settings to json

* Set object cast on settings column of Company table

* Fixes for refactor of companies and clients table

* Test

* Client Settings Datamapper

* Client Settings

* Default client language

* Client Settings

* Working on client settings options

* Client Settings

* Settings Json serialization/deserialization handling
2019-02-17 21:34:46 +11:00

87 lines
1.8 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\PaymentTerm;
use App\Utils\Traits\UserSessionAttributes;
use Illuminate\Support\Facades\Session;
use Tests\TestCase;
/**
* @test
* @covers App\Http\ViewComposers\TranslationComposer
*/
class CollectionMergingTest extends TestCase
{
use UserSessionAttributes;
public function setUp()
{
parent::setUp();
Session::start();
$this->setCurrentCompanyId(1);
$this->terms = PaymentTerm::scope()->get();
}
public function testBlankCollectionReturned()
{
$this->assertEquals($this->terms->count(), 0);
}
public function testMergingCollection()
{
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
$new_terms = $this->terms->map(function($term) {
return $term['num_days'];
});
$payment_terms->merge($new_terms);
$this->assertEquals($payment_terms->count(), 8);
}
public function testSortingCollection()
{
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
$new_terms = $this->terms->map(function($term) {
return $term['num_days'];
});
$payment_terms->merge($new_terms)
->sortBy('num_days')
->values()
->all();
$term = $payment_terms->first();
$this->assertEquals($term['num_days'], 0);
}
public function testSortingCollectionLast()
{
$payment_terms = collect(unserialize(CACHED_PAYMENT_TERMS));
$new_terms = $this->terms->map(function($term) {
return $term['num_days'];
});
$payment_terms->merge($new_terms)
->sortBy('num_days')
->values()
->all();
$term = $payment_terms->last();
$this->assertEquals($term['num_days'], 90);
}
}