2015-08-20 17:09:04 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use \AcceptanceTester;
|
|
|
|
use Faker\Factory;
|
|
|
|
|
|
|
|
class InvoiceCest
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Faker\Generator
|
|
|
|
*/
|
|
|
|
private $faker;
|
|
|
|
|
|
|
|
public function _before(AcceptanceTester $I)
|
|
|
|
{
|
|
|
|
$I->checkIfLogin($I);
|
|
|
|
|
|
|
|
$this->faker = Factory::create();
|
|
|
|
}
|
2015-10-23 14:54:07 +02: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;
|
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);
|
|
|
|
|
2015-08-20 17:09:04 +02:00
|
|
|
$I->amOnPage('/invoices/create');
|
|
|
|
|
|
|
|
$invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value');
|
|
|
|
|
2015-09-01 20:40:30 +02:00
|
|
|
$I->selectDropdown($I, $clientEmail, '.client_select .dropdown-toggle');
|
2015-08-20 17:09:04 +02:00
|
|
|
$I->selectDataPicker($I, '#invoice_date');
|
|
|
|
$I->selectDataPicker($I, '#due_date', '+ 15 day');
|
|
|
|
$I->fillField('#po_number', rand(100, 200));
|
|
|
|
$I->fillField('#discount', rand(0, 20));
|
|
|
|
|
|
|
|
$this->fillItems($I);
|
|
|
|
|
|
|
|
$I->click('#saveButton');
|
|
|
|
$I->wait(1);
|
|
|
|
$I->see($invoiceNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function createRecurringInvoice(AcceptanceTester $I)
|
|
|
|
{
|
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-30 14:08:15 +02:00
|
|
|
|
2015-08-20 17:09:04 +02:00
|
|
|
$this->fillItems($I);
|
2015-08-30 14:08:15 +02:00
|
|
|
|
|
|
|
$I->executeJS("submitAction('email')");
|
2015-08-20 17:09:04 +02:00
|
|
|
$I->wait(1);
|
2015-09-01 20:40:30 +02:00
|
|
|
$I->see($clientEmail);
|
2015-08-20 17:09:04 +02:00
|
|
|
|
2015-08-30 14:08:15 +02:00
|
|
|
$invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value');
|
|
|
|
$I->click('Recurring Invoice');
|
2015-09-01 20:40:30 +02:00
|
|
|
$I->see($clientEmail);
|
2015-08-30 14:08:15 +02:00
|
|
|
|
2015-10-13 09:11:44 +02:00
|
|
|
$I->click('#lastSent');
|
2015-08-30 14:08:15 +02:00
|
|
|
$I->see($invoiceNumber);
|
|
|
|
}
|
2015-10-23 14:54:07 +02:00
|
|
|
|
2015-08-20 17:09:04 +02:00
|
|
|
public function editInvoice(AcceptanceTester $I)
|
|
|
|
{
|
|
|
|
$I->wantTo('edit an invoice');
|
|
|
|
|
|
|
|
$I->amOnPage('/invoices/1/edit');
|
|
|
|
|
|
|
|
//change po_number with random number
|
|
|
|
$po_number = rand(100, 300);
|
2015-09-01 20:40:30 +02:00
|
|
|
$I->fillField('#po_number', $po_number);
|
2015-08-20 17:09:04 +02:00
|
|
|
|
|
|
|
//save
|
|
|
|
$I->executeJS('submitAction()');
|
|
|
|
$I->wait(1);
|
|
|
|
|
|
|
|
//check if po_number was updated
|
|
|
|
$I->seeInDatabase('invoices', ['po_number' => $po_number]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function cloneInvoice(AcceptanceTester $I)
|
|
|
|
{
|
|
|
|
$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()');
|
|
|
|
$I->wait(1);
|
|
|
|
|
|
|
|
$I->see($invoiceNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
for ($i = 1; $i <= $max; $i++) {
|
|
|
|
$row_selector = sprintf('table.invoice-table tbody tr:nth-child(%d) ', $i);
|
|
|
|
|
|
|
|
$product_key = $this->faker->text(10);
|
|
|
|
$description = $this->faker->text(80);
|
|
|
|
$unit_cost = $this->faker->randomFloat(2, 0, 100);
|
|
|
|
$quantity = $this->faker->randomDigitNotNull;
|
|
|
|
|
|
|
|
$I->fillField($row_selector.'#product_key', $product_key);
|
|
|
|
$I->fillField($row_selector.'textarea', $description);
|
|
|
|
$I->fillField($row_selector.'td:nth-child(4) input', $unit_cost);
|
|
|
|
$I->fillField($row_selector.'td:nth-child(5) input', $quantity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|