Updated tests

This commit is contained in:
James Cole
2017-03-05 11:18:34 +01:00
parent 884d6c59a2
commit e5a2e1a8c7
8 changed files with 318 additions and 111 deletions

View File

@@ -12,7 +12,9 @@ declare(strict_types = 1);
namespace Tests\Feature\Controllers;
use FireflyIII\Models\TransactionJournal;
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
use Tests\TestCase;
class AttachmentControllerTest extends TestCase
@@ -22,6 +24,8 @@ class AttachmentControllerTest extends TestCase
*/
public function testDelete()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.delete', [1]));
$response->assertStatus(200);
@@ -34,10 +38,13 @@ class AttachmentControllerTest extends TestCase
*/
public function testDestroy()
{
$this->session(['attachments.delete.url' => 'http://localhost']);
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('destroy')->andReturn(true);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['attachments.delete.url' => 'http://localhost']);
$this->be($this->user());
$response = $this->post(route('attachments.destroy', [1]));
$response->assertStatus(302);
@@ -49,9 +56,12 @@ class AttachmentControllerTest extends TestCase
*/
public function testDownload()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('exists')->once()->andReturn(true);
$repository->shouldReceive('getContent')->once()->andReturn('This is attachment number one.');
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.download', [1]));
@@ -65,6 +75,8 @@ class AttachmentControllerTest extends TestCase
*/
public function testEdit()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.edit', [1]));
$response->assertStatus(200);
@@ -78,6 +90,8 @@ class AttachmentControllerTest extends TestCase
*/
public function testPreview()
{
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->be($this->user());
$response = $this->get(route('attachments.preview', [1]));
$response->assertStatus(200);
@@ -88,6 +102,12 @@ class AttachmentControllerTest extends TestCase
*/
public function testUpdate()
{
// mock stuff
$journalRepos = $this->mock(JournalRepositoryInterface::class);
$repository = $this->mock(AttachmentRepositoryInterface::class);
$repository->shouldReceive('update')->once();
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
$this->session(['attachments.edit.url' => 'http://localhost']);
$data = [
'title' => 'Some updated title ' . rand(1000, 9999),
@@ -99,14 +119,6 @@ class AttachmentControllerTest extends TestCase
$response = $this->post(route('attachments.update', [1]), $data);
$response->assertStatus(302);
$response->assertSessionHas('success');
// view should be updated
$this->be($this->user());
$response = $this->get(route('attachments.edit', [1]));
$response->assertStatus(200);
// has bread crumb
$response->assertSee('<ol class="breadcrumb">');
$response->assertSee($data['title']);
}