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

193 lines
5.6 KiB
PHP
Raw Normal View History

2015-08-20 17:09:04 +02:00
<?php
use Faker\Factory;
class InvoiceCest
{
/**
* @var \Faker\Generator
*/
private $faker;
public function _before(AcceptanceTester $I)
{
$I->checkIfLogin($I);
$this->faker = Factory::create();
}
2017-02-10 15:13:50 +01:00
2015-08-20 17:09:04 +02:00
public function createInvoice(AcceptanceTester $I)
{
2015-09-01 20:40:30 +02:00
$clientEmail = $this->faker->safeEmail;
2017-02-14 14:50:01 +01:00
$itemTaxName = 'TAX_21';
2015-08-20 17:09:04 +02:00
$I->wantTo('create an invoice');
2015-09-01 20:40:30 +02:00
$I->amOnPage('/clients/create');
2015-10-28 20:22:07 +01:00
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
2015-09-01 20:40:30 +02:00
$I->click('Save');
$I->see($clientEmail);
2017-02-14 21:02:54 +01:00
$clientId = $I->grabFromCurrentUrl('~clients/(\d+)~');
2017-02-10 15:13:50 +01:00
$I->amOnPage('/tax_rates/create');
2017-02-14 14:50:01 +01:00
$I->fillField(['name' => 'name'], $itemTaxName);
2017-02-10 15:13:50 +01:00
$I->fillField(['name' => 'rate'], 21);
$I->click('Save');
$I->see($itemTaxName);
2015-08-20 17:09:04 +02:00
$I->amOnPage('/invoices/create');
$invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value');
2017-02-14 21:02:54 +01:00
// check tax and discount rounding
2015-09-01 20:40:30 +02:00
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
2016-10-02 11:50:15 +02:00
$I->selectDataPicker($I, '#invoice_date');
2015-08-20 17:09:04 +02:00
$I->selectDataPicker($I, '#due_date', '+ 15 day');
$I->fillField('#po_number', rand(100, 200));
2017-02-10 15:13:50 +01:00
$I->fillField('#discount', 15);
2017-02-14 21:02:54 +01:00
$I->selectOption('#taxRateSelect1', $itemTaxName . ' 21%');
2017-02-14 14:50:01 +01:00
$this->fillItem($I, 1, 'Item', 'Notes', 64.50, 3);
2015-08-20 17:09:04 +02:00
$I->click('#saveButton');
$I->wait(1);
$I->see($invoiceNumber);
2017-02-14 21:02:54 +01:00
$I->see('199.01');
2017-08-10 18:05:21 +02:00
for ($i=1; $i<=10; $i++) {
$this->updateDesign($I, $i);
}
2017-02-14 21:02:54 +01:00
$I->amOnPage("/clients/{$clientId}#invoices");
$I->see('199.01');
2015-08-20 17:09:04 +02:00
}
2017-08-10 18:05:21 +02:00
private function updateDesign($I, $designId)
{
$I->selectOption('#invoice_design_id', $designId);
$I->click('#saveButton');
}
2017-02-10 15:13:50 +01:00
/*
public function editInvoice(AcceptanceTester $I)
{
$I->wantTo('edit an invoice');
// Check all language files
$count = $I->grabNumRecords('date_formats');
for ($i=1; $i<=$count; $i++) {
$format = $I->grabFromDatabase('date_formats', 'format', ['id' => $i]);
$date = mktime(0, 0, 0, 12, 31, date('Y'));
$value = date($format, $date);
$I->amOnPage('/settings/localization');
$I->selectOption('date_format_id', $value);
$I->click('Save');
//change po_number with random number
$I->amOnPage('/invoices/1/edit');
2016-10-02 11:50:15 +02:00
$I->selectDataPicker($I, '#invoice_date');
$po_number = rand(1, 10000);
$I->fillField('#po_number', $po_number);
//save
$I->executeJS('submitAction()');
$I->wait(1);
//check if po_number was updated
$I->seeInDatabase('invoices', [
'po_number' => $po_number,
'invoice_date' => date('Y-m-d')
]);
}
}
2016-10-05 16:47:03 +02:00
*/
2017-02-14 21:02:54 +01:00
public function createRecurringInvoice(AcceptanceTester $I)
2015-08-20 17:09:04 +02:00
{
2015-09-01 20:40:30 +02:00
$clientEmail = $this->faker->safeEmail;
2015-08-20 17:09:04 +02:00
$I->wantTo('create a recurring invoice');
2015-09-01 20:40:30 +02:00
$I->amOnPage('/clients/create');
2015-10-28 20:22:07 +01:00
$I->fillField(['name' => 'contacts[0][email]'], $clientEmail);
2015-09-01 20:40:30 +02:00
$I->click('Save');
$I->see($clientEmail);
2015-08-20 17:09:04 +02:00
2015-09-01 20:40:30 +02:00
$I->amOnPage('/recurring_invoices/create');
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
2015-08-20 17:09:04 +02:00
$I->selectDataPicker($I, '#end_date', '+ 1 week');
$I->fillField('#po_number', rand(100, 200));
$I->fillField('#discount', rand(0, 20));
2015-08-20 17:09:04 +02:00
$this->fillItems($I);
2015-08-30 14:08:15 +02:00
$I->executeJS("submitAction('email')");
2017-02-19 15:55:30 +01:00
$I->wait(3);
2015-09-01 20:40:30 +02:00
$I->see($clientEmail);
2015-08-20 17:09:04 +02:00
2016-10-05 16:47:03 +02:00
$I->click('#lastSent');
2015-09-01 20:40:30 +02:00
$I->see($clientEmail);
2015-08-30 14:08:15 +02:00
2016-10-05 16:47:03 +02:00
$I->click('Recurring Invoice');
$I->see($clientEmail);
2015-08-30 14:08:15 +02:00
}
2015-10-23 14:54:07 +02:00
2015-08-20 17:09:04 +02:00
2017-02-14 21:02:54 +01:00
public function cloneInvoice(AcceptanceTester $I)
2015-08-20 17:09:04 +02:00
{
$I->wantTo('clone an invoice');
2015-09-01 20:40:30 +02:00
$I->amOnPage('/invoices/1/clone');
2015-08-20 17:09:04 +02:00
$invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value');
$I->executeJS('submitAction()');
2017-02-19 21:08:53 +01:00
$I->wait(3);
2015-08-20 17:09:04 +02:00
$I->see($invoiceNumber);
}
2015-08-20 17:09:04 +02:00
/*
public function deleteInvoice(AcceptanceTester $I)
{
$I->wantTo('delete an invoice');
$I->amOnPage('/invoices');
$I->seeCurrentUrlEquals('/invoices');
//delete invoice
$I->executeJS(sprintf('deleteEntity(%d)', $id = Helper::getRandom('Invoice', 'public_id', ['is_quote' => 0])));
$I->acceptPopup();
$I->wait(5);
//check if invoice was removed
$I->seeInDatabase('invoices', ['public_id' => $id, 'is_deleted' => true]);
}
*/
private function fillItems(AcceptanceTester $I, $max = 2)
{
2017-02-14 14:50:01 +01:00
for ($row = 1; $row <= $max; $row++) {
2015-08-20 17:09:04 +02:00
2017-02-10 15:13:50 +01:00
$product = $this->faker->text(10);
$description = $this->faker->text(80);
$cost = $this->faker->randomFloat(2, 0, 100);
$quantity = $this->faker->randomDigitNotNull;
2015-08-20 17:09:04 +02:00
2017-02-14 14:50:01 +01:00
$this->fillItem($I, $row, $product, $description, $cost, $quantity);
2015-08-20 17:09:04 +02:00
}
}
2017-02-10 15:13:50 +01:00
2017-02-14 14:50:01 +01:00
private function fillItem(AcceptanceTester $I, $row, $product, $description, $cost, $quantity)
2017-02-10 15:13:50 +01:00
{
2017-02-14 14:50:01 +01:00
$row_selector = sprintf('table.invoice-table tbody tr:nth-child(%d) ', $row);
2017-12-25 14:23:30 +01:00
$I->fillField($row_selector.'td:nth-child(2) input.tt-input', $product);
2017-02-10 15:13:50 +01:00
$I->fillField($row_selector.'textarea', $description);
2017-02-14 14:50:01 +01:00
$I->fillField($row_selector.'td:nth-child(4) input', $cost);
2017-02-10 15:13:50 +01:00
$I->fillField($row_selector.'td:nth-child(5) input', $quantity);
}
2015-08-20 17:09:04 +02:00
}