mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 21:07:30 -05:00 
			
		
		
		
	Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started. For more information on customizing the code style applied by Shift, [watch this short video][4]. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://github.com/squizlabs/PHP_CodeSniffer [3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 [4]: https://laravelshift.com/videos/shift-code-style
		
			
				
	
	
		
			86 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			86 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
/**
 | 
						|
 * Invoice Ninja (https://invoiceninja.com).
 | 
						|
 *
 | 
						|
 * @link https://github.com/invoiceninja/invoiceninja source repository
 | 
						|
 *
 | 
						|
 * @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
 | 
						|
 *
 | 
						|
 * @license https://www.elastic.co/licensing/elastic-license
 | 
						|
 */
 | 
						|
 | 
						|
namespace Tests\Unit;
 | 
						|
 | 
						|
use Tests\TestCase;
 | 
						|
 | 
						|
/**
 | 
						|
 * @test
 | 
						|
 * @covers  App\Utils\Traits\MakesInvoiceValues
 | 
						|
 */
 | 
						|
class MakesInvoiceValuesTest extends TestCase
 | 
						|
{
 | 
						|
    public function testStrReplaceArray()
 | 
						|
    {
 | 
						|
        $columns = ['custom_invoice_label3'];
 | 
						|
 | 
						|
        $columns = str_replace(
 | 
						|
            ['custom_invoice_label1',
 | 
						|
                'custom_invoice_label2',
 | 
						|
                'custom_invoice_label3',
 | 
						|
                'custom_invoice_label4', ],
 | 
						|
            ['custom_invoice_value1',
 | 
						|
                'custom_invoice_value2',
 | 
						|
                'custom_invoice_value3',
 | 
						|
                'custom_invoice_value4', ],
 | 
						|
            $columns
 | 
						|
        );
 | 
						|
 | 
						|
        $this->assertTrue(in_array('custom_invoice_value3', $columns));
 | 
						|
        $this->assertFalse(in_array('custom_invoice_value1', $columns));
 | 
						|
    }
 | 
						|
 | 
						|
    public function testFilteringItemTaxes()
 | 
						|
    {
 | 
						|
        $taxes = collect();
 | 
						|
 | 
						|
        $tax_name = 'GST';
 | 
						|
        $tax_rate = '10.00';
 | 
						|
 | 
						|
        $key = str_replace(' ', '', $tax_name.$tax_rate);
 | 
						|
 | 
						|
        $group_tax = collect(['key' => $key, 'total' => 20, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
 | 
						|
        $taxes->push($group_tax);
 | 
						|
        $group_tax = collect(['key' => $key, 'total' => 30, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
 | 
						|
        $taxes->push($group_tax);
 | 
						|
        $group_tax = collect(['key' => $key, 'total' => 30, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
 | 
						|
        $taxes->push($group_tax);
 | 
						|
        $group_tax = collect(['key' => $key, 'total' => 20, 'tax_name' => $tax_name.' '.$tax_rate.'%']);
 | 
						|
        $taxes->push($group_tax);
 | 
						|
        $group_tax = collect(['key' => 'VAT', 'total' => 20, 'tax_name' => 'VAT'.' '.'17.5%']);
 | 
						|
        $taxes->push($group_tax);
 | 
						|
 | 
						|
        $this->assertEquals(5, $taxes->count());
 | 
						|
 | 
						|
        $keys = $taxes->pluck('key')->unique();
 | 
						|
 | 
						|
        $this->assertEquals('GST10.00', $keys->first());
 | 
						|
 | 
						|
        $tax_array = [];
 | 
						|
 | 
						|
        foreach ($keys as $key) {
 | 
						|
            $tax_name = $taxes->filter(function ($value, $k) use ($key) {
 | 
						|
                return $value['key'] == $key;
 | 
						|
            })->pluck('tax_name')->first();
 | 
						|
 | 
						|
            $total_line_tax = $taxes->filter(function ($value, $k) use ($key) {
 | 
						|
                return $value['key'] == $key;
 | 
						|
            })->sum('total');
 | 
						|
 | 
						|
            $tax_array[] = ['name' => $tax_name, 'total' => $total_line_tax];
 | 
						|
        }
 | 
						|
 | 
						|
        //$this->assertEquals("GST10.00", print_r($tax_array));
 | 
						|
        $this->assertEquals(100, $tax_array[0]['total']);
 | 
						|
    }
 | 
						|
}
 |