Integration tests

This commit is contained in:
Hillel Coren 2015-08-30 15:08:15 +03:00
parent ff0a37f1d8
commit ba50e701c8
20 changed files with 3003 additions and 283 deletions

View File

@ -101,6 +101,7 @@ class AppController extends BaseController
if (Industry::count() == 0) { if (Industry::count() == 0) {
Artisan::call('db:seed', array('--force' => true)); Artisan::call('db:seed', array('--force' => true));
} }
Cache::flush();
Artisan::call('optimize', array('--force' => true)); Artisan::call('optimize', array('--force' => true));
$firstName = trim(Input::get('first_name')); $firstName = trim(Input::get('first_name'));

View File

@ -326,6 +326,7 @@ class InvoiceController extends BaseController
$actions[] = ['url' => 'javascript:onArchiveClick()', 'label' => trans("texts.archive_{$entityType}")]; $actions[] = ['url' => 'javascript:onArchiveClick()', 'label' => trans("texts.archive_{$entityType}")];
$actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans("texts.delete_{$entityType}")]; $actions[] = ['url' => 'javascript:onDeleteClick()', 'label' => trans("texts.delete_{$entityType}")];
$lastSent = ($invoice->is_recurring && $invoice->last_sent_date) ? $invoice->recurring_invoices->last() : null;
$data = array( $data = array(
'entityType' => $entityType, 'entityType' => $entityType,
@ -338,7 +339,8 @@ class InvoiceController extends BaseController
'title' => trans("texts.edit_{$entityType}"), 'title' => trans("texts.edit_{$entityType}"),
'client' => $invoice->client, 'client' => $invoice->client,
'isRecurring' => $invoice->is_recurring, 'isRecurring' => $invoice->is_recurring,
'actions' => $actions); 'actions' => $actions,
'lastSent' => $lastSent);
$data = array_merge($data, self::getViewModel()); $data = array_merge($data, self::getViewModel());
// Set the invitation link on the client's contacts // Set the invitation link on the client's contacts

View File

@ -221,7 +221,8 @@ class ReportController extends BaseController
foreach ($period as $d) foreach ($period as $d)
{ {
$dateFormat = $groupBy == 'DAYOFYEAR' ? 'z' : ($groupBy == 'WEEK' ? 'W' : 'n'); $dateFormat = $groupBy == 'DAYOFYEAR' ? 'z' : ($groupBy == 'WEEK' ? 'W' : 'n');
$date = $d->format('Y'.$dateFormat); // MySQL returns 1-366 for DAYOFYEAR, whereas PHP returns 0-365
$date = $groupBy == 'DAYOFYEAR' ? $d->format('Y') . ($d->format($dateFormat) + 1) : $d->format('Y'.$dateFormat);
$totals[] = isset($data[$date]) ? $data[$date] : 0; $totals[] = isset($data[$date]) ? $data[$date] : 0;
if ($entityType == ENTITY_INVOICE) if ($entityType == ENTITY_INVOICE)

View File

@ -219,6 +219,7 @@ Route::get('/forgot_password', function() {
}); });
if (!defined('CONTACT_EMAIL')) {
define('CONTACT_EMAIL', Config::get('mail.from.address')); define('CONTACT_EMAIL', Config::get('mail.from.address'));
define('CONTACT_NAME', Config::get('mail.from.name')); define('CONTACT_NAME', Config::get('mail.from.name'));
define('SITE_URL', Config::get('app.url')); define('SITE_URL', Config::get('app.url'));
@ -399,7 +400,7 @@ define('USER_TYPE_SELF_HOST', 'SELF_HOST');
define('USER_TYPE_CLOUD_HOST', 'CLOUD_HOST'); define('USER_TYPE_CLOUD_HOST', 'CLOUD_HOST');
define('NEW_VERSION_AVAILABLE', 'NEW_VERSION_AVAILABLE'); define('NEW_VERSION_AVAILABLE', 'NEW_VERSION_AVAILABLE');
define('TEST_USERNAME', 'user@email.com'); define('TEST_USERNAME', 'user@example.com');
define('TEST_PASSWORD', 'password'); define('TEST_PASSWORD', 'password');
define('TOKEN_BILLING_DISABLED', 1); define('TOKEN_BILLING_DISABLED', 1);
@ -442,6 +443,7 @@ function otrans($text)
return $string != $english ? $string : ''; return $string != $english ? $string : '';
} }
} }
}
/* /*
// Log all SQL queries to laravel.log // Log all SQL queries to laravel.log

View File

@ -119,6 +119,6 @@ return [
| |
*/ */
'pretend' => false, 'pretend' => env('MAIL_PRETEND'),
]; ];

