mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fixed budget controller tests.
This commit is contained in:
parent
e57ce6e644
commit
ed8e392616
@ -1,19 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class ExampleTest
|
|
||||||
*/
|
|
||||||
class ExampleTest extends TestCase
|
|
||||||
{
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A basic functional test example.
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function testBasicExample()
|
|
||||||
{
|
|
||||||
$this->assertTrue(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -165,18 +165,147 @@ class BudgetControllerTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testShowInvalidRepetition()
|
||||||
|
{
|
||||||
|
|
||||||
|
$repetition = FactoryMuffin::create('FireflyIII\Models\LimitRepetition');
|
||||||
|
$budget = $repetition->budgetLimit->budget;
|
||||||
|
$otherBudget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
|
$otherBudget->user_id = $budget->user_id;
|
||||||
|
$otherBudget->save();
|
||||||
|
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$this->be($otherBudget->user);
|
||||||
|
|
||||||
|
Amount::shouldReceive('getCurrencyCode')->andReturn('x');
|
||||||
|
Amount::shouldReceive('format')->andReturn('x');
|
||||||
|
$repository->shouldReceive('getJournals')->andReturn(new Collection);
|
||||||
|
$repository->shouldReceive('getBudgetLimits')->andReturn(new Collection);
|
||||||
|
|
||||||
|
|
||||||
|
$this->call('GET', '/budgets/show/' . $otherBudget->id . '/' . $repetition->id);
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertViewHas('message', 'Invalid selection.');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public function testStore()
|
public function testStore()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
// a budget:
|
||||||
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
|
$this->be($budget->user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => 'New test budget ' . rand(1, 1000),
|
||||||
|
'_token' => 'replaceme'
|
||||||
|
];
|
||||||
|
|
||||||
|
// fake validation routine:
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
|
// fake store routine:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$repository->shouldReceive('store')->andReturn($budget);
|
||||||
|
|
||||||
|
$this->call('POST', '/budgets/store', $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertSessionHas('success');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testStoreAndRedirect()
|
||||||
|
{
|
||||||
|
// a budget:
|
||||||
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
|
$this->be($budget->user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => 'New test budget ' . rand(1, 1000),
|
||||||
|
'_token' => 'replaceme',
|
||||||
|
'create_another' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
// fake validation routine:
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
|
// fake store routine:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$repository->shouldReceive('store')->andReturn($budget);
|
||||||
|
|
||||||
|
$this->call('POST', '/budgets/store', $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertSessionHas('success');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
|
||||||
|
// a budget:
|
||||||
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
|
$this->be($budget->user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => 'Edited test account ' . rand(1, 1000),
|
||||||
|
'active' => 1,
|
||||||
|
'_token' => 'replaceme'
|
||||||
|
];
|
||||||
|
|
||||||
|
// fake validation routine:
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
|
// fake update routine:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$repository->shouldReceive('update')->andReturn($budget);
|
||||||
|
|
||||||
|
$this->call('POST', '/budgets/update/' . $budget->id, $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertSessionHas('success');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpdateAndRedirect()
|
||||||
|
{
|
||||||
|
|
||||||
|
// a budget:
|
||||||
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
|
$this->be($budget->user);
|
||||||
|
|
||||||
|
$data = [
|
||||||
|
'name' => 'Edited test account ' . rand(1, 1000),
|
||||||
|
'active' => 1,
|
||||||
|
'_token' => 'replaceme',
|
||||||
|
'return_to_edit' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
// fake validation routine:
|
||||||
|
$request = $this->mock('FireflyIII\Http\Requests\BudgetFormRequest');
|
||||||
|
$request->shouldReceive('input')->andReturn('');
|
||||||
|
|
||||||
|
// fake update routine:
|
||||||
|
$repository = $this->mock('FireflyIII\Repositories\Budget\BudgetRepositoryInterface');
|
||||||
|
$repository->shouldReceive('update')->andReturn($budget);
|
||||||
|
|
||||||
|
$this->call('POST', '/budgets/update/' . $budget->id, $data);
|
||||||
|
$this->assertResponseStatus(302);
|
||||||
|
$this->assertSessionHas('success');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUpdateIncome()
|
public function testUpdateIncome()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
|
||||||
|
// a budget:
|
||||||
|
$budget = FactoryMuffin::create('FireflyIII\Models\Budget');
|
||||||
|
$this->be($budget->user);
|
||||||
|
$date = Carbon::now()->format('FY');
|
||||||
|
$pref = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['budgetIncomeTotal' . $date, 1000])->andReturn($pref);
|
||||||
|
Amount::shouldReceive('format')->andReturn('xx');
|
||||||
|
|
||||||
|
$this->call('GET', '/budgets/income');
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertViewHas('amount');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -41,7 +41,7 @@ FactoryMuffin::define(
|
|||||||
FactoryMuffin::define(
|
FactoryMuffin::define(
|
||||||
'FireflyIII\Models\Budget', [
|
'FireflyIII\Models\Budget', [
|
||||||
'user_id' => 'factory|FireflyIII\User',
|
'user_id' => 'factory|FireflyIII\User',
|
||||||
'name' => 'word',
|
'name' => 'sentence',
|
||||||
'active' => 'boolean',
|
'active' => 'boolean',
|
||||||
'encrypted' => 1,
|
'encrypted' => 1,
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user