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

140 lines
4.1 KiB
PHP
Raw Normal View History

2016-01-19 06:53:55 -06:00
<?php
/**
* AccountControllerTest.php
* Copyright (C) 2016 Sander Dorigo
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
2016-02-06 02:52:31 -06:00
use Illuminate\Pagination\LengthAwarePaginator;
2016-01-19 06:53:55 -06:00
/**
* Class AccountControllerTest
*/
class AccountControllerTest extends TestCase
{
2016-01-19 09:55:53 -06:00
/**
* @covers FireflyIII\Http\Controllers\AccountController::create
* @covers FireflyIII\Http\Controllers\AccountController::__construct
* @dataProvider dateRangeProvider
2016-02-05 08:41:40 -06:00
*
* @param $range
2016-01-19 09:55:53 -06:00
*/
public function testCreate($range)
2016-01-19 06:53:55 -06:00
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-01-24 11:11:57 -06:00
$this->call('GET', '/accounts/create/asset');
$this->assertResponseStatus(200);
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
* @covers FireflyIII\Http\Controllers\AccountController::delete
*/
2016-01-19 06:53:55 -06:00
public function testDelete()
{
$this->be($this->user());
2016-01-24 11:11:57 -06:00
$this->call('GET', '/accounts/delete/1');
$this->assertResponseStatus(200);
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
* @covers FireflyIII\Http\Controllers\AccountController::destroy
*/
2016-01-19 06:53:55 -06:00
public function testDestroy()
{
2016-01-19 07:37:44 -06:00
$this->be($this->user());
$this->session(['accounts.delete.url' => 'http://localhost']);
2016-01-24 11:11:57 -06:00
$this->call('POST', '/accounts/destroy/6');
2016-01-19 07:37:44 -06:00
$this->assertSessionHas('success');
2016-01-24 11:11:57 -06:00
$this->assertResponseStatus(302);
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
* @covers FireflyIII\Http\Controllers\AccountController::edit
*/
2016-01-19 06:53:55 -06:00
public function testEdit()
{
$this->be($this->user());
2016-01-24 11:11:57 -06:00
$this->call('GET', '/accounts/edit/1');
$this->assertResponseStatus(200);
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
2016-02-05 08:41:40 -06:00
* @covers FireflyIII\Http\Controllers\AccountController::index
* @covers FireflyIII\Http\Controllers\AccountController::isInArray
* @dataProvider dateRangeProvider
2016-02-05 08:41:40 -06:00
*
* @param $range
2016-01-19 09:55:53 -06:00
*/
public function testIndex($range)
2016-01-19 06:53:55 -06:00
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-01-24 11:11:57 -06:00
$this->call('GET', '/accounts/asset');
$this->assertResponseStatus(200);
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
2016-02-05 08:41:40 -06:00
* @covers FireflyIII\Http\Controllers\AccountController::show
* @dataProvider dateRangeProvider
2016-02-05 08:41:40 -06:00
*
* @param $range
2016-01-19 09:55:53 -06:00
*/
public function testShow($range)
2016-01-19 06:53:55 -06:00
{
2016-02-06 02:52:31 -06:00
$repository = $this->mock('FireflyIII\Repositories\Account\AccountRepositoryInterface');
$repository->shouldReceive('getJournals')->once()->andReturn(new LengthAwarePaginator([], 0, 50));
2016-01-19 06:53:55 -06:00
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
2016-01-24 11:11:57 -06:00
$this->call('GET', '/accounts/show/1');
$this->assertResponseStatus(200);
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
* @covers FireflyIII\Http\Controllers\AccountController::store
2016-02-04 00:30:48 -06:00
* @covers FireflyIII\Http\Requests\AccountFormRequest::authorize
* @covers FireflyIII\Http\Requests\AccountFormRequest::rules
*
2016-01-19 09:55:53 -06:00
*/
2016-01-19 06:53:55 -06:00
public function testStore()
{
2016-01-19 07:37:44 -06:00
$this->be($this->user());
$this->session(['accounts.create.url' => 'http://localhost']);
$args = [
'name' => 'Some kind of test account.',
'what' => 'asset',
'amount_currency_id_virtualBalance' => 1,
'amount_currency_id_openingBalance' => 1,
];
2016-01-24 11:11:57 -06:00
$this->call('POST', '/accounts/store', $args);
$this->assertResponseStatus(302);
2016-01-19 07:37:44 -06:00
$this->assertSessionHas('success');
2016-01-19 06:53:55 -06:00
}
2016-01-19 09:55:53 -06:00
/**
* @covers FireflyIII\Http\Controllers\AccountController::update
2016-02-04 00:30:48 -06:00
* @covers FireflyIII\Http\Requests\AccountFormRequest::authorize
* @covers FireflyIII\Http\Requests\AccountFormRequest::rules
2016-01-19 09:55:53 -06:00
*/
2016-01-19 06:53:55 -06:00
public function testUpdate()
{
2016-01-20 02:31:24 -06:00
$this->session(['accounts.edit.url' => 'http://localhost']);
$args = [
'id' => 1,
'name' => 'TestData new name',
'active' => 1,
];
$this->be($this->user());
2016-01-24 11:11:57 -06:00
$this->call('POST', '/accounts/update/1', $args);
$this->assertResponseStatus(302);
2016-01-20 02:31:24 -06:00
$this->assertSessionHas('success');
2016-01-19 06:53:55 -06:00
}
}