mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Wrote new tests.
This commit is contained in:
@@ -11,10 +11,21 @@ declare(strict_types = 1);
|
||||
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class PiggyBankControllerTest
|
||||
*
|
||||
* @package Tests\Feature\Controllers
|
||||
*/
|
||||
class PiggyBankControllerTest extends TestCase
|
||||
{
|
||||
|
||||
@@ -23,6 +34,10 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testAdd()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.add', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -33,6 +48,10 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testAddMobile()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.add-money-mobile', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -44,6 +63,14 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.create'));
|
||||
$response->assertStatus(200);
|
||||
@@ -55,6 +82,10 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testDelete()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.delete', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -66,9 +97,14 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
|
||||
|
||||
$this->session(['piggy-banks.delete.url' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('piggy-banks.destroy', [2]));
|
||||
@@ -82,6 +118,14 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testEdit()
|
||||
{
|
||||
// mock stuff
|
||||
$account = factory(Account::class)->make();
|
||||
$accountRepos = $this->mock(AccountRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$accountRepos->shouldReceive('getAccountsByType')
|
||||
->withArgs([[AccountType::DEFAULT, AccountType::ASSET]])->andReturn(new Collection([$account]))->once();
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.edit', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -94,6 +138,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getPiggyBanks')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.index'));
|
||||
$response->assertStatus(200);
|
||||
@@ -105,8 +155,15 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testOrder()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('reset');
|
||||
$repository->shouldReceive('setOrder')->times(2);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('piggy-banks.order', [1, 2]));
|
||||
$response = $this->post(route('piggy-banks.order'), ['order' => [1, 2]]);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
@@ -115,6 +172,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostAdd()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('createEvent')->once();
|
||||
|
||||
$data = ['amount' => '1.123'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('piggy-banks.add', [1]), $data);
|
||||
@@ -130,6 +193,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostAddExact()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('createEvent')->once();
|
||||
|
||||
// find a piggy with current amount = 0.
|
||||
$piggy = PiggyBank::leftJoin('piggy_bank_repetitions', 'piggy_bank_repetitions.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->where('currentamount', 0)
|
||||
@@ -149,6 +218,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testPostRemove()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('createEvent')->once();
|
||||
|
||||
$data = ['amount' => '1.123'];
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('piggy-banks.remove', [1]), $data);
|
||||
@@ -162,6 +237,11 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testRemove()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.remove', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -172,6 +252,10 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testRemoveMobile()
|
||||
{
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.remove-money-mobile', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -183,6 +267,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testShow()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('getEvents')->andReturn(new Collection);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('piggy-banks.show', [1]));
|
||||
$response->assertStatus(200);
|
||||
@@ -194,6 +284,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('store')->andReturn(new PiggyBank);
|
||||
|
||||
$this->session(['piggy-banks.create.url' => 'http://localhost']);
|
||||
$data = [
|
||||
'name' => 'Piggy ' . rand(999, 10000),
|
||||
@@ -214,6 +310,12 @@ class PiggyBankControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// mock stuff
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
$repository->shouldReceive('update')->andReturn(new PiggyBank);
|
||||
|
||||
$this->session(['piggy-banks.edit.url' => 'http://localhost']);
|
||||
$data = [
|
||||
'name' => 'Updated Piggy ' . rand(999, 10000),
|
||||
|
Reference in New Issue
Block a user