mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-01 06:34:35 -04:00
Tests
This commit is contained in:
parent
47cdeef258
commit
28a214a9bc
@ -14,7 +14,7 @@ namespace App\DataMapper;
|
|||||||
class InvoiceItem
|
class InvoiceItem
|
||||||
{
|
{
|
||||||
|
|
||||||
private $qty;
|
private $quantity;
|
||||||
|
|
||||||
private $cost;
|
private $cost;
|
||||||
|
|
||||||
@ -38,5 +38,15 @@ class InvoiceItem
|
|||||||
|
|
||||||
private $line_total;
|
private $line_total;
|
||||||
|
|
||||||
|
private $date;
|
||||||
|
|
||||||
|
private $custom_value1;
|
||||||
|
|
||||||
|
private $custom_value2;
|
||||||
|
|
||||||
|
private $custom_value3;
|
||||||
|
|
||||||
|
private $custom_value4;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -226,6 +226,8 @@ trait MakesInvoiceValues
|
|||||||
*/
|
*/
|
||||||
public function table(array $columns) :string
|
public function table(array $columns) :string
|
||||||
{
|
{
|
||||||
|
//need to transform taxes and custom labels between the header column and value columns
|
||||||
|
|
||||||
$data = '<table class="table table-hover table-striped">';
|
$data = '<table class="table table-hover table-striped">';
|
||||||
|
|
||||||
$data .= '<thead><tr class="heading">';
|
$data .= '<thead><tr class="heading">';
|
||||||
@ -233,17 +235,30 @@ trait MakesInvoiceValues
|
|||||||
foreach($columns as $column)
|
foreach($columns as $column)
|
||||||
$data .= '<td>' . ctrans('texts.column') . '</td>';
|
$data .= '<td>' . ctrans('texts.column') . '</td>';
|
||||||
|
|
||||||
$data .= '</tr></thead>';
|
$data .= '</tr></thead>';
|
||||||
|
|
||||||
|
$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);
|
||||||
|
|
||||||
foreach($this->line_items as $item)
|
foreach($this->line_items as $item)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data .= '<tr class="item">';
|
$data .= '<tr class="item">';
|
||||||
|
|
||||||
foreach($columns as $column)
|
foreach($columns as $column)
|
||||||
$data .= '<td>{$item->column}</td>';
|
$data .= '<td>'. $item->{$column} . '</td>';
|
||||||
|
|
||||||
$data .= '</tr>';
|
$data .= '</tr>';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$data .= '</table>';
|
$data .= '</table>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,14 +163,22 @@
|
|||||||
</table>
|
</table>
|
||||||
{{--
|
{{--
|
||||||
column variables:
|
column variables:
|
||||||
|
|
||||||
|
date
|
||||||
|
discount
|
||||||
|
product_key
|
||||||
item
|
item
|
||||||
description
|
notes
|
||||||
cost
|
cost
|
||||||
quantity
|
quantity
|
||||||
taxes
|
taxes (tax_name1, tax_name2, tax_rate1, tax_rate2)
|
||||||
subtotal
|
line_total
|
||||||
|
custom_label1 ( will show as the following parameter as its value -> custom_invoice_value1 )
|
||||||
|
custom_label2 ( will show as the following parameter as its value -> custom_invoice_value2 )
|
||||||
|
custom_label3 ( will show as the following parameter as its value -> custom_invoice_value3 )
|
||||||
|
custom_label4 ( will show as the following parameter as its value -> custom_invoice_value4 )
|
||||||
--}}
|
--}}
|
||||||
{{ $invoice->table(['item','description','cost','quantity', 'taxes', 'subtotal']) }}
|
{{ $invoice->table(['item','description','cost','quantity', 'tax_name1', 'line_total']) }}
|
||||||
|
|
||||||
<table cellpadding="0" cellspacing="0">
|
<table cellpadding="0" cellspacing="0">
|
||||||
|
|
||||||
|
36
tests/Unit/MakesInvoiceValuesTest.php
Normal file
36
tests/Unit/MakesInvoiceValuesTest.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user