Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Documents/ReceiptTest.php
Show First 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | public function testHtmlOutput(): void | ||||
$header = $dom->getElementById('header'); | $header = $dom->getElementById('header'); | ||||
$companyOutput = $this->getNodeContent($header->getElementsByTagName('td')[0]); | $companyOutput = $this->getNodeContent($header->getElementsByTagName('td')[0]); | ||||
$companyExpected = \config('app.company.name') . "\n" . \config('app.company.address'); | $companyExpected = \config('app.company.name') . "\n" . \config('app.company.address'); | ||||
$this->assertSame($companyExpected, $companyOutput); | $this->assertSame($companyExpected, $companyOutput); | ||||
// The main table content | // The main table content | ||||
$content = $dom->getElementById('content'); | $content = $dom->getElementById('content'); | ||||
$records = $content->getElementsByTagName('tr'); | $records = $content->getElementsByTagName('tr'); | ||||
$this->assertCount(5, $records); | $this->assertCount(7, $records); | ||||
$headerCells = $records[0]->getElementsByTagName('th'); | $headerCells = $records[0]->getElementsByTagName('th'); | ||||
$this->assertCount(3, $headerCells); | $this->assertCount(3, $headerCells); | ||||
$this->assertSame('Date', $this->getNodeContent($headerCells[0])); | $this->assertSame('Date', $this->getNodeContent($headerCells[0])); | ||||
$this->assertSame('Description', $this->getNodeContent($headerCells[1])); | $this->assertSame('Description', $this->getNodeContent($headerCells[1])); | ||||
$this->assertSame('Amount', $this->getNodeContent($headerCells[2])); | $this->assertSame('Amount', $this->getNodeContent($headerCells[2])); | ||||
$cells = $records[1]->getElementsByTagName('td'); | $cells = $records[1]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | $this->assertCount(3, $cells); | ||||
$this->assertSame('2020-05-01', $this->getNodeContent($cells[0])); | $this->assertSame('2020-05-01', $this->getNodeContent($cells[0])); | ||||
$this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | $this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | ||||
$this->assertSame('12,34 CHF', $this->getNodeContent($cells[2])); | $this->assertSame('12,34 CHF', $this->getNodeContent($cells[2])); | ||||
$cells = $records[2]->getElementsByTagName('td'); | $cells = $records[2]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | $this->assertCount(3, $cells); | ||||
$this->assertSame('2020-05-10', $this->getNodeContent($cells[0])); | $this->assertSame('2020-05-10', $this->getNodeContent($cells[0])); | ||||
$this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | $this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | ||||
$this->assertSame('0,01 CHF', $this->getNodeContent($cells[2])); | $this->assertSame('0,01 CHF', $this->getNodeContent($cells[2])); | ||||
$cells = $records[3]->getElementsByTagName('td'); | $cells = $records[3]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | $this->assertCount(3, $cells); | ||||
$this->assertSame('2020-05-31', $this->getNodeContent($cells[0])); | $this->assertSame('2020-05-21', $this->getNodeContent($cells[0])); | ||||
$this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | $this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | ||||
$this->assertSame('1,00 CHF', $this->getNodeContent($cells[2])); | $this->assertSame('1,00 CHF', $this->getNodeContent($cells[2])); | ||||
$summaryCells = $records[4]->getElementsByTagName('td'); | $cells = $records[4]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | |||||
$this->assertSame('2020-05-30', $this->getNodeContent($cells[0])); | |||||
$this->assertSame("Refund", $this->getNodeContent($cells[1])); | |||||
$this->assertSame('-1,00 CHF', $this->getNodeContent($cells[2])); | |||||
$cells = $records[5]->getElementsByTagName('td'); | |||||
$this->assertCount(3, $cells); | |||||
$this->assertSame('2020-05-31', $this->getNodeContent($cells[0])); | |||||
$this->assertSame("Chargeback", $this->getNodeContent($cells[1])); | |||||
$this->assertSame('-0,10 CHF', $this->getNodeContent($cells[2])); | |||||
$summaryCells = $records[6]->getElementsByTagName('td'); | |||||
$this->assertCount(2, $summaryCells); | $this->assertCount(2, $summaryCells); | ||||
$this->assertSame('Total', $this->getNodeContent($summaryCells[0])); | $this->assertSame('Total', $this->getNodeContent($summaryCells[0])); | ||||
$this->assertSame('13,35 CHF', $this->getNodeContent($summaryCells[1])); | $this->assertSame('12,25 CHF', $this->getNodeContent($summaryCells[1])); | ||||
// Customer data | // Customer data | ||||
$customer = $dom->getElementById('customer'); | $customer = $dom->getElementById('customer'); | ||||
$customerCells = $customer->getElementsByTagName('td'); | $customerCells = $customer->getElementsByTagName('td'); | ||||
$customerOutput = $this->getNodeContent($customerCells[0]); | $customerOutput = $this->getNodeContent($customerCells[0]); | ||||
$customerExpected = "Firstname Lastname\nTest Unicode Straße 150\n10115 Berlin"; | $customerExpected = "Firstname Lastname\nTest Unicode Straße 150\n10115 Berlin"; | ||||
$this->assertSame($customerExpected, $this->getNodeContent($customerCells[0])); | $this->assertSame($customerExpected, $this->getNodeContent($customerCells[0])); | ||||
$customerIdents = $this->getNodeContent($customerCells[1]); | $customerIdents = $this->getNodeContent($customerCells[1]); | ||||
Show All 23 Lines | public function testHtmlOutputVat(): void | ||||
$this->assertStringStartsWith('<!DOCTYPE html>', $html); | $this->assertStringStartsWith('<!DOCTYPE html>', $html); | ||||
$dom = new \DOMDocument('1.0', 'UTF-8'); | $dom = new \DOMDocument('1.0', 'UTF-8'); | ||||
$dom->loadHTML($html); | $dom->loadHTML($html); | ||||
// The main table content | // The main table content | ||||
$content = $dom->getElementById('content'); | $content = $dom->getElementById('content'); | ||||
$records = $content->getElementsByTagName('tr'); | $records = $content->getElementsByTagName('tr'); | ||||
$this->assertCount(7, $records); | $this->assertCount(9, $records); | ||||
$cells = $records[1]->getElementsByTagName('td'); | $cells = $records[1]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | $this->assertCount(3, $cells); | ||||
$this->assertSame('2020-05-01', $this->getNodeContent($cells[0])); | $this->assertSame('2020-05-01', $this->getNodeContent($cells[0])); | ||||
$this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | $this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | ||||
$this->assertSame('11,39 CHF', $this->getNodeContent($cells[2])); | $this->assertSame('11,39 CHF', $this->getNodeContent($cells[2])); | ||||
$cells = $records[2]->getElementsByTagName('td'); | $cells = $records[2]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | $this->assertCount(3, $cells); | ||||
$this->assertSame('2020-05-10', $this->getNodeContent($cells[0])); | $this->assertSame('2020-05-10', $this->getNodeContent($cells[0])); | ||||
$this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | $this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | ||||
$this->assertSame('0,01 CHF', $this->getNodeContent($cells[2])); | $this->assertSame('0,01 CHF', $this->getNodeContent($cells[2])); | ||||
$cells = $records[3]->getElementsByTagName('td'); | $cells = $records[3]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | $this->assertCount(3, $cells); | ||||
$this->assertSame('2020-05-31', $this->getNodeContent($cells[0])); | $this->assertSame('2020-05-21', $this->getNodeContent($cells[0])); | ||||
$this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | $this->assertSame("$appName Services", $this->getNodeContent($cells[1])); | ||||
$this->assertSame('0,92 CHF', $this->getNodeContent($cells[2])); | $this->assertSame('0,92 CHF', $this->getNodeContent($cells[2])); | ||||
$subtotalCells = $records[4]->getElementsByTagName('td'); | $cells = $records[4]->getElementsByTagName('td'); | ||||
$this->assertCount(3, $cells); | |||||
$this->assertSame('2020-05-30', $this->getNodeContent($cells[0])); | |||||
$this->assertSame("Refund", $this->getNodeContent($cells[1])); | |||||
$this->assertSame('-0,92 CHF', $this->getNodeContent($cells[2])); | |||||
$cells = $records[5]->getElementsByTagName('td'); | |||||
$this->assertCount(3, $cells); | |||||
$this->assertSame('2020-05-31', $this->getNodeContent($cells[0])); | |||||
$this->assertSame("Chargeback", $this->getNodeContent($cells[1])); | |||||
$this->assertSame('-0,09 CHF', $this->getNodeContent($cells[2])); | |||||
$subtotalCells = $records[6]->getElementsByTagName('td'); | |||||
$this->assertCount(2, $subtotalCells); | $this->assertCount(2, $subtotalCells); | ||||
$this->assertSame('Subtotal', $this->getNodeContent($subtotalCells[0])); | $this->assertSame('Subtotal', $this->getNodeContent($subtotalCells[0])); | ||||
$this->assertSame('12,32 CHF', $this->getNodeContent($subtotalCells[1])); | $this->assertSame('11,31 CHF', $this->getNodeContent($subtotalCells[1])); | ||||
$vatCells = $records[5]->getElementsByTagName('td'); | $vatCells = $records[7]->getElementsByTagName('td'); | ||||
$this->assertCount(2, $vatCells); | $this->assertCount(2, $vatCells); | ||||
$this->assertSame('VAT (7.7%)', $this->getNodeContent($vatCells[0])); | $this->assertSame('VAT (7.7%)', $this->getNodeContent($vatCells[0])); | ||||
$this->assertSame('1,03 CHF', $this->getNodeContent($vatCells[1])); | $this->assertSame('0,94 CHF', $this->getNodeContent($vatCells[1])); | ||||
$totalCells = $records[6]->getElementsByTagName('td'); | $totalCells = $records[8]->getElementsByTagName('td'); | ||||
$this->assertCount(2, $totalCells); | $this->assertCount(2, $totalCells); | ||||
$this->assertSame('Total', $this->getNodeContent($totalCells[0])); | $this->assertSame('Total', $this->getNodeContent($totalCells[0])); | ||||
$this->assertSame('13,35 CHF', $this->getNodeContent($totalCells[1])); | $this->assertSame('12,25 CHF', $this->getNodeContent($totalCells[1])); | ||||
} | } | ||||
/** | /** | ||||
* Test receipt PDF output | * Test receipt PDF output | ||||
*/ | */ | ||||
public function testPdfOutput(): void | public function testPdfOutput(): void | ||||
{ | { | ||||
$wallet = $this->getTestData(); | $wallet = $this->getTestData(); | ||||
Show All 24 Lines | protected function getTestData(string $country = null): Wallet | ||||
'billing_address' => "Test Unicode Straße 150\n10115 Berlin", | 'billing_address' => "Test Unicode Straße 150\n10115 Berlin", | ||||
'country' => $country | 'country' => $country | ||||
]); | ]); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
// Create two payments out of the 2020-05 period | // Create two payments out of the 2020-05 period | ||||
// and three in it, plus one in the period but unpaid, | // and three in it, plus one in the period but unpaid, | ||||
// and one with amount 0 | // and one with amount 0, and an extra refund and chanrgeback | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA1', | 'id' => 'AAA1', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => PaymentProvider::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => PaymentProvider::TYPE_ONEOFF, | ||||
'description' => 'Paid in April', | 'description' => 'Paid in April', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
Show All 33 Lines | protected function getTestData(string $country = null): Wallet | ||||
'description' => 'Payment not yet paid', | 'description' => 'Payment not yet paid', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 999, | 'amount' => 999, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | $payment->updated_at = Carbon::create(2020, 5, 1, 0, 0, 0); | ||||
$payment->save(); | $payment->save(); | ||||
// ... so we expect the last three on the receipt | // ... so we expect the five three on the receipt | ||||
$payment = Payment::create([ | $payment = Payment::create([ | ||||
'id' => 'AAA5', | 'id' => 'AAA5', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => PaymentProvider::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_ONEOFF, | 'type' => PaymentProvider::TYPE_ONEOFF, | ||||
'description' => 'Payment OK', | 'description' => 'Payment OK', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 1234, | 'amount' => 1234, | ||||
Show All 17 Lines | protected function getTestData(string $country = null): Wallet | ||||
'id' => 'AAA7', | 'id' => 'AAA7', | ||||
'status' => PaymentProvider::STATUS_PAID, | 'status' => PaymentProvider::STATUS_PAID, | ||||
'type' => PaymentProvider::TYPE_RECURRING, | 'type' => PaymentProvider::TYPE_RECURRING, | ||||
'description' => 'Payment OK', | 'description' => 'Payment OK', | ||||
'wallet_id' => $wallet->id, | 'wallet_id' => $wallet->id, | ||||
'provider' => 'stripe', | 'provider' => 'stripe', | ||||
'amount' => 100, | 'amount' => 100, | ||||
]); | ]); | ||||
$payment->updated_at = Carbon::create(2020, 5, 21, 23, 59, 0); | |||||
$payment->save(); | |||||
$payment = Payment::create([ | |||||
'id' => 'ref1', | |||||
'status' => PaymentProvider::STATUS_PAID, | |||||
'type' => PaymentProvider::TYPE_REFUND, | |||||
'description' => 'refund desc', | |||||
'wallet_id' => $wallet->id, | |||||
'provider' => 'stripe', | |||||
'amount' => -100, | |||||
]); | |||||
$payment->updated_at = Carbon::create(2020, 5, 30, 23, 59, 0); | |||||
$payment->save(); | |||||
$payment = Payment::create([ | |||||
'id' => 'chback1', | |||||
'status' => PaymentProvider::STATUS_PAID, | |||||
'type' => PaymentProvider::TYPE_CHARGEBACK, | |||||
'description' => '', | |||||
'wallet_id' => $wallet->id, | |||||
'provider' => 'stripe', | |||||
'amount' => -10, | |||||
]); | |||||
$payment->updated_at = Carbon::create(2020, 5, 31, 23, 59, 0); | $payment->updated_at = Carbon::create(2020, 5, 31, 23, 59, 0); | ||||
$payment->save(); | $payment->save(); | ||||
// Make sure some config is set so we can test it's put into the receipt | // Make sure some config is set so we can test it's put into the receipt | ||||
if (empty(\config('app.company.name'))) { | if (empty(\config('app.company.name'))) { | ||||
\config(['app.company.name' => 'Company Co.']); | \config(['app.company.name' => 'Company Co.']); | ||||
} | } | ||||
if (empty(\config('app.company.email'))) { | if (empty(\config('app.company.email'))) { | ||||
Show All 33 Lines |