mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 14:41:20 +00:00
Improve test coverage.
This commit is contained in:
344
tests/Unit/Rules/BelongsUserTest.php
Normal file
344
tests/Unit/Rules/BelongsUserTest.php
Normal file
@@ -0,0 +1,344 @@
|
||||
<?php
|
||||
/**
|
||||
* BelongsUserTest.php
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Rules\BelongsUser;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class BelongsUserTest
|
||||
*/
|
||||
class BelongsUserTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBillId(): void
|
||||
{
|
||||
$attribute = 'bill_id';
|
||||
$bill = $this->getRandomBill();
|
||||
$value = $bill->id;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBillIdFalse(): void
|
||||
{
|
||||
$attribute = 'bill_id';
|
||||
$value = '-1';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBillName(): void
|
||||
{
|
||||
$attribute = 'bill_name';
|
||||
$bill = $this->getRandomBill();
|
||||
$value = $bill->name;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBillNameFalse(): void
|
||||
{
|
||||
$attribute = 'bill_name';
|
||||
$value = 'Some random name';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testAccountIdFalse(): void
|
||||
{
|
||||
$attribute = 'source_id';
|
||||
$value = '-1';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testAccountId(): void
|
||||
{
|
||||
$attribute = 'destination_id';
|
||||
$asset =$this->getRandomAsset();
|
||||
$value = $asset->id;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBudgetId(): void
|
||||
{
|
||||
$attribute = 'budget_id';
|
||||
$budget = $this->getRandomBudget();
|
||||
$value = $budget->id;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBudgetIdFalse(): void
|
||||
{
|
||||
$attribute = 'budget_id';
|
||||
$value = '-1';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBudgetName(): void
|
||||
{
|
||||
$attribute = 'budget_name';
|
||||
$budget = $this->getRandomBudget();
|
||||
$value = $budget->name;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testBudgetNameFalse(): void
|
||||
{
|
||||
$attribute = 'budget_name';
|
||||
$value = 'Some random budget';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testCategoryId(): void
|
||||
{
|
||||
$attribute = 'category_id';
|
||||
$category = $this->getRandomCategory();
|
||||
$value = $category->id;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testCategoryIdFalse(): void
|
||||
{
|
||||
$attribute = 'category_id';
|
||||
$value = '-1';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testPiggyBankId(): void
|
||||
{
|
||||
$attribute = 'piggy_bank_id';
|
||||
$piggyBank = $this->getRandomPiggyBank();
|
||||
$value = $piggyBank->id;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testPiggyBankIdFalse(): void
|
||||
{
|
||||
$attribute = 'piggy_bank_id';
|
||||
$value = '-1';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testPiggyBankIdLongAttribute(): void
|
||||
{
|
||||
$attribute = 'a.b.piggy_bank_id';
|
||||
$piggyBank = $this->getRandomPiggyBank();
|
||||
$value = $piggyBank->id;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testPiggyBankName(): void
|
||||
{
|
||||
$attribute = 'piggy_bank_name';
|
||||
$piggyBank = $this->getRandomPiggyBank();
|
||||
$value = $piggyBank->name;
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\BelongsUser
|
||||
*/
|
||||
public function testPiggyBankNameFalse(): void
|
||||
{
|
||||
$attribute = 'piggy_bank_name';
|
||||
$value = 'Some random name';
|
||||
|
||||
$this->be($this->user());
|
||||
$engine = new BelongsUser;
|
||||
try {
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
} catch (FireflyException $e) {
|
||||
$this->assertTrue(false, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
83
tests/Unit/Rules/IsAssetAccountIdTest.php
Normal file
83
tests/Unit/Rules/IsAssetAccountIdTest.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* IsAssetAccountIdTest.php
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Rules\IsAssetAccountId;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsAssetAccountIdTest
|
||||
*/
|
||||
class IsAssetAccountIdTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsAssetAccountId
|
||||
*/
|
||||
public function testNotAsset(): void
|
||||
{
|
||||
$attribute = 'not-used';
|
||||
$expense = $this->getRandomExpense();
|
||||
$value = $expense->id;
|
||||
|
||||
$engine = new IsAssetAccountId();
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsAssetAccountId
|
||||
*/
|
||||
public function testAsset(): void
|
||||
{
|
||||
$attribute = 'not-used';
|
||||
$asset = $this->getRandomAsset();
|
||||
$value = $asset->id;
|
||||
|
||||
$engine = new IsAssetAccountId();
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsAssetAccountId
|
||||
*/
|
||||
public function testNull(): void
|
||||
{
|
||||
$attribute = 'not-used';
|
||||
$value = '-1';
|
||||
|
||||
$engine = new IsAssetAccountId();
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
}
|
||||
78
tests/Unit/Rules/IsBooleanTest.php
Normal file
78
tests/Unit/Rules/IsBooleanTest.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* IsBooleanTest.php
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Rules\IsBoolean;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsBooleanTest
|
||||
*/
|
||||
class IsBooleanTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsBoolean
|
||||
*/
|
||||
public function testFalse(): void
|
||||
{
|
||||
$attribute = 'not-important';
|
||||
|
||||
$false = ['not', 2, -1, []];
|
||||
|
||||
/** @var mixed $value */
|
||||
foreach ($false as $value) {
|
||||
|
||||
$engine = new IsBoolean();
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsBoolean
|
||||
*/
|
||||
public function testTrue(): void
|
||||
{
|
||||
$attribute = 'not-important';
|
||||
|
||||
$true = [true, false, 0, 1, '0', '1', 'true', 'false', 'yes', 'no', 'on', 'off'];
|
||||
|
||||
/** @var mixed $value */
|
||||
foreach ($true as $value) {
|
||||
|
||||
$engine = new IsBoolean();
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
74
tests/Unit/Rules/IsDateOrTimeTest.php
Normal file
74
tests/Unit/Rules/IsDateOrTimeTest.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* IsDateOrTimeTest.php
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Rules\IsDateOrTime;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsDateOrTimeTest
|
||||
*/
|
||||
class IsDateOrTimeTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsDateOrTime
|
||||
*/
|
||||
public function testFalse(): void
|
||||
{
|
||||
$attribute = 'not-important';
|
||||
$values = ['20xx-01-x','1234567890', '2xx0101', '', false];
|
||||
|
||||
/** @var mixed $value */
|
||||
foreach ($values as $value) {
|
||||
$engine = new IsDateOrTime();
|
||||
$this->assertFalse($engine->passes($attribute, $value), $value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsDateOrTime
|
||||
*/
|
||||
public function testTrue(): void
|
||||
{
|
||||
$attribute = 'not-important';
|
||||
$values = ['2019-01-01', '20190101', '2019-01-01 12:12:12', '12:12:12'];
|
||||
|
||||
/** @var mixed $value */
|
||||
foreach ($values as $value) {
|
||||
$engine = new IsDateOrTime();
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
164
tests/Unit/Rules/IsValidAttachmentModelTest.php
Normal file
164
tests/Unit/Rules/IsValidAttachmentModelTest.php
Normal file
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
/**
|
||||
* IsValidAttachmentModelTest.php
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\ImportJob;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\ImportJob\ImportJobRepositoryInterface;
|
||||
use FireflyIII\Repositories\Journal\JournalRepositoryInterface;
|
||||
use FireflyIII\Rules\IsValidAttachmentModel;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class IsValidAttachmentModelTest
|
||||
*/
|
||||
class IsValidAttachmentModelTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testBillFull(): void
|
||||
{
|
||||
$bill = $this->getRandomBill();
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
|
||||
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('find')->atLeast()->once()->withArgs([$bill->id])->andReturn($bill);
|
||||
|
||||
$value = $bill->id;
|
||||
$attribute = 'not-important';
|
||||
$this->be($this->user());
|
||||
$engine = new IsValidAttachmentModel(Bill::class);
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testImportJob(): void
|
||||
{
|
||||
$job = $this->getRandomImportJob();
|
||||
$jobRepos = $this->mock(ImportJobRepositoryInterface::class);
|
||||
|
||||
$jobRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$jobRepos->shouldReceive('find')->atLeast()->once()->withArgs([$job->id])->andReturn($job);
|
||||
|
||||
$value = $job->id;
|
||||
$attribute = 'not-important';
|
||||
$this->be($this->user());
|
||||
$engine = new IsValidAttachmentModel(ImportJob::class);
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testTransaction(): void
|
||||
{
|
||||
$transaction = $this->getRandomWithdrawal()->transactions()->first();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$journalRepos->shouldReceive('findTransaction')->atLeast()->once()->withArgs([$transaction->id])->andReturn($transaction);
|
||||
|
||||
$value = $transaction->id;
|
||||
$attribute = 'not-important';
|
||||
$this->be($this->user());
|
||||
$engine = new IsValidAttachmentModel(Transaction::class);
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testTransactionJournal(): void
|
||||
{
|
||||
$journal = $this->getRandomWithdrawal();
|
||||
$journalRepos = $this->mock(JournalRepositoryInterface::class);
|
||||
|
||||
$journalRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$journalRepos->shouldReceive('findNull')->atLeast()->once()->withArgs([$journal->id])->andReturn($journal);
|
||||
|
||||
$value = $journal->id;
|
||||
$attribute = 'not-important';
|
||||
$this->be($this->user());
|
||||
$engine = new IsValidAttachmentModel(TransactionJournal::class);
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testBadModel(): void
|
||||
{
|
||||
$value = '123';
|
||||
$attribute = 'not-important';
|
||||
$this->be($this->user());
|
||||
$engine = new IsValidAttachmentModel('False');
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testBillPartial(): void
|
||||
{
|
||||
$bill = $this->getRandomBill();
|
||||
$billRepos = $this->mock(BillRepositoryInterface::class);
|
||||
|
||||
$billRepos->shouldReceive('setUser')->atLeast()->once();
|
||||
$billRepos->shouldReceive('find')->atLeast()->once()->withAnyArgs([$bill->id])->andReturn($bill);
|
||||
|
||||
$value = $bill->id;
|
||||
$attribute = 'not-important';
|
||||
$this->be($this->user());
|
||||
$engine = new IsValidAttachmentModel('Bill');
|
||||
$this->assertTrue($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\IsValidAttachmentModel
|
||||
*/
|
||||
public function testNotLoggedIn(): void
|
||||
{
|
||||
$value = '1';
|
||||
$attribute = 'not-important';
|
||||
$engine = new IsValidAttachmentModel(Bill::class);
|
||||
$this->assertFalse($engine->passes($attribute, $value));
|
||||
}
|
||||
|
||||
}
|
||||
150
tests/Unit/Rules/UniqueIbanTest.php
Normal file
150
tests/Unit/Rules/UniqueIbanTest.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
/**
|
||||
* UniqueIbanTest.php
|
||||
* Copyright (c) 2019 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/>.
|
||||
*/
|
||||
|
||||
namespace Tests\Unit\Rules;
|
||||
|
||||
|
||||
use FireflyIII\Rules\UniqueIban;
|
||||
use Log;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class UniqueIbanTest
|
||||
*/
|
||||
class UniqueIbanTest extends TestCase
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
Log::info(sprintf('Now in %s.', get_class($this)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\UniqueIban
|
||||
*/
|
||||
public function testBasic(): void
|
||||
{
|
||||
$asset = $this->getRandomAsset();
|
||||
$iban = $asset->iban;
|
||||
$asset->iban = 'NL123';
|
||||
$asset->save();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
$engine = new UniqueIban(null, 'asset');
|
||||
$this->assertFalse($engine->passes('not-important', $asset->iban));
|
||||
|
||||
$asset->iban = $iban;
|
||||
$asset->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\UniqueIban
|
||||
*/
|
||||
public function testBasicSkipExisting(): void
|
||||
{
|
||||
$asset = $this->getRandomAsset();
|
||||
$iban = $asset->iban;
|
||||
$asset->iban = 'NL123';
|
||||
$asset->save();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
$engine = new UniqueIban($asset, 'asset');
|
||||
$this->assertTrue($engine->passes('not-important', $asset->iban));
|
||||
|
||||
$asset->iban = $iban;
|
||||
$asset->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\UniqueIban
|
||||
*/
|
||||
public function testRevenue(): void
|
||||
{
|
||||
// give revenue account new IBAN.
|
||||
// should be OK to give it to an expense account
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$iban = $revenue->iban;
|
||||
$revenue->iban = 'NL123';
|
||||
$revenue->save();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
// returns true because this mix is OK.
|
||||
$engine = new UniqueIban(null, 'expense');
|
||||
$this->assertTrue($engine->passes('not-important', 'NL123'));
|
||||
|
||||
|
||||
$revenue->iban = $iban;
|
||||
$revenue->save();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\UniqueIban
|
||||
*/
|
||||
public function testExpense(): void
|
||||
{
|
||||
// give expense account new IBAN.
|
||||
// should be OK to give it to an expense account
|
||||
$expense = $this->getRandomExpense();
|
||||
$iban = $expense->iban;
|
||||
$expense->iban = 'NL123';
|
||||
$expense->save();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
// returns true because this mix is OK.
|
||||
$engine = new UniqueIban(null, 'revenue');
|
||||
$this->assertTrue($engine->passes('not-important', 'NL123'));
|
||||
|
||||
$expense->iban = $iban;
|
||||
$expense->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \FireflyIII\Rules\UniqueIban
|
||||
*/
|
||||
public function testRevenueAsset(): void
|
||||
{
|
||||
// give revenue account new IBAN.
|
||||
// should be OK to give it to an expense account
|
||||
$revenue = $this->getRandomRevenue();
|
||||
$iban = $revenue->iban;
|
||||
$revenue->iban = 'NL123';
|
||||
$revenue->save();
|
||||
|
||||
$this->be($this->user());
|
||||
|
||||
// returns false because this mix is not OK.
|
||||
$engine = new UniqueIban(null, 'asset');
|
||||
$this->assertFalse($engine->passes('not-important', 'NL123'));
|
||||
|
||||
|
||||
$revenue->iban = $iban;
|
||||
$revenue->save();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user