be($this->user());
$this->call('GET', route('categories.create'));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('
');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::delete
*/
public function testDelete()
{
$this->be($this->user());
$this->call('GET', route('categories.delete', [1]));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::destroy
*/
public function testDestroy()
{
$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');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::edit
*/
public function testEdit()
{
$this->be($this->user());
$this->call('GET', route('categories.edit', [1]));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::index
*/
public function testIndex()
{
$this->be($this->user());
$this->call('GET', route('categories.index'));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::noCategory
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testNoCategory(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('categories.no-category'));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShow(string $range)
{
$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();
$collector->shouldReceive('withBudgetInformation')->andReturnSelf()->once();
$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');
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('categories.show', [1]));
$this->assertResponseStatus(200);
$this->see('');
}
/**
* @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('');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowByDate(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('setRange')->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.date', [1, '2015-01-01']));
$this->assertResponseStatus(200);
$this->see('');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::store
*/
public function testStore()
{
$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('');
$this->see($data['name']);
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::update
*/
public function testUpdate()
{
$this->session(['categories.edit.url' => 'http://localhost']);
$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('');
$this->see($data['name']);
}
}