mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-11-17 07:08:19 +00:00
Expand tests.
This commit is contained in:
@@ -23,6 +23,8 @@ declare(strict_types=1);
|
||||
namespace Tests\Feature\Controllers\Admin;
|
||||
|
||||
use FireflyIII\Models\LinkType;
|
||||
use FireflyIII\Repositories\LinkType\LinkTypeRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
@@ -51,10 +53,13 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testDeleteEditable()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$repository->shouldReceive('get')->once()->andReturn(new Collection([$linkType]));
|
||||
$repository->shouldReceive('countJournals')->andReturn(2);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||
$response->assertStatus(200);
|
||||
@@ -65,7 +70,8 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testDeleteNonEditable()
|
||||
{
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||
$response->assertStatus(302);
|
||||
@@ -77,10 +83,14 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$repository->shouldReceive('find')->andReturn($linkType);
|
||||
$repository->shouldReceive('destroy');
|
||||
$this->be($this->user());
|
||||
$this->session(['link_types.delete.uri' => 'http://localhost']);
|
||||
$response = $this->post(route('admin.links.destroy', [$linkType->id]));
|
||||
@@ -119,6 +129,8 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$repository->shouldReceive('get')->andReturn(new Collection);
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.index'));
|
||||
$response->assertStatus(200);
|
||||
@@ -140,11 +152,15 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
$data = [
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
];
|
||||
$repository->shouldReceive('store')->once()->andReturn(LinkType::first());
|
||||
$repository->shouldReceive('find')->andReturn(LinkType::first());
|
||||
|
||||
$this->session(['link_types.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.store'), $data);
|
||||
@@ -157,12 +173,14 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testStoreRedirect()
|
||||
{
|
||||
$data = [
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
'create_another' => '1',
|
||||
];
|
||||
$repository->shouldReceive('store')->once()->andReturn(new LinkType);
|
||||
$this->session(['link_types.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.store'), $data);
|
||||
@@ -175,9 +193,11 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
$linKType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
|
||||
// create editable link type just in case:
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
@@ -186,7 +206,7 @@ class LinkControllerTest extends TestCase
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.update', [$linKType->id]), $data);
|
||||
$response = $this->post(route('admin.links.update', [$linkType->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
@@ -196,7 +216,7 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateNonEditable()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
|
||||
$data = [
|
||||
@@ -217,6 +237,7 @@ class LinkControllerTest extends TestCase
|
||||
*/
|
||||
public function testUpdateRedirect()
|
||||
{
|
||||
$repository = $this->mock(LinkTypeRepositoryInterface::class);
|
||||
// create editable link type just in case:
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
|
||||
|
||||
@@ -226,6 +247,7 @@ class LinkControllerTest extends TestCase
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$repository->shouldReceive('update')->once()->andReturn(new $linkType);
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.update', [$linkType->id]), $data);
|
||||
|
||||
Reference in New Issue
Block a user