mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Coverage should be back at 100%. Fixed some formatting too.
This commit is contained in:
@@ -32,6 +32,38 @@ class PiggybankControllerTest extends TestCase
|
||||
m::close();
|
||||
}
|
||||
|
||||
public function testAddMoneyGET()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(1);
|
||||
|
||||
$this->action('GET', 'PiggybankController@addMoney', $piggyBank->id);
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testCreatePiggybank()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
$this->action('GET', 'PiggybankController@createPiggybank');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testCreateRepeated()
|
||||
{
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
$this->action('GET', 'PiggybankController@createRepeated');
|
||||
$this->assertResponseOk();
|
||||
|
||||
}
|
||||
|
||||
public function testDelete()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
@@ -86,6 +118,28 @@ class PiggybankControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testEditRepeated()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->repeats = 1;
|
||||
$piggyBank->save();
|
||||
|
||||
|
||||
$this->_accounts->shouldReceive('getActiveDefaultAsSelectList')->once()->andReturn([]);
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email');
|
||||
|
||||
$this->action('GET', 'PiggybankController@edit', $piggyBank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testIndex()
|
||||
{
|
||||
$aOne = f::create('Account');
|
||||
@@ -107,6 +161,208 @@ class PiggybankControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testModifyMoneyAddPOST()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->targetamount = 200;
|
||||
$piggyBank->save();
|
||||
$input = [
|
||||
$piggyBank->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'add'
|
||||
];
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn(
|
||||
$piggyBank->account()->first()->user_id
|
||||
);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
Event::shouldReceive('fire')->with('piggybanks.change');
|
||||
$this->_piggybanks->shouldReceive('modifyAmount')->once();
|
||||
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->once()->andReturn(200);
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
public function testModifyMoneyAddPOSTFails()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->targetamount = 200;
|
||||
$piggyBank->save();
|
||||
$input = [
|
||||
$piggyBank->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'add'
|
||||
];
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($piggyBank->account()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
Event::shouldReceive('fire')->with('piggybanks.change');
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->once()->andReturn(5);
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('warning');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Firefly\Exception\FireflyException
|
||||
*/
|
||||
public function testModifyMoneyPOSTException()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
$piggyBank->targetamount = 200;
|
||||
$piggyBank->save();
|
||||
$input = [
|
||||
$piggyBank->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'yomoma'
|
||||
];
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->andReturn($piggyBank->account()->first()->user_id);
|
||||
$this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email');
|
||||
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('warning');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testModifyMoneyRemovePOST()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->save();
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$rep->piggybank()->first()->account()->first()->user_id
|
||||
);
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(11);
|
||||
$this->_piggybanks->shouldReceive('modifyAmount')->once();
|
||||
|
||||
$input = [
|
||||
$rep->piggybank()->first()->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'remove'
|
||||
];
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('success');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
public function testModifyMoneyRemovePOSTFails()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->currentAmount = 5;
|
||||
$rep->save();
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$rep->piggybank()->first()->account()->first()->user_id
|
||||
);
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
|
||||
$input = [
|
||||
$rep->piggybank()->first()->id,
|
||||
'amount' => 10.0,
|
||||
'what' => 'remove'
|
||||
];
|
||||
|
||||
$this->action('POST', 'PiggybankController@modMoney', $input);
|
||||
$this->assertSessionHas('warning');
|
||||
$this->assertResponseStatus(302);
|
||||
|
||||
}
|
||||
|
||||
public function teststorePiggybank()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storePiggybank');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreRepeated()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storeRepeated');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function teststorePiggybankFails()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
unset($piggy->id);
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storePiggybank');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testStoreRepeatedFails()
|
||||
{
|
||||
$piggy = f::create('Piggybank');
|
||||
unset($piggy->id);
|
||||
$this->_piggybanks->shouldReceive('store')->once()->andReturn($piggy);
|
||||
$this->action('POST', 'PiggybankController@storeRepeated');
|
||||
$this->assertResponseStatus(302);
|
||||
}
|
||||
|
||||
public function testRemoveMoneyGET()
|
||||
{
|
||||
$pig = $this->mock('Piggybank');
|
||||
$piggybank = f::create('Piggybank');
|
||||
$rep = f::create('PiggybankRepetition');
|
||||
$rep->piggybank_id = $piggybank->id;
|
||||
$rep->save();
|
||||
|
||||
|
||||
// for binding
|
||||
Auth::shouldReceive('user')->andReturn($this->_user);
|
||||
Auth::shouldReceive('check')->andReturn(true);
|
||||
$this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn(
|
||||
$rep->piggybank()->first()->account()->first()->user_id
|
||||
);
|
||||
$pig->shouldReceive('currentRelevantRep')->andReturn($rep);
|
||||
|
||||
$this->_piggybanks->shouldReceive('leftOnAccount')->andReturn(1)->once();
|
||||
|
||||
$this->action('GET', 'PiggybankController@removeMoney', $piggybank->id);
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
public function testShow()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
@@ -122,8 +378,6 @@ class PiggybankControllerTest extends TestCase
|
||||
$this->assertResponseOk();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function testUpdate()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
@@ -146,7 +400,7 @@ class PiggybankControllerTest extends TestCase
|
||||
public function testUpdateFails()
|
||||
{
|
||||
$piggyBank = f::create('Piggybank');
|
||||
unset($piggyBank->amount);
|
||||
unset($piggyBank->name);
|
||||
|
||||
$this->_piggybanks->shouldReceive('update')->andReturn($piggyBank);
|
||||
|
||||
@@ -164,6 +418,4 @@ class PiggybankControllerTest extends TestCase
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user