. */ declare(strict_types=1); namespace Tests\Feature\Controllers\Transaction; use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournalLink; use FireflyIII\Repositories\Journal\JournalRepositoryInterface; use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface; use Tests\TestCase; /** * Class LinkControllerTest */ class LinkControllerTest extends TestCase { /** * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::__construct * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::delete */ public function testDelete() { $journalRepos = $this->mock(JournalRepositoryInterface::class); $linkRepos = $this->mock(LinkTypeRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->get(route('transactions.link.delete', [1])); $response->assertStatus(200); } /** * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::destroy */ public function testDestroy() { $journalRepos = $this->mock(JournalRepositoryInterface::class); $repository = $this->mock(LinkTypeRepositoryInterface::class); $repository->shouldReceive('destroyLink'); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $this->session(['journal_links.delete.uri' => 'http://localhost/']); $response = $this->post(route('transactions.link.destroy', [1])); $response->assertStatus(302); $response->assertSessionHas('success'); } /** * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store * @covers \FireflyIII\Http\Requests\JournalLinkRequest */ public function testStore() { $repository = $this->mock(LinkTypeRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $data = [ 'link_other' => 8, 'link_type' => '1_inward', ]; $journalRepos->shouldReceive('first')->andReturn(new TransactionJournal); $journalRepos->shouldReceive('find')->andReturn(new TransactionJournal); $repository->shouldReceive('findLink')->andReturn(false); $repository->shouldReceive('storeLink')->andReturn(new TransactionJournalLink); $this->be($this->user()); $response = $this->post(route('transactions.link.store', [1]), $data); $response->assertStatus(302); $response->assertSessionHas('success'); $response->assertRedirect(route('transactions.show', [1])); } /** * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store * @covers \FireflyIII\Http\Requests\JournalLinkRequest */ public function testStoreAlreadyLinked() { $repository = $this->mock(LinkTypeRepositoryInterface::class); $journalRepos = $this->mock(JournalRepositoryInterface::class); $data = [ 'link_other' => 8, 'link_type' => '1_inward', ]; $journalRepos->shouldReceive('first')->andReturn(new TransactionJournal); $journalRepos->shouldReceive('find')->andReturn(new TransactionJournal); $repository->shouldReceive('findLink')->andReturn(true); $this->be($this->user()); $response = $this->post(route('transactions.link.store', [1]), $data); $response->assertStatus(302); $response->assertSessionHas('error'); $response->assertRedirect(route('transactions.show', [1])); } /** * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::store * @covers \FireflyIII\Http\Requests\JournalLinkRequest */ public function testStoreInvalid() { $journalRepos = $this->mock(JournalRepositoryInterface::class); $linkRepos = $this->mock(LinkTypeRepositoryInterface::class); $data = [ 'link_other' => 0, 'link_type' => '1_inward', ]; $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $this->be($this->user()); $response = $this->post(route('transactions.link.store', [1]), $data); $response->assertStatus(302); $response->assertSessionHas('error'); $response->assertRedirect(route('transactions.show', [1])); } /** * @covers \FireflyIII\Http\Controllers\Transaction\LinkController::switchLink */ public function testSwitchLink() { $journalRepos = $this->mock(JournalRepositoryInterface::class); $repository = $this->mock(LinkTypeRepositoryInterface::class); $journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal); $repository->shouldReceive('switchLink')->andReturn(false); $this->be($this->user()); $response = $this->get(route('transactions.link.switch', [1])); $response->assertStatus(302); } }