1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/tests/acceptance/TaxRatesCest.php

151 lines
4.8 KiB
PHP
Raw Normal View History

2017-03-19 16:23:57 +01:00
<?php
use Codeception\Util\Fixtures;
use Faker\Factory;
class TaxRatesCest
{
private $faker;
public function _before(AcceptanceTester $I)
{
$I->checkIfLogin($I);
$this->faker = Factory::create();
}
2017-05-15 07:54:35 +02:00
public function lineItemTaxRates(AcceptanceTester $I)
{
2017-05-15 07:54:35 +02:00
$I->wantTo('test line item tax rates');
$clientEmail = $this->faker->safeEmail;
$productKey = $this->faker->text(10);
$itemTaxRate = $this->faker->randomFloat(2, 5, 15);
$itemTaxName = $this->faker->word();
$invoiceTaxRate = $this->faker->randomFloat(2, 5, 15);
$invoiceTaxName = $this->faker->word();
$itemCost = $this->faker->numberBetween(1, 20);
$total = $itemCost;
$total += round($itemCost * $itemTaxRate / 100, 2);
$total += round($itemCost * $invoiceTaxRate / 100, 2);
2016-10-02 11:51:10 +02:00
2016-03-15 14:25:00 +01:00
$itemTaxRate = number_format($itemTaxRate, 3);
$invoiceTaxRate = number_format($invoiceTaxRate, 3);
// create tax rates
2017-03-19 14:31:25 +01:00
$I->createTaxRate($I, $itemTaxName, $itemTaxRate);
$I->createTaxRate($I, $invoiceTaxName, $invoiceTaxRate);
// enable line item taxes
$I->amOnPage('/settings/tax_rates');
$I->checkOption('#invoice_item_taxes');
$I->click('Save');
// create product
$I->amOnPage('/products/create');
$I->fillField(['name' => 'product_key'], $productKey);
$I->fillField(['name' => 'notes'], $this->faker->text(80));
$I->fillField(['name' => 'cost'], $itemCost);
2017-05-17 12:14:32 +02:00
$I->selectOption('select[name=tax_select1]', $itemTaxName . ': ' . $itemTaxRate . '%');
$I->click('Save');
$I->wait(1);
2016-10-02 11:51:10 +02:00
//$I->see($productKey);
// create client
$I->amOnPage('/clients/create');
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
$I->click('Save');
$I->see($clientEmail);
// create invoice
$I->amOnPage('/invoices/create');
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
$I->fillField('table.invoice-table tbody tr:nth-child(1) #product_key', $productKey);
2016-02-29 19:08:09 +01:00
$I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable');
2017-03-19 17:31:24 +01:00
$I->selectOption('#taxRateSelect1', $invoiceTaxName . ' ' . floatval($invoiceTaxRate) . '%');
2016-04-15 09:25:26 +02:00
$I->wait(3);
// check total is right before saving
$I->see("\${$total}");
2017-03-25 20:51:08 +01:00
$I->click('Save Draft');
2016-04-30 20:41:05 +02:00
$I->wait(3);
$I->see($clientEmail);
// check total is right after saving
$I->see("\${$total}");
$I->amOnPage('/invoices');
2016-05-05 08:35:39 +02:00
$I->wait(2);
2016-10-02 11:51:10 +02:00
// check total is right in list view
$I->see("\${$total}");
}
2017-05-15 07:54:35 +02:00
public function invoiceTaxRates(AcceptanceTester $I)
{
$I->wantTo('test invoice tax rates');
$clientEmail = $this->faker->safeEmail;
$productKey = $this->faker->text(10);
$invoiceTaxRate = $this->faker->randomFloat(2, 5, 15);
$invoiceTaxName = $this->faker->word();
$itemCost = $this->faker->numberBetween(1, 20);
$total = $itemCost;
$total += round($itemCost * $invoiceTaxRate / 100, 2);
$invoiceTaxRate = number_format($invoiceTaxRate, 3);
// create tax rates
$I->createTaxRate($I, $invoiceTaxName, $invoiceTaxRate);
// enable line item taxes
$I->amOnPage('/settings/tax_rates');
2017-05-17 12:31:21 +02:00
$I->selectOption('#tax_select1', $invoiceTaxName . ': ' . $invoiceTaxRate . '%');
2017-05-15 07:54:35 +02:00
$I->click('Save');
// create product
$I->amOnPage('/products/create');
$I->fillField(['name' => 'product_key'], $productKey);
$I->fillField(['name' => 'notes'], $this->faker->text(80));
$I->fillField(['name' => 'cost'], $itemCost);
$I->click('Save');
$I->wait(1);
//$I->see($productKey);
// create client
$I->amOnPage('/clients/create');
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
$I->click('Save');
$I->see($clientEmail);
// create invoice
$I->amOnPage('/invoices/create');
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
$I->fillField('table.invoice-table tbody tr:nth-child(1) #product_key', $productKey);
$I->click('table.invoice-table tbody tr:nth-child(1) .tt-selectable');
$I->wait(3);
// check total is right before saving
$I->see("\${$total}");
$I->click('Save Draft');
$I->wait(3);
$I->see($clientEmail);
// check total is right after saving
$I->see("\${$total}");
$I->amOnPage('/invoices');
$I->wait(2);
// check total is right in list view
$I->see("\${$total}");
// enable line item taxes
$I->amOnPage('/settings/tax_rates');
2017-05-17 12:31:21 +02:00
$I->selectOption('#tax_select1', '');
2017-05-15 07:54:35 +02:00
$I->click('Save');
}
2016-10-02 11:51:10 +02:00
}