View File

@ -23,6 +23,8 @@ class UserTableSeeder extends Seeder
'username' => TEST_USERNAME, 'username' => TEST_USERNAME,
'account_id' => $account->id, 'account_id' => $account->id,
'password' => Hash::make(TEST_PASSWORD), 'password' => Hash::make(TEST_PASSWORD),
'registered' => true,
'confirmed' => true,
]); ]);
} }

View File

@ -31,7 +31,7 @@ return array(
'client' => 'Kunde', 'client' => 'Kunde',
'invoice_date' => 'Rechnungsdatum', 'invoice_date' => 'Rechnungsdatum',
'due_date' => 'Fällig am', 'due_date' => 'Fällig am',
'invoice_number' => 'Rechungsnummer', 'invoice_number' => 'Rechnungsnummer',
'invoice_number_short' => 'Rechnung #', 'invoice_number_short' => 'Rechnung #',
'po_number' => 'Bestellnummer', 'po_number' => 'Bestellnummer',
'po_number_short' => 'BN #', 'po_number_short' => 'BN #',
@ -346,7 +346,7 @@ return array(
'chart_builder' => 'Diagrammersteller', 'chart_builder' => 'Diagrammersteller',
'ninja_email_footer' => 'Nutze :site um Kunden Rechnungen zu stellen und online bezahlt zu werden, kostenlos!', 'ninja_email_footer' => 'Nutze :site um Kunden Rechnungen zu stellen und online bezahlt zu werden, kostenlos!',
'go_pro' => 'Werde Pro-Mitglied', 'go_pro' => 'Go Pro',
// Quotes // Quotes
'quote' => 'Angebot', 'quote' => 'Angebot',

View File

@ -20,7 +20,7 @@
@endif @endif
{!! Former::text('product_key')->label('texts.product') !!} {!! Former::text('product_key')->label('texts.product') !!}
{!! Former::textarea('notes')->data_bind("value: wrapped_notes, valueUpdate: 'afterkeydown'") !!} {!! Former::textarea('notes') !!}
{!! Former::text('cost') !!} {!! Former::text('cost') !!}
</div> </div>
@ -35,29 +35,6 @@
<script type="text/javascript"> <script type="text/javascript">
function ViewModel(data) {
var self = this;
@if ($product)
self.notes = ko.observable(wordWrapText('{{ str_replace(["\r\n","\r","\n"], '\n', addslashes($product->notes)) }}', 300));
@else
self.notes = ko.observable('');
@endif
self.wrapped_notes = ko.computed({
read: function() {
return self.notes();
},
write: function(value) {
value = wordWrapText(value, 235);
self.notes(value);
},
owner: this
});
}
window.model = new ViewModel();
ko.applyBindings(model);
$(function() { $(function() {
$('#product_key').focus(); $('#product_key').focus();
}); });

View File

@ -100,10 +100,10 @@
<div class="pull-right" style="padding-top: 6px"> <div class="pull-right" style="padding-top: 6px">
{!! trans('texts.created_by_invoice', ['invoice' => link_to('/invoices/'.$invoice->recurring_invoice->public_id, trans('texts.recurring_invoice'))]) !!} {!! trans('texts.created_by_invoice', ['invoice' => link_to('/invoices/'.$invoice->recurring_invoice->public_id, trans('texts.recurring_invoice'))]) !!}
</div> </div>
@elseif ($invoice && $invoice->last_sent_date && $invoice->recurring_invoices->last()) @elseif ($invoice && isset($lastSent) && $lastSent)
<div class="pull-right" style="padding-top: 6px"> <div class="pull-right" style="padding-top: 6px">
{!! trans('texts.last_invoice_sent', [ {!! trans('texts.last_invoice_sent', [
'date' => link_to('/invoices/'.$invoice->recurring_invoices->last()->public_id, Utils::dateToString($invoice->last_sent_date)) 'date' => link_to('/invoices/'.$lastSent->public_id, Utils::dateToString($invoice->last_sent_date), ['id' => 'lastInvoiceSent'])
]) !!} ]) !!}
</div> </div>
@endif @endif

View File

@ -2,5 +2,5 @@
// This is global bootstrap for autoloading // This is global bootstrap for autoloading
use Codeception\Util\Fixtures; use Codeception\Util\Fixtures;
Fixtures::add('username', 'user@email.com'); Fixtures::add('username', 'user@example.com');
Fixtures::add('password', 'password'); Fixtures::add('password', 'password');

View File

@ -1,5 +1,6 @@
<?php <?php
use Codeception\Util\Fixtures;
/** /**
* Inherited Methods * Inherited Methods
@ -23,4 +24,15 @@ class FunctionalTester extends \Codeception\Actor
/** /**
* Define custom actions here * Define custom actions here
*/ */
function checkIfLogin(\FunctionalTester $I)
{
//if ($I->loadSessionSnapshot('login')) return;
$I->amOnPage('/login');
$I->fillField(['name' => 'email'], Fixtures::get('username'));
$I->fillField(['name' => 'password'], Fixtures::get('password'));
$I->click('Let\'s go');
//$I->saveSessionSnapshot('login');
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -25,7 +25,7 @@ class ChartsAndReportsCest
$faker = Faker\Factory::create(); $faker = Faker\Factory::create();
$I->wantTo("Run the report"); $I->wantTo('Run the report');
$I->amOnPage('/company/advanced_settings/charts_and_reports'); $I->amOnPage('/company/advanced_settings/charts_and_reports');

View File

@ -1,30 +0,0 @@
<?php
use \AcceptanceTester;
use Faker\Factory;
class GatewayCest
{
private $faker;
public function _before(AcceptanceTester $I)
{
$I->checkIfLogin($I);
$this->faker = Factory::create();
}
// tests
public function create(AcceptanceTester $I)
{
$I->wantTo("create a gateway");
$I->amOnPage('/gateways/create');
$I->seeCurrentUrlEquals('/gateways/create');
$I->fillField(['name' => '23_apiKey'], $this->faker->swiftBicNumber);
$I->click('Save');
$I->see('Successfully created gateway');
$I->seeInDatabase('account_gateways', array('gateway_id' => 23));
}
}

View File

@ -47,18 +47,22 @@ class InvoiceCest
$I->amOnPage('/recurring_invoices/create'); $I->amOnPage('/recurring_invoices/create');
$I->selectDropdown($I, $clientName, '.client_select .dropdown-toggle'); $I->selectDropdown($I, $clientName, '.client_select .dropdown-toggle');
//$I->selectOption('#frequency_id', Helper::getRandom('Frequency'));
$I->selectDataPicker($I, '#start_date');
$I->selectDataPicker($I, '#end_date', '+ 1 week'); $I->selectDataPicker($I, '#end_date', '+ 1 week');
$I->fillField('#po_number', rand(100, 200)); $I->fillField('#po_number', rand(100, 200));
$I->fillField('#discount', rand(0, 20)); $I->fillField('#discount', rand(0, 20));
$this->fillItems($I); $this->fillItems($I);
$I->executeJS('submitAction()'); $I->executeJS("submitAction('email')");
$I->wait(1); $I->wait(1);
$I->see($clientName); $I->see($clientName);
$invoiceNumber = $I->grabAttributeFrom('#invoice_number', 'value');
$I->click('Recurring Invoice');
$I->see($clientName);
$I->click('#lastInvoiceSent');
$I->see($invoiceNumber);
} }
public function editInvoice(AcceptanceTester $I) public function editInvoice(AcceptanceTester $I)
@ -111,25 +115,6 @@ class InvoiceCest
} }
*/ */
/*
public function indexInvoice(AcceptanceTester $I)
{
$I->wantTo('list invoices');
$I->amOnPage('/invoices');
$I->seeCurrentUrlEquals('/invoices');
$random_invoice_number = Helper::getRandom('Invoice', 'invoice_number', [
'is_quote' => 0,
'is_recurring' => false
]);
if ($random_invoice_number) {
$I->wait(2);
$I->see($random_invoice_number);
}
}
*/
private function fillItems(AcceptanceTester $I, $max = 2) private function fillItems(AcceptanceTester $I, $max = 2)
{ {

View File

@ -20,7 +20,7 @@ class PaymentCest
$clientName = $I->grabFromDatabase('clients', 'name'); $clientName = $I->grabFromDatabase('clients', 'name');
$amount = rand(1, 30); $amount = rand(1, 30);
$I->wantTo("enter a payment"); $I->wantTo('enter a payment');
$I->amOnPage('/payments/create'); $I->amOnPage('/payments/create');
$I->selectDropdown($I, $clientName, '.client-select .dropdown-toggle'); $I->selectDropdown($I, $clientName, '.client-select .dropdown-toggle');
@ -40,7 +40,7 @@ class PaymentCest
{ {
$ref = $this->faker->text(12); $ref = $this->faker->text(12);
$I->wantTo("edit a payment"); $I->wantTo('edit a payment');
$I->amOnPage('/payments/1/edit'); $I->amOnPage('/payments/1/edit');
$I->selectDataPicker($I, '#payment_date', 'now + 2 day'); $I->selectDataPicker($I, '#payment_date', 'now + 2 day');
@ -52,7 +52,7 @@ class PaymentCest
public function listPayments(AcceptanceTester $I) public function listPayments(AcceptanceTester $I)
{ {
$I->wantTo("list payments"); $I->wantTo('list payments');
$I->amOnPage('/payments'); $I->amOnPage('/payments');
$I->seeNumberOfElements('tbody tr[role=row]', [1, 10]); $I->seeNumberOfElements('tbody tr[role=row]', [1, 10]);

View File

@ -69,7 +69,7 @@ class TaskCest
public function listTasks(AcceptanceTester $I) public function listTasks(AcceptanceTester $I)
{ {
$I->wantTo("list tasks"); $I->wantTo('list tasks');
$I->amOnPage('/tasks'); $I->amOnPage('/tasks');
$I->seeNumberOfElements('tbody tr[role=row]', [1, 10]); $I->seeNumberOfElements('tbody tr[role=row]', [1, 10]);

View File

@ -7,5 +7,9 @@
class_name: FunctionalTester class_name: FunctionalTester
modules: modules:
enabled: enabled:
# add framework module here
- \Helper\Functional - \Helper\Functional
- PhpBrowser:
url: 'http://ninja.dev/'
- Laravel5:
environment_file: '.env'
cleanup: false

View File

@ -0,0 +1,193 @@
<?php
use \FunctionalTester;
use Faker\Factory;
class SettingsCest
{
private $faker;
public function _before(FunctionalTester $I)
{
$I->checkIfLogin($I);
$this->faker = Factory::create();
}
public function companyDetails(FunctionalTester $I)
{
$I->wantTo('update the company details');
$I->amOnPage('/company/details');
$name = $this->faker->company;
$I->fillField(['name' => 'name'], $name);
$I->fillField(['name' => 'work_email'], $this->faker->safeEmail);
$I->fillField(['name' => 'work_phone'], $this->faker->phoneNumber);
$I->fillField(['name' => 'address1'], $this->faker->buildingNumber . ' ' . $this->faker->streetName);
$I->fillField(['name' => 'address2'], $this->faker->secondaryAddress);
$I->fillField(['name' => 'city'], $this->faker->city);
$I->fillField(['name' => 'state'], $this->faker->state);
$I->fillField(['name' => 'postal_code'], $this->faker->postcode);
$I->fillField(['name' => 'first_name'], $this->faker->firstName);
$I->fillField(['name' => 'last_name'], $this->faker->lastName);
$I->fillField(['name' => 'phone'], $this->faker->phoneNumber);
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated settings');
$I->seeRecord('accounts', array('name' => $name));
}
public function productSettings(FunctionalTester $I)
{
$I->wantTo('update the product settings');
$I->amOnPage('/company/products');
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated settings');
}
public function onlinePayments(FunctionalTester $I)
{
$gateway = $I->grabRecord('account_gateways', array('gateway_id' => 23));
if (!$gateway) {
$apiKey = $this->faker->swiftBicNumber;
$I->wantTo('create a gateway');
$I->amOnPage('/gateways/create');
$I->seeCurrentUrlEquals('/gateways/create');
$I->fillField(['name' => '23_apiKey'], $apiKey);
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully created gateway');
$I->seeRecord('account_gateways', array('gateway_id' => 23));
} else {
$config = json_decode($gateway->config);
$apiKey = $config->apiKey;
}
/*
$I->amOnPage('/gateways/1/edit');
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated gateway');
$I->seeRecord('account_gateways', array('config' => '{"apiKey":"ASHHOWAH"}'));
*/
}
public function createProduct(FunctionalTester $I)
{
$I->wantTo('create a product');
$I->amOnPage('/products/create');
$productKey = $this->faker->text(10);
$I->fillField(['name' => 'product_key'], $productKey);
$I->fillField(['name' => 'notes'], $this->faker->text(80));
$I->fillField(['name' => 'cost'], $this->faker->numberBetween(1,20));
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully created product');
$I->seeRecord('products', array('product_key' => $productKey));
}
public function updateProduct(FunctionalTester $I)
{
return;
$I->wantTo('update a product');
$I->amOnPage('/products/1/edit');
$productKey = $this->faker->text(10);
$I->fillField(['name' => 'product_key'], $productKey);
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated product');
$I->seeRecord('products', array('product_key' => $productKey));
}
public function updateNotifications(FunctionalTester $I)
{
$I->wantTo('update notification settings');
$I->amOnPage('/company/notifications');
$terms = $this->faker->text(80);
$I->fillField(['name' => 'invoice_terms'], $terms);
$I->fillField(['name' => 'invoice_footer'], $this->faker->text(60));
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated settings');
$I->seeRecord('accounts', array('invoice_terms' => $terms));
}
public function updateInvoiceDesign(FunctionalTester $I)
{
$I->wantTo('update invoice design');
$I->amOnPage('/company/advanced_settings/invoice_design');
$color = $this->faker->hexcolor;
$I->fillField(['name' => 'labels_item'], $this->faker->text(14));
$I->fillField(['name' => 'primary_color'], $color);
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated settings');
$I->seeRecord('accounts', array('primary_color' => $color));
}
public function updateInvoiceSettings(FunctionalTester $I)
{
$I->wantTo('update invoice settings');
$I->amOnPage('/company/advanced_settings/invoice_settings');
$label = $this->faker->text(10);
$I->fillField(['name' => 'custom_client_label1'], $label);
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated settings');
$I->seeRecord('accounts', array('custom_client_label1' => $label));
$I->amOnPage('/clients/create');
$I->see($label);
}
public function updateEmailTemplates(FunctionalTester $I)
{
$I->wantTo('update email templates');
$I->amOnPage('/company/advanced_settings/email_templates');
$string = $this->faker->text(100);
$I->fillField(['name' => 'email_template_payment'], $string);
$I->click('Save');
$I->seeResponseCodeIs(200);
$I->see('Successfully updated settings');
$I->seeRecord('accounts', array('email_template_payment' => $string));
}
public function runReport(FunctionalTester $I)
{
$I->wantTo('run the report');
$I->amOnPage('/company/advanced_settings/charts_and_reports');
$I->click('Run');
$I->seeResponseCodeIs(200);
}
}