firefly-iii/tests/acceptance/Controllers/Transaction/SingleControllerTest.php
2016-12-11 10:38:06 +01:00

143 lines
4.4 KiB
PHP

<?php
/**
* SingleControllerTest.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.
*/
namespace Transaction;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use TestCase;
/**
* Generated by PHPUnit_SkeletonGenerator on 2016-12-10 at 05:51:44.
*/
class SingleControllerTest 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\Transaction\SingleController::create
*/
public function testCreate()
{
$this->be($this->user());
$this->call('get', route('transactions.create', ['withdrawal']));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::delete
*/
public function testDelete()
{
$this->be($this->user());
$this->call('get', route('transactions.delete', [12]));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::destroy
*/
public function testDestroy()
{
$this->session(['transactions.delete.url' => 'http://localhost']);
$this->be($this->user());
$repository = $this->mock(JournalRepositoryInterface::class);
$repository->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$repository->shouldReceive('delete')->once();
$this->call('post', route('transactions.destroy', [13]));
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::edit
*/
public function testEdit()
{
$this->be($this->user());
$this->call('get', route('transactions.edit', [13]));
$this->assertResponseStatus(200);
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::store
*/
public function testStore()
{
$this->session(['transactions.create.url' => 'http://localhost']);
$this->be($this->user());
$data = [
'what' => 'withdrawal',
'amount' => 10,
'amount_currency_id_amount' => 1,
'source_account_id' => 1,
'destination_account_name' => 'Some destination',
'date' => '2016-01-01',
'description' => 'Some description',
];
$this->call('post', route('transactions.store', ['withdrawal']), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
}
/**
* @covers \FireflyIII\Http\Controllers\Transaction\SingleController::update
*/
public function testUpdate()
{
$this->session(['transactions.edit.url' => 'http://localhost']);
$this->be($this->user());
$data = [
'id' => 123,
'what' => 'withdrawal',
'description' => 'Updated groceries',
'source_account_id' => 1,
'destination_account_name' => 'PLUS',
'amount' => 123,
'amount_currency_id_amount' => 1,
'budget_id' => 1,
'category' => 'Daily groceries',
'tags' => '',
'date' => '2016-01-01',
];
$this->call('post', route('transactions.update', [123]), $data);
$this->assertResponseStatus(302);
$this->assertSessionHas('success');
$this->call('get', route('transactions.show', [123]));
$this->assertResponseStatus(200);
$this->see('Updated groceries');
// has bread crumb
$this->see('<ol class="breadcrumb">');
}
}