mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-18 18:44:16 +00:00
196 lines
6.1 KiB
PHP
196 lines
6.1 KiB
PHP
<?php
|
|
/**
|
|
* AccountControllerTest.php
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
|
*
|
|
* This software may be modified and distributed under the terms of the
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
*
|
|
* See the LICENSE file for details.
|
|
*/
|
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
|
use FireflyIII\Models\Account;
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
|
use FireflyIII\Repositories\Account\AccountTaskerInterface;
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
|
/**
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-11-20 at 07:15:07.
|
|
*/
|
|
class AccountControllerTest extends TestCase
|
|
{
|
|
|
|
|
|
/**
|
|
* Sets up the fixture, for example, opens a network connection.
|
|
* This method is called before a test is executed.
|
|
*/
|
|
public function setUp()
|
|
{
|
|
parent::setUp();
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::create
|
|
*/
|
|
public function testCreate()
|
|
{
|
|
$this->be($this->user());
|
|
$this->call('GET', route('accounts.create', ['asset']));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::delete
|
|
*/
|
|
public function testDelete()
|
|
{
|
|
$this->be($this->user());
|
|
$this->call('GET', route('accounts.delete', [1]));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::destroy
|
|
*/
|
|
public function testDestroy()
|
|
{
|
|
$repository = $this->mock(AccountRepositoryInterface::class);
|
|
$repository->shouldReceive('find')->withArgs([0])->once()->andReturn(new Account);
|
|
$repository->shouldReceive('destroy')->andReturn(true);
|
|
$this->session(['accounts.delete.url' => 'http://localhost']);
|
|
$this->be($this->user());
|
|
$this->call('post', route('accounts.destroy', [1]));
|
|
$this->assertResponseStatus(302);
|
|
$this->assertSessionHas('success');
|
|
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::edit
|
|
*/
|
|
public function testEdit()
|
|
{
|
|
$this->be($this->user());
|
|
$this->call('GET', route('accounts.edit', [1]));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::index
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param string $range
|
|
*/
|
|
public function testIndex(string $range)
|
|
{
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', route('accounts.index', ['asset']));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::show
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param string $range
|
|
*/
|
|
public function testShow(string $range)
|
|
{
|
|
|
|
$tasker = $this->mock(AccountTaskerInterface::class);
|
|
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
|
|
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
|
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
$collector->shouldReceive('setAccounts')->andReturnSelf();
|
|
$collector->shouldReceive('setRange')->andReturnSelf();
|
|
$collector->shouldReceive('setLimit')->andReturnSelf();
|
|
$collector->shouldReceive('setPage')->andReturnSelf();
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10));
|
|
|
|
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', route('accounts.show', [1]));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::showWithDate
|
|
* @dataProvider dateRangeProvider
|
|
*
|
|
* @param string $range
|
|
*/
|
|
public function testShowByDate(string $range)
|
|
{
|
|
$this->be($this->user());
|
|
$this->changeDateRange($this->user(), $range);
|
|
$this->call('GET', route('accounts.show.date', [1, '2016-01-01']));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::store
|
|
*/
|
|
public function testStore()
|
|
{
|
|
$this->session(['accounts.create.url' => 'http://localhost']);
|
|
$this->be($this->user());
|
|
$data = [
|
|
'name' => 'new account ' . rand(1000, 9999),
|
|
'what' => 'asset',
|
|
];
|
|
|
|
$this->call('post', route('accounts.store', ['asset']), $data);
|
|
$this->assertResponseStatus(302);
|
|
$this->assertSessionHas('success');
|
|
|
|
// list should have this new account.
|
|
$this->call('GET', route('accounts.index', ['asset']));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
$this->see($data['name']);
|
|
}
|
|
|
|
/**
|
|
* @covers FireflyIII\Http\Controllers\AccountController::update
|
|
*/
|
|
public function testUpdate()
|
|
{
|
|
$this->session(['accounts.edit.url' => 'http://localhost']);
|
|
$this->be($this->user());
|
|
$data = [
|
|
'name' => 'updated account ' . rand(1000, 9999),
|
|
'active' => 1,
|
|
'what' => 'asset',
|
|
];
|
|
|
|
$this->call('post', route('accounts.update', [1]), $data);
|
|
$this->assertResponseStatus(302);
|
|
$this->assertSessionHas('success');
|
|
|
|
// list should have this new account.
|
|
$this->call('GET', route('accounts.index', ['asset']));
|
|
$this->assertResponseStatus(200);
|
|
// has bread crumb
|
|
$this->see('<ol class="breadcrumb">');
|
|
$this->see($data['name']);
|
|
}
|
|
}
|