Files
firefly-iii/tests/acceptance/Controllers/AccountControllerTest.php

185 lines
5.5 KiB
PHP
Raw Normal View History

2016-11-19 20:30:30 +01:00
<?php
2016-12-06 09:16:36 +01:00
/**
* 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.
*/
2016-12-11 13:16:56 +01:00
use FireflyIII\Models\Account;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
2016-11-19 20:30:30 +01:00
/**
2016-11-20 08:30:25 +01:00
* Generated by PHPUnit_SkeletonGenerator on 2016-11-20 at 07:15:07.
2016-11-19 20:30:30 +01:00
*/
class AccountControllerTest extends TestCase
{
2016-11-20 07:24:18 +01:00
2016-11-19 20:30:30 +01:00
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
2016-11-20 08:30:25 +01:00
parent::setUp();
2016-11-19 20:30:30 +01:00
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::create
*/
public function testCreate()
{
2016-11-20 08:30:25 +01:00
$this->be($this->user());
$this->call('GET', route('accounts.create', ['asset']));
$this->assertResponseStatus(200);
2016-12-09 07:08:31 +01:00
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::delete
*/
public function testDelete()
{
2016-11-20 08:46:02 +01:00
$this->be($this->user());
$this->call('GET', route('accounts.delete', [1]));
$this->assertResponseStatus(200);
2016-12-09 07:08:31 +01:00
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::destroy
*/
public function testDestroy()
{
2016-12-11 13:16:56 +01:00
$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');
2016-11-19 20:30:30 +01:00
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::edit
*/
public function testEdit()
{
2016-11-20 08:46:02 +01:00
$this->be($this->user());
$this->call('GET', route('accounts.edit', [1]));
$this->assertResponseStatus(200);
2016-12-09 07:08:31 +01:00
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
2016-11-20 08:46:02 +01:00
* @covers FireflyIII\Http\Controllers\AccountController::index
* @dataProvider dateRangeProvider
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-11-20 08:46:02 +01:00
public function testIndex(string $range)
2016-11-19 20:30:30 +01:00
{
2016-11-20 08:46:02 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('accounts.index', ['asset']));
$this->assertResponseStatus(200);
2016-12-09 07:08:31 +01:00
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
2016-11-20 08:54:52 +01:00
* @covers FireflyIII\Http\Controllers\AccountController::show
2016-11-20 08:46:02 +01:00
* @dataProvider dateRangeProvider
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-11-20 08:46:02 +01:00
public function testShow(string $range)
2016-11-19 20:30:30 +01:00
{
2016-11-20 08:46:02 +01:00
$tasker = $this->mock(\FireflyIII\Repositories\Account\AccountTaskerInterface::class);
$tasker->shouldReceive('amountOutInPeriod')->withAnyArgs()->andReturn('-1');
$tasker->shouldReceive('amountInInPeriod')->withAnyArgs()->andReturn('1');
2016-11-20 08:54:52 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-11-20 08:46:02 +01:00
$this->call('GET', route('accounts.show', [1]));
$this->assertResponseStatus(200);
2016-12-09 07:08:31 +01:00
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
2016-11-20 08:54:52 +01:00
* @covers FireflyIII\Http\Controllers\AccountController::showWithDate
2016-11-20 08:46:02 +01:00
* @dataProvider dateRangeProvider
*
* @param string $range
2016-11-19 20:30:30 +01:00
*/
2016-12-06 09:16:36 +01:00
public function testShowByDate(string $range)
2016-11-19 20:30:30 +01:00
{
2016-11-20 08:46:02 +01:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-11-20 08:54:52 +01:00
$this->call('GET', route('accounts.show.date', [1, '2016-01-01']));
2016-11-20 08:46:02 +01:00
$this->assertResponseStatus(200);
2016-12-09 07:08:31 +01:00
// has bread crumb
$this->see('<ol class="breadcrumb">');
2016-11-19 20:30:30 +01:00
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::store
*/
public function testStore()
{
2016-12-11 13:16:56 +01:00
$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']);
2016-11-19 20:30:30 +01:00
}
/**
* @covers FireflyIII\Http\Controllers\AccountController::update
*/
public function testUpdate()
{
2016-12-11 13:16:56 +01:00
$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']);
2016-11-19 20:30:30 +01:00
}
}