mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New unit tests to cover missed methods.
This commit is contained in:
@@ -1,21 +1,9 @@
|
||||
<?php
|
||||
$db = realpath(__DIR__ . '/_data') . '/db.sqlite';
|
||||
if(!file_exists($db)) {
|
||||
exec('touch '.$db);
|
||||
exec('php artisan migrate --seed --env=testing');
|
||||
exec('sqlite3 tests/_data/db.sqlite .dump > tests/_data/dump.sql');
|
||||
$db = realpath(__DIR__ . '/_data') . '/db.sqlite';
|
||||
$dump = realpath(__DIR__ . '/_data') . '/dump.sql';
|
||||
if (!file_exists($db)) {
|
||||
$out = [];
|
||||
exec('touch ' . $db);
|
||||
exec('php artisan migrate --seed --env=testing', $out);
|
||||
exec('sqlite3 tests/_data/db.sqlite .dump > tests/_data/dump.sql', $out);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class resetToClean
|
||||
*/
|
||||
class resetToClean
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static public function clean()
|
||||
{
|
||||
//exec('cp ' . realpath(__DIR__ . '/_data') . '/clean.sqlite ' . realpath(__DIR__ . '/_data') . '/testing.sqlite');
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,10 @@ modules:
|
||||
Db:
|
||||
populate: false
|
||||
cleanup: true
|
||||
dsn: 'sqlite:tests/_data/db.sqlite'
|
||||
user: ''
|
||||
password: ''
|
||||
dump: tests/_data/dump.sql
|
||||
Laravel4:
|
||||
environment: 'testing'
|
||||
filters: false
|
||||
@@ -55,7 +55,6 @@ class AccountControllerCest
|
||||
$I->see('Delete account "Delete me"');
|
||||
$I->submitForm('#destroy', []);
|
||||
$I->dontSeeRecord('accounts', ['id' => 3, 'deleted_at' => null]);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -113,7 +112,6 @@ class AccountControllerCest
|
||||
$I->see('Create a new asset account');
|
||||
$I->submitForm('#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'store']);
|
||||
$I->seeRecord('accounts', ['name' => 'New through tests.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -128,7 +126,6 @@ class AccountControllerCest
|
||||
'#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'create_another']
|
||||
);
|
||||
$I->seeRecord('accounts', ['name' => 'New through tests.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -141,7 +138,6 @@ class AccountControllerCest
|
||||
$I->see('Create a new asset account');
|
||||
$I->submitForm('#store', ['name' => null, 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']);
|
||||
$I->dontSeeRecord('accounts', ['name' => 'New through tests.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -156,7 +152,6 @@ class AccountControllerCest
|
||||
'#store', ['name' => 'New through tests.', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'validate_only']
|
||||
);
|
||||
$I->dontSeeRecord('accounts', ['name' => 'New through tests.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,7 +164,6 @@ class AccountControllerCest
|
||||
$I->see('Edit asset account "Delete me"');
|
||||
$I->submitForm('#update', ['name' => 'Update me', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'update']);
|
||||
$I->seeRecord('accounts', ['name' => 'Update me']);
|
||||
resetToClean::clean();
|
||||
|
||||
}
|
||||
|
||||
@@ -185,7 +179,6 @@ class AccountControllerCest
|
||||
'#update', ['name' => 'Savings accountXX', 'what' => 'asset', 'account_role' => 'defaultExpense', 'post_submit_action' => 'return_to_edit']
|
||||
);
|
||||
$I->seeRecord('accounts', ['name' => 'Savings accountXX']);
|
||||
resetToClean::clean();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,6 @@ class BudgetControllerCest
|
||||
$I->see('Create a new budget');
|
||||
$I->submitForm('#store', ['name' => 'New budget.', 'post_submit_action' => 'store']);
|
||||
$I->seeRecord('budgets', ['name' => 'New budget.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +196,6 @@ class BudgetControllerCest
|
||||
$I->see('Edit budget "Delete me"');
|
||||
$I->submitForm('#update', ['name' => 'Update me', 'post_submit_action' => 'update']);
|
||||
$I->seeRecord('budgets', ['name' => 'Update me']);
|
||||
resetToClean::clean();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,6 @@ class CategoryControllerCest
|
||||
$I->see('Create a new category');
|
||||
$I->submitForm('#store', ['name' => 'New category.', 'post_submit_action' => 'store']);
|
||||
$I->seeRecord('categories', ['name' => 'New category.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +119,6 @@ class CategoryControllerCest
|
||||
$I->see('Create a new category');
|
||||
$I->submitForm('#store', ['name' => 'New category.', 'post_submit_action' => 'create_another']);
|
||||
$I->seeRecord('categories', ['name' => 'New category.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,7 +131,6 @@ class CategoryControllerCest
|
||||
$I->see('Create a new category');
|
||||
$I->submitForm('#store', ['name' => null, 'post_submit_action' => 'validate_only']);
|
||||
$I->dontSeeRecord('categories', ['name' => 'New category.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,7 +143,6 @@ class CategoryControllerCest
|
||||
$I->see('Create a new category');
|
||||
$I->submitForm('#store', ['name' => 'New category.', 'post_submit_action' => 'validate_only']);
|
||||
$I->dontSeeRecord('categories', ['name' => 'New category.']);
|
||||
resetToClean::clean();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -159,7 +155,6 @@ class CategoryControllerCest
|
||||
$I->see('Edit category "Delete me"');
|
||||
$I->submitForm('#update', ['name' => 'Update me', 'post_submit_action' => 'update']);
|
||||
$I->seeRecord('categories', ['name' => 'Update me']);
|
||||
resetToClean::clean();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -168,7 +168,6 @@ class CurrencyControllerCest
|
||||
$I->see('Edit currency "US Dollar"');
|
||||
$I->submitForm('#update', ['name' => 'Successful update', 'symbol' => '$', 'code' => 'USD', 'post_submit_action' => 'update']);
|
||||
$I->seeRecord('transaction_currencies', ['name' => 'Successful update']);
|
||||
resetToClean::clean();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,10 @@ class TransactionControllerCest
|
||||
public function destroyTransfer(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo('destroy a transfer');
|
||||
$I->amOnPage('/transaction/delete/406');
|
||||
|
||||
$journal = TransactionJournal::whereDescription('Money for new PC')->first();
|
||||
|
||||
$I->amOnPage('/transaction/delete/' . $journal->id);
|
||||
$I->submitForm('#destroy', []);
|
||||
$I->see('Transaction "Money for new PC" destroyed.');
|
||||
|
||||
@@ -63,8 +66,9 @@ class TransactionControllerCest
|
||||
|
||||
public function edit(FunctionalTester $I)
|
||||
{
|
||||
$journal = TransactionJournal::whereDescription('Money for piggy')->first();
|
||||
$I->wantTo('edit a transaction');
|
||||
$I->amOnPage('/transaction/edit/408');
|
||||
$I->amOnPage('/transaction/edit/' . $journal->id);
|
||||
$I->see('Edit transfer "Money for piggy"');
|
||||
}
|
||||
|
||||
@@ -91,8 +95,10 @@ class TransactionControllerCest
|
||||
|
||||
public function show(FunctionalTester $I)
|
||||
{
|
||||
$journal = TransactionJournal::whereDescription('Money for new PC')->first();
|
||||
|
||||
$I->wantTo('see a transaction');
|
||||
$I->amOnPage('/transaction/show/406');
|
||||
$I->amOnPage('/transaction/show/' . $journal->id);
|
||||
$I->see('Transfer "Money for new PC"');
|
||||
$I->see('1.259');
|
||||
}
|
||||
@@ -117,27 +123,6 @@ class TransactionControllerCest
|
||||
$I->see('Transaction "Test" stored.');
|
||||
}
|
||||
|
||||
public function storeAndReturn(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo('store a transaction');
|
||||
$I->amOnPage('/transactions/create/withdrawal');
|
||||
$I->submitForm(
|
||||
'#store', [
|
||||
'reminder' => '',
|
||||
'description' => 'Test',
|
||||
'account_id' => 1,
|
||||
'expense_account' => 'Zomaar',
|
||||
'amount' => 100,
|
||||
'date' => '2014-12-30',
|
||||
'budget_id' => 3,
|
||||
'category' => 'Categorrr',
|
||||
'post_submit_action' => 'create_another'
|
||||
]
|
||||
);
|
||||
$I->see('Transaction "Test" stored.');
|
||||
}
|
||||
|
||||
|
||||
public function storeAndFail(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo('store a transaction and fail');
|
||||
@@ -158,6 +143,26 @@ class TransactionControllerCest
|
||||
$I->see('Could not store transaction: The description field is required.');
|
||||
}
|
||||
|
||||
public function storeAndReturn(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo('store a transaction');
|
||||
$I->amOnPage('/transactions/create/withdrawal');
|
||||
$I->submitForm(
|
||||
'#store', [
|
||||
'reminder' => '',
|
||||
'description' => 'Test',
|
||||
'account_id' => 1,
|
||||
'expense_account' => 'Zomaar',
|
||||
'amount' => 100,
|
||||
'date' => '2014-12-30',
|
||||
'budget_id' => 3,
|
||||
'category' => 'Categorrr',
|
||||
'post_submit_action' => 'create_another'
|
||||
]
|
||||
);
|
||||
$I->see('Transaction "Test" stored.');
|
||||
}
|
||||
|
||||
public function update(FunctionalTester $I)
|
||||
{
|
||||
$I->wantTo('update a transaction');
|
||||
|
||||
@@ -1,2 +1,8 @@
|
||||
<?php
|
||||
// Here you can initialize variables that will be available to your tests
|
||||
$db = realpath(__DIR__ . '/../_data') . '/db.sqlite';
|
||||
if (!file_exists($db)) {
|
||||
$out = [];
|
||||
exec('touch ' . $db);
|
||||
exec('php artisan migrate --seed --env=testing', $out);
|
||||
exec('sqlite3 tests/_data/db.sqlite .dump > tests/_data/dump.sql', $out);
|
||||
}
|
||||
40
tests/unit/AccountTest.php
Normal file
40
tests/unit/AccountTest.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
use League\FactoryMuffin\Facade as f;
|
||||
|
||||
/**
|
||||
* Class AccountTest
|
||||
*/
|
||||
class AccountTest extends TestCase
|
||||
{
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
// tests
|
||||
|
||||
public function testAccountMeta()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
$newMeta = $account->updateMeta('field', 'value');
|
||||
$this->assertInstanceOf('AccountMeta', $newMeta);
|
||||
$secondMeta = $account->updateMeta('field', 'newValue');
|
||||
$this->assertEquals($newMeta->id, $secondMeta->id);
|
||||
$this->assertEquals($newMeta->data, 'value');
|
||||
$this->assertEquals($secondMeta->data, 'newValue');
|
||||
}
|
||||
|
||||
public function testAccountUser()
|
||||
{
|
||||
$account = f::create('Account');
|
||||
$this->assertInstanceOf('Account', $account);
|
||||
$this->assertInstanceOf('User', $account->user);
|
||||
}
|
||||
|
||||
}
|
||||
18
tests/unit/ExamplATest.php
Normal file
18
tests/unit/ExamplATest.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
class ExamplATest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
// tests
|
||||
public function testMe()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user