Files
firefly-iii/tests/models/AccountModelTest.php

141 lines
3.5 KiB
PHP
Raw Normal View History

2015-05-24 10:01:00 +02:00
<?php
2015-05-24 11:13:46 +02:00
use FireflyIII\Models\Account;
use League\FactoryMuffin\Facade as FactoryMuffin;
2015-05-24 10:01:00 +02:00
/**
* Class AccountModelTest
*/
class AccountModelTest extends TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
parent::setUp();
}
/**
* This method is called before the first test of this test class is run.
*
* @since Method available since Release 3.4.0
*/
public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
public function tearDown()
{
parent::tearDown();
}
/**
* @covers FireflyIII\Models\Account::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncrypted()
{
2015-05-24 11:13:46 +02:00
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// search for account with the same properties:
$search = [
'name' => $account->name,
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id
];
$result = Account::firstOrCreateEncrypted($search);
// should be the same account:
$this->assertEquals($account->id, $result->id);
}
/**
* @covers FireflyIII\Models\Account::firstOrCreateEncrypted
*/
public function testFirstOrCreateEncryptedNew()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
2015-05-26 08:17:58 +02:00
FactoryMuffin::create('FireflyIII\User');
2015-05-24 11:13:46 +02:00
// search for account with the same properties:
$search = [
'name' => 'Some new account',
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id,
2015-05-25 19:58:13 +02:00
'active' => 1,
2015-05-24 11:13:46 +02:00
];
$result = Account::firstOrCreateEncrypted($search);
// should not be the same account:
$this->assertNotEquals($account->id, $result->id);
2015-05-24 10:01:00 +02:00
}
/**
* @covers FireflyIII\Models\Account::firstOrNullEncrypted
*/
public function testFirstOrNullEncrypted()
{
2015-05-24 11:13:46 +02:00
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
// search for account with the same properties:
$search = [
'name' => $account->name,
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id
];
$result = Account::firstOrNullEncrypted($search);
// should be the same account:
$this->assertEquals($account->id, $result->id);
}
/**
* @covers FireflyIII\Models\Account::firstOrNullEncrypted
*/
public function testFirstOrNullEncryptedNew()
{
// create account:
$account = FactoryMuffin::create('FireflyIII\Models\Account');
2015-05-26 08:17:58 +02:00
FactoryMuffin::create('FireflyIII\User');
2015-05-24 11:13:46 +02:00
// search for account with the same properties:
$search = [
'name' => 'Some new account',
'account_type_id' => $account->account_type_id,
'user_id' => $account->user_id,
2015-05-25 19:58:13 +02:00
'active' => 1,
2015-05-24 11:13:46 +02:00
];
$result = Account::firstOrNullEncrypted($search);
// should not be the same account:
$this->assertNull($result);
2015-05-24 10:01:00 +02:00
}
2015-05-24 15:18:19 +02:00
}