. */ declare(strict_types=1); namespace Tests\Unit\Rules; use FireflyIII\Rules\UniqueIban; use Log; use Tests\TestCase; /** * Class UniqueIbanTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) * @SuppressWarnings(PHPMD.ExcessiveMethodLength) * @SuppressWarnings(PHPMD.TooManyPublicMethods) */ 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(); } }