be($category->user); $this->call('GET', '/categories/create'); $this->assertResponseOk(); $this->assertViewHas('subTitle', 'Create a new category'); } public function testDelete() { $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); $this->call('GET', '/categories/delete/' . $category->id); $this->assertResponseOk(); $this->assertViewHas('subTitle', 'Delete category "' . e($category->name) . '"'); } public function testDestroy() { $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $repository->shouldReceive('destroy'); $this->call('POST', '/categories/destroy/' . $category->id, ['_token' => 'replaceMe']); $this->assertResponseStatus(302); $this->assertSessionHas('success', 'The category "' . e($category->name) . '" was deleted.'); } public function testEdit() { $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); $this->call('GET', '/categories/edit/' . $category->id); $this->assertResponseOk(); $this->assertViewHas('subTitle', 'Edit category "' . e($category->name) . '"'); } public function testIndex() { $collection = new Collection; $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); $collection->push($category); Amount::shouldReceive('getCurrencyCode')->andReturn('xx'); $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $repository->shouldReceive('getCategories')->andReturn($collection); $repository->shouldReceive('getLatestActivity')->andReturn(new Carbon); $this->call('GET', '/categories'); $this->assertResponseOk(); $this->assertViewHas('categories'); } public function testNoCategory() { $collection = new Collection; $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $this->be($journal->user); $collection->push($journal); Amount::shouldReceive('format')->andReturn('xx'); Amount::shouldReceive('getCurrencyCode')->andReturn('xx'); $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $repository->shouldReceive('getWithoutCategory')->andReturn($repository); $this->call('GET', '/categories/list/noCategory'); $this->assertResponseOk(); $this->assertViewHas('subTitle'); } public function testShow() { $category = FactoryMuffin::create('FireflyIII\Models\Category'); $collection = new Collection; $journal = FactoryMuffin::create('FireflyIII\Models\TransactionJournal'); $this->be($category->user); $collection->push($journal); $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $repository->shouldReceive('getJournals')->andReturn($collection); $repository->shouldReceive('countJournals')->andReturn(1); Amount::shouldReceive('format')->andReturn('xx'); Amount::shouldReceive('getCurrencyCode')->andReturn('xx'); $this->call('GET', '/categories/show/' . $category->id); $this->assertResponseOk(); $this->assertViewHas('hideCategory', true); } public function testStore() { // create $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); // mock $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest'); // expect $repository->shouldReceive('store')->andReturn($category); $request->shouldReceive('input')->andReturn(''); $this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]); $this->assertResponseStatus(302); $this->assertSessionHas('success', 'New category "' . $category->name . '" stored!'); } // public function testStoreAndRedirect() { // create $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); // mock: $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest'); // fake: $repository->shouldReceive('store')->andReturn($category); $request->shouldReceive('input')->andReturn(''); $this->call('POST', '/categories/store', ['_token' => 'replaceMe', 'create_another' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]); $this->assertResponseStatus(302); $this->assertSessionHas('success', 'New category "' . $category->name . '" stored!'); } public function testUpdate() { // create $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); // mock $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest'); // expect $repository->shouldReceive('update')->andReturn($category); $request->shouldReceive('input')->andReturn(''); $this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'name' => 'Bla bla #' . rand(1, 1000)]); $this->assertResponseStatus(302); $this->assertSessionHas('success', 'Category "' . $category->name . '" updated.'); } public function testUpdateAndRedirect() { // create $category = FactoryMuffin::create('FireflyIII\Models\Category'); $this->be($category->user); // mock $repository = $this->mock('FireflyIII\Repositories\Category\CategoryRepositoryInterface'); $request = $this->mock('FireflyIII\Http\Requests\CategoryFormRequest'); // expect $request->shouldReceive('input')->andReturn(''); $repository->shouldReceive('update')->andReturn($category); $this->call('POST', '/categories/update/' . $category->id, ['_token' => 'replaceMe', 'return_to_edit' => 1, 'name' => 'Bla bla #' . rand(1, 1000)]); $this->assertResponseStatus(302); $this->assertSessionHas('success', 'Category "' . $category->name . '" updated.'); } }