Files
firefly-iii/tests/acceptance/Controllers/CategoryControllerTest.php
2016-12-15 17:16:46 +01:00

187 lines
5.4 KiB
PHP

<?php
/**
* 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.
*/
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:40.
*/
class CategoryControllerTest 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\CategoryController::create
*/
public function testCreate()
{
$this->be($this->user());
$this->call('GET', route('categories.create'));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @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('<ol class="breadcrumb">');
}
/**
* @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('<ol class="breadcrumb">');
}
/**
* @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('<ol class="breadcrumb">');
}
/**
* @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('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::show
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShow(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('categories.show', [1]));
$this->assertResponseStatus(200);
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\CategoryController::showByDate
* @dataProvider dateRangeProvider
*
* @param string $range
*/
public function testShowByDate(string $range)
{
$this->be($this->user());
$this->changeDateRange($this->user(), $range);
$this->call('GET', route('categories.show', [1, '2015-01-01']));
$this->assertResponseStatus(200);
$this->see('<ol class="breadcrumb">');
}
/**
* @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('<ol class="breadcrumb">');
$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('<ol class="breadcrumb">');
$this->see($data['name']);
}
}