mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-09 12:01:28 +00:00
Refactored a lot of tests.
This commit is contained in:
@@ -30,6 +30,7 @@ use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Log;
|
||||
use Mockery;
|
||||
use Preferences;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -55,19 +56,19 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testDelete(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// data
|
||||
$attachment = $this->getRandomAttachment();
|
||||
|
||||
return;
|
||||
// mock stuff
|
||||
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.delete', [1]));
|
||||
$response = $this->get(route('attachments.delete', [$attachment->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
@@ -78,17 +79,17 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testDestroy(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$attachment = $this->getRandomAttachment();
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$repository->shouldReceive('destroy')->andReturn(true);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->session(['attachments.delete.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('attachments.destroy', [1]));
|
||||
$response = $this->post(route('attachments.destroy', [$attachment->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
@@ -98,17 +99,16 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testDownload(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$attachment = $this->getRandomAttachment();
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('exists')->once()->andReturn(true);
|
||||
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.download', [1]));
|
||||
$response = $this->get(route('attachments.download', [$attachment->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('This is attachment number one.');
|
||||
@@ -119,16 +119,18 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testDownloadFail(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
|
||||
// mock stuff
|
||||
$attachment = $this->getRandomAttachment();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('exists')->once()->andReturn(false);
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.download', [1]));
|
||||
$response = $this->get(route('attachments.download', [$attachment->id]));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
|
||||
@@ -137,19 +139,15 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testEdit(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
|
||||
return;
|
||||
$this->mockDefaultSession();
|
||||
$attachRepository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$attachment = $this->getRandomAttachment();
|
||||
$userRepos->shouldReceive('hasRole')->withArgs([Mockery::any(), 'owner'])->andReturn(true)->atLeast()->once();
|
||||
|
||||
$attachRepository->shouldReceive('getNoteText')->andReturn('OK');
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.edit', [1]));
|
||||
$response = $this->get(route('attachments.edit', [$attachment->id]));
|
||||
$response->assertStatus(200);
|
||||
// has bread crumb
|
||||
$response->assertSee('<ol class="breadcrumb">');
|
||||
@@ -160,6 +158,7 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
@@ -180,13 +179,13 @@ class AttachmentControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate(): void
|
||||
{
|
||||
$this->mockDefaultSession();
|
||||
// mock stuff
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$attachment = $this->getRandomAttachment();
|
||||
$repository->shouldReceive('update')->once();
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
Preferences::shouldReceive('mark')->atLeast()->once();
|
||||
|
||||
$this->session(['attachments.edit.uri' => 'http://localhost']);
|
||||
$data = [
|
||||
@@ -196,50 +195,44 @@ class AttachmentControllerTest extends TestCase
|
||||
];
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('attachments.update', [1]), $data);
|
||||
$response = $this->post(route('attachments.update', [$attachment->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AttachmentController
|
||||
* @covers \FireflyIII\Http\Controllers\AttachmentController
|
||||
*/
|
||||
public function testView(): void
|
||||
{
|
||||
$this->markTestIncomplete('Needs to be rewritten for v4.8.0');
|
||||
$attachment = $this->getRandomAttachment();
|
||||
$this->mockDefaultSession();
|
||||
|
||||
return;
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$repository->shouldReceive('exists')->once()->andReturn(true);
|
||||
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
|
||||
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.view', [3]));
|
||||
$response = $this->get(route('attachments.view', [$attachment->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\AttachmentController
|
||||
* @covers \FireflyIII\Http\Controllers\AttachmentController
|
||||
*/
|
||||
public function testViewFail(): void
|
||||
{
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$userRepos = $this->mock(UserRepositoryInterface::class);
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
$this->mockDefaultSession();
|
||||
$repository = $this->mock(AttachmentRepositoryInterface::class);
|
||||
$attachment = $this->getRandomAttachment();
|
||||
|
||||
$repository->shouldReceive('exists')->once()->andReturn(false);
|
||||
|
||||
|
||||
$journalRepos->shouldReceive('firstNull')->once()->andReturn(new TransactionJournal);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('attachments.view', [1]));
|
||||
$response = $this->get(route('attachments.view', [$attachment->id]));
|
||||
$response->assertStatus(500);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user