2016-11-19 13:30:30 -06:00
|
|
|
<?php
|
2016-12-06 02:16:36 -06:00
|
|
|
/**
|
|
|
|
* CategoryControllerTest.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-18 03:37:59 -06:00
|
|
|
use Carbon\Carbon;
|
|
|
|
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
|
|
|
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
2016-12-11 07:03:30 -06:00
|
|
|
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
|
2016-12-18 03:37:59 -06:00
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
use Illuminate\Support\Collection;
|
2016-11-19 13:30:30 -06:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2016-12-09 23:54:50 -06:00
|
|
|
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:40.
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
class CategoryControllerTest extends TestCase
|
|
|
|
{
|
2016-11-20 00:24:18 -06:00
|
|
|
|
2016-11-19 13:30:30 -06: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 01:30:25 -06:00
|
|
|
parent::setUp();
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::create
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testCreate()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('categories.create'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::delete
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testDelete()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('categories.delete', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::destroy
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testDestroy()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->session(['categories.delete.url' => 'http://localhost']);
|
|
|
|
$repository = $this->mock(CategoryRepositoryInterface::class);
|
|
|
|
$repository->shouldReceive('destroy')->andReturn(true);
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('categories.destroy', [1]));
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::edit
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testEdit()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('categories.edit', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::index
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testIndex()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('categories.index'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-11 07:03:30 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::noCategory
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 10:16:46 -06:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
2016-12-11 07:03:30 -06:00
|
|
|
public function testNoCategory(string $range)
|
2016-11-19 13:30:30 -06:00
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('categories.no-category'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
// has bread crumb
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-11 07:03:30 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::show
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 10:16:46 -06:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
2016-12-11 07:03:30 -06:00
|
|
|
public function testShow(string $range)
|
2016-11-19 13:30:30 -06:00
|
|
|
{
|
2016-12-18 03:37:59 -06:00
|
|
|
|
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
$accRepository = $this->mock(AccountRepositoryInterface::class);
|
|
|
|
$catRepository = $this->mock(CategoryRepositoryInterface::class);
|
|
|
|
|
|
|
|
$accRepository->shouldReceive('getAccountsByType')->once()->andReturn(new Collection);
|
|
|
|
$catRepository->shouldReceive('firstUseDate')->once()->andReturn(new Carbon);
|
|
|
|
|
|
|
|
// collector stuff:
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
2016-12-28 02:56:07 -06:00
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
2016-12-18 03:37:59 -06:00
|
|
|
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
|
|
|
|
|
|
|
// more repos stuff:
|
|
|
|
$catRepository->shouldReceive('spentInPeriod')->andReturn('0');
|
|
|
|
$catRepository->shouldReceive('earnedInPeriod')->andReturn('0');
|
|
|
|
|
|
|
|
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('categories.show', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
2016-12-28 02:56:07 -06:00
|
|
|
/**
|
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::showAll
|
|
|
|
* @dataProvider dateRangeProvider
|
|
|
|
*
|
|
|
|
* @param string $range
|
|
|
|
*/
|
|
|
|
public function testShowAll(string $range)
|
|
|
|
{
|
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
|
|
|
|
// collector stuff:
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
|
|
|
|
|
|
|
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
|
|
|
$this->call('GET', route('categories.show.all', [1]));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
|
|
|
}
|
|
|
|
|
2016-11-19 13:30:30 -06:00
|
|
|
/**
|
2016-12-11 07:03:30 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
|
|
|
|
* @dataProvider dateRangeProvider
|
2016-12-15 10:16:46 -06:00
|
|
|
*
|
|
|
|
* @param string $range
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
2016-12-11 07:03:30 -06:00
|
|
|
public function testShowByDate(string $range)
|
2016-11-19 13:30:30 -06:00
|
|
|
{
|
2016-12-18 03:37:59 -06:00
|
|
|
$collector = $this->mock(JournalCollectorInterface::class);
|
|
|
|
|
|
|
|
// collector stuff:
|
|
|
|
$collector->shouldReceive('setPage')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setLimit')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setAllAssetAccounts')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('setRange')->andReturnSelf()->once();
|
2016-12-28 02:56:07 -06:00
|
|
|
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
|
2016-12-18 03:37:59 -06:00
|
|
|
$collector->shouldReceive('setCategory')->andReturnSelf()->once();
|
|
|
|
$collector->shouldReceive('getPaginatedJournals')->andReturn(new LengthAwarePaginator([], 0, 10))->once();
|
|
|
|
|
|
|
|
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->be($this->user());
|
|
|
|
$this->changeDateRange($this->user(), $range);
|
2016-12-18 12:34:03 -06:00
|
|
|
$this->call('GET', route('categories.show.date', [1, '2015-01-01']));
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::store
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testStore()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->session(['categories.create.url' => 'http://localhost']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'name' => 'New Category ' . rand(1000, 9999),
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('categories.store'), $data);
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
|
|
|
|
|
|
|
// must be in list
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('categories.index'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
|
|
|
$this->see($data['name']);
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-12-07 12:53:41 -06:00
|
|
|
* @covers \FireflyIII\Http\Controllers\CategoryController::update
|
2016-11-19 13:30:30 -06:00
|
|
|
*/
|
|
|
|
public function testUpdate()
|
|
|
|
{
|
2016-12-11 07:03:30 -06:00
|
|
|
$this->session(['categories.edit.url' => 'http://localhost']);
|
2016-11-20 04:43:19 -06:00
|
|
|
|
2016-12-11 07:03:30 -06:00
|
|
|
$data = [
|
|
|
|
'name' => 'Updated Category ' . rand(1000, 9999),
|
|
|
|
'active' => 1,
|
|
|
|
];
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('post', route('categories.update', [1]), $data);
|
|
|
|
$this->assertResponseStatus(302);
|
|
|
|
$this->assertSessionHas('success');
|
|
|
|
|
|
|
|
// must be in list
|
|
|
|
$this->be($this->user());
|
|
|
|
$this->call('GET', route('categories.index'));
|
|
|
|
$this->assertResponseStatus(200);
|
|
|
|
$this->see('<ol class="breadcrumb">');
|
|
|
|
$this->see($data['name']);
|
2016-11-20 04:43:19 -06:00
|
|
|
}
|
2016-12-11 07:03:30 -06:00
|
|
|
|
2016-11-19 13:30:30 -06:00
|
|
|
}
|