mirror of
				https://github.com/firefly-iii/firefly-iii.git
				synced 2025-10-31 18:54:58 +00:00 
			
		
		
		
	Some tests fixed. But messy! [skip ci]
This commit is contained in:
		| @@ -31,11 +31,17 @@ class BudgetTest extends TestCase | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public function tearDown() | ||||
|     { | ||||
|         Mockery::close(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \Budget | ||||
|      * | ||||
|      */ | ||||
|     public function testBudgetModel() { | ||||
|     public function testBudgetModel() | ||||
|     { | ||||
|         // create budget: | ||||
|         $budget = f::create('Budget'); | ||||
|  | ||||
| @@ -51,12 +57,9 @@ class BudgetTest extends TestCase | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public function tearDown() | ||||
|     { | ||||
|         Mockery::close(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::create | ||||
|      */ | ||||
|     public function testCreate() | ||||
|     { | ||||
|         // test config: | ||||
| @@ -78,7 +81,9 @@ class BudgetTest extends TestCase | ||||
|  | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::delete | ||||
|      */ | ||||
|     public function testDelete() | ||||
|     { | ||||
|  | ||||
| @@ -99,6 +104,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::destroy | ||||
|      */ | ||||
|     public function testDestroy() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -121,6 +129,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::destroy | ||||
|      */ | ||||
|     public function testDestroyFromDate() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -143,7 +154,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::edit | ||||
|      */ | ||||
|     public function testEdit() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -164,6 +177,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::indexByBudget | ||||
|      */ | ||||
|     public function testIndexByBudget() | ||||
|     { | ||||
|         $this->_repository->shouldReceive('get')->once()->andReturn([]); | ||||
| @@ -179,6 +195,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::indexByDate | ||||
|      */ | ||||
|     public function testIndexByDate() | ||||
|     { | ||||
|         $collection = new Collection(); | ||||
| @@ -196,6 +215,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::show | ||||
|      */ | ||||
|     public function testShowDefault() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -222,6 +244,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::show | ||||
|      */ | ||||
|     public function testShowOutsideEnvelope() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -250,6 +275,10 @@ class BudgetTest extends TestCase | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::show | ||||
|      */ | ||||
|     public function testShowWithRepetition() | ||||
|     { | ||||
|         $budget     = f::create('Budget'); | ||||
| @@ -285,6 +314,9 @@ class BudgetTest extends TestCase | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::store | ||||
|      */ | ||||
|     public function testStore() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -300,6 +332,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::store | ||||
|      */ | ||||
|     public function testStoreComingFromDate() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -315,6 +350,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::store | ||||
|      */ | ||||
|     public function testStoreFails() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -329,6 +367,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertSessionHas('error'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::store | ||||
|      */ | ||||
|     public function testStoreWithRecreation() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -344,6 +385,9 @@ class BudgetTest extends TestCase | ||||
|         $this->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::update | ||||
|      */ | ||||
|     public function testUpdate() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -366,6 +410,9 @@ class BudgetTest extends TestCase | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::update | ||||
|      */ | ||||
|     public function testUpdateFails() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
| @@ -386,6 +433,9 @@ class BudgetTest extends TestCase | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \BudgetController::update | ||||
|      */ | ||||
|     public function testUpdateFromDate() | ||||
|     { | ||||
|         $budget = f::create('Budget'); | ||||
|   | ||||
| @@ -17,6 +17,9 @@ class CategoryTest extends TestCase | ||||
|     protected $_user; | ||||
|     protected $_category; | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|     public function setUp() | ||||
|     { | ||||
|         parent::setUp(); | ||||
| @@ -28,62 +31,100 @@ class CategoryTest extends TestCase | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * | ||||
|      */ | ||||
|     public function tearDown() | ||||
|     { | ||||
|         Mockery::close(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     /** | ||||
|      * @covers \CategoryController::create | ||||
|      */ | ||||
|     public function testCreate() | ||||
|     { | ||||
|         // test the view: | ||||
|         View::shouldReceive('make')->with('categories.create')->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('title', 'Create a new category')->once(); | ||||
|  | ||||
|         $this->action('GET', 'CategoryController@create'); | ||||
|         $this->assertResponseOk(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \CategoryController::delete | ||||
|      */ | ||||
|     public function testDelete() | ||||
|     { | ||||
|  | ||||
|         $category = f::create('Category'); | ||||
|  | ||||
|         // for successful binding: | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user); | ||||
|         Auth::shouldReceive('check')->andReturn(true); | ||||
|         // test the view: | ||||
|         View::shouldReceive('make')->with('categories.delete')->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('category', m::any())->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('title', 'Delete category "' . $category->name . '"')->once(); | ||||
|  | ||||
|         // for successful binding with the category to delete: | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3); | ||||
|         Auth::shouldReceive('check')->andReturn(true)->between(1, 2); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email'); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); | ||||
|  | ||||
|         $this->action('GET', 'CategoryController@delete', $category->id); | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \CategoryController::destroy | ||||
|      */ | ||||
|     public function testDestroy() | ||||
|     { | ||||
|         $category = f::create('Category'); | ||||
|  | ||||
|         // for successful binding: | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user); | ||||
|         Auth::shouldReceive('check')->andReturn(true); | ||||
|         // for successful binding with the category to delete: | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3); | ||||
|         Auth::shouldReceive('check')->andReturn(true)->between(1, 2); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); | ||||
|  | ||||
|         // fire the repository: | ||||
|         $this->_repository->shouldReceive('destroy')->once()->andReturn(true); | ||||
|  | ||||
|         // fire and test: | ||||
|         $this->action('POST', 'CategoryController@destroy', $category->id); | ||||
|         $this->assertRedirectedToRoute('categories.index'); | ||||
|         $this->assertSessionHas('success'); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \CategoryController::edit | ||||
|      */ | ||||
|     public function testEdit() | ||||
|     { | ||||
|         $category = f::create('Category'); | ||||
|  | ||||
|         // for successful binding. | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user); | ||||
|         Auth::shouldReceive('check')->andReturn(true); | ||||
|         // for successful binding with the category to edit: | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3); | ||||
|         Auth::shouldReceive('check')->andReturn(true)->between(1, 2); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn('some@email'); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); // | ||||
|  | ||||
|         // test the view: | ||||
|         View::shouldReceive('make')->with('categories.edit')->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('category', m::any())->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('title', 'Edit category "' . $category->name . '"')->once(); | ||||
|  | ||||
|  | ||||
|         $this->action('GET', 'CategoryController@edit', $category->id); | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \CategoryController::index | ||||
|      */ | ||||
|     public function testIndex() | ||||
|     { | ||||
|         $category   = f::create('Category'); | ||||
| @@ -91,19 +132,30 @@ class CategoryTest extends TestCase | ||||
|         $collection->add($category); | ||||
|  | ||||
|         $this->_repository->shouldReceive('get')->with()->once()->andReturn($collection); | ||||
|  | ||||
|         View::shouldReceive('make')->with('categories.index')->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('categories', $collection)->once()->andReturn(m::self()) | ||||
|             ->shouldReceive('with')->with('title', 'All your categories')->once(); | ||||
|  | ||||
|  | ||||
|  | ||||
|         $this->action('GET', 'CategoryController@index'); | ||||
|         $this->assertResponseOk(); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @covers \CategoryController::show | ||||
|      */ | ||||
|     public function testShow() | ||||
|     { | ||||
|         $category = f::create('Category'); | ||||
|  | ||||
|         // for successful binding. | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user); | ||||
|         Auth::shouldReceive('check')->andReturn(true); | ||||
|         // for successful binding with the category to show: | ||||
|         Auth::shouldReceive('user')->andReturn($this->_user)->between(1, 3); | ||||
|         Auth::shouldReceive('check')->andReturn(true)->between(1, 2); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('id')->once()->andReturn($category->user_id); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->once()->andReturn($category->email); | ||||
|         $this->_user->shouldReceive('getAttribute')->with('email')->andReturn('some@email'); // | ||||
|  | ||||
|         $this->session(['start' => new Carbon, 'end' => new Carbon]); | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user