mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Expand test coverage.
This commit is contained in:
@@ -26,6 +26,7 @@ use Carbon\Carbon;
|
||||
use FireflyIII\Helpers\Collector\JournalCollectorInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\Preference;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
@@ -35,6 +36,7 @@ use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use Illuminate\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use Steam;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -347,6 +349,9 @@ class AccountControllerTest extends TestCase
|
||||
$repository->shouldReceive('store')->once()->andReturn(factory(Account::class)->make());
|
||||
$journalRepos->shouldReceive('first')->once()->andReturn(new TransactionJournal);
|
||||
|
||||
// change the preference:
|
||||
Preferences::setForUser($this->user(), 'frontPageAccounts', [1]);
|
||||
|
||||
$this->session(['accounts.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$data = [
|
||||
|
235
tests/Feature/Controllers/Admin/LinkControllerTest.php
Normal file
235
tests/Feature/Controllers/Admin/LinkControllerTest.php
Normal file
@@ -0,0 +1,235 @@
|
||||
<?php
|
||||
/**
|
||||
* LinkControllerTest.php
|
||||
* Copyright (c) 2017 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Feature\Controllers;
|
||||
|
||||
use FireflyIII\Models\LinkType;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class LinkControllerTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.TooManyPublicMethods)
|
||||
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class LinkControllerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::__construct
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::create
|
||||
*/
|
||||
public function testCreate()
|
||||
{
|
||||
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.create'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::delete
|
||||
*/
|
||||
public function testDeleteEditable()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello', 'outward' => 'bye', 'name' => 'Test type']);
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::delete
|
||||
*/
|
||||
public function testDeleteNonEditable()
|
||||
{
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.delete', [$linkType->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::destroy
|
||||
*/
|
||||
public function testDestroy()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hellox', 'outward' => 'byex', 'name' => 'Test typeX']);
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$this->be($this->user());
|
||||
$this->session(['link_types.delete.uri' => 'http://localhost']);
|
||||
$response = $this->post(route('admin.links.destroy', [$linkType->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::edit
|
||||
*/
|
||||
public function testEditEditable()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
LinkType::create(['editable' => 1, 'inward' => 'hello Y', 'outward' => 'bye Y', 'name' => 'Test type Y']);
|
||||
|
||||
$linkType = LinkType::where('editable', 1)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.edit', [$linkType->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::edit
|
||||
*/
|
||||
public function testEditNonEditable()
|
||||
{
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.edit', [$linkType->id]));
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::index
|
||||
*/
|
||||
public function testIndex()
|
||||
{
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.index'));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::show
|
||||
*/
|
||||
public function testShow()
|
||||
{
|
||||
$linkType = LinkType::first();
|
||||
$this->be($this->user());
|
||||
$response = $this->get(route('admin.links.show', [$linkType->id]));
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::store
|
||||
*/
|
||||
public function testStore()
|
||||
{
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
];
|
||||
$this->session(['link_types.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::store
|
||||
*/
|
||||
public function testStoreRedirect()
|
||||
{
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
'create_another' => '1',
|
||||
];
|
||||
$this->session(['link_types.create.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.store'), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::update
|
||||
*/
|
||||
public function testUpdate()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
$linKType = LinkType::create(['editable' => 1, 'inward' => 'helloxz', 'outward' => 'bzyex', 'name' => 'Test tyzpeX']);
|
||||
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.update', [$linKType->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::update
|
||||
*/
|
||||
public function testUpdateNonEditable()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
$linkType = LinkType::where('editable', 0)->first();
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.update', [$linkType->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('error');
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Http\Controllers\Admin\LinkController::update
|
||||
*/
|
||||
public function testUpdateRedirect()
|
||||
{
|
||||
// create editable link type just in case:
|
||||
$linkType = LinkType::create(['editable' => 1, 'inward' => 'healox', 'outward' => 'byaex', 'name' => 'Test tyapeX']);
|
||||
|
||||
$data = [
|
||||
'name' => 'test ' . rand(1, 1000),
|
||||
'inward' => 'test inward' . rand(1, 1000),
|
||||
'outward' => 'test outward' . rand(1, 1000),
|
||||
'return_to_edit' => '1',
|
||||
];
|
||||
$this->session(['link_types.edit.uri' => 'http://localhost']);
|
||||
$this->be($this->user());
|
||||
$response = $this->post(route('admin.links.update', [$linkType->id]), $data);
|
||||
$response->assertStatus(302);
|
||||
$response->assertSessionHas('success');
|
||||
}
|
||||
}
|
@@ -65,8 +65,8 @@ class AttachmentHelperTest extends TestCase
|
||||
{
|
||||
$journal = TransactionJournal::first();
|
||||
$helper = new AttachmentHelper;
|
||||
$path = resource_path('stubs/csv.csv');
|
||||
$file = new UploadedFile($path, 'csv.csv', 'text/plain', filesize($path), null, true);
|
||||
$path = resource_path('stubs/binary.bin');
|
||||
$file = new UploadedFile($path, 'binary.bin', 'application/octet-stream', filesize($path), null, true);
|
||||
|
||||
$helper->saveAttachmentsForModel($journal, [$file]);
|
||||
$errors = $helper->getErrors();
|
||||
@@ -74,7 +74,7 @@ class AttachmentHelperTest extends TestCase
|
||||
|
||||
$this->assertCount(1, $errors);
|
||||
$this->assertCount(0, $messages);
|
||||
$this->assertEquals('File "csv.csv" is of type "text/plain" which is not accepted as a new upload.', $errors->first());
|
||||
$this->assertEquals('File "binary.bin" is of type "application/octet-stream" which is not accepted as a new upload.', $errors->first());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user