mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New tests for object transformers.
This commit is contained in:
@@ -75,7 +75,7 @@ class BillTransformerTest extends TestCase
|
||||
public function testNote()
|
||||
{
|
||||
|
||||
$bill = Bill::create(
|
||||
$bill = Bill::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'name' => 'Some bill ' . rand(1, 10000),
|
||||
@@ -88,8 +88,8 @@ class BillTransformerTest extends TestCase
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$noteText = 'I are a note ' . rand(1, 10000);
|
||||
$note = Note::create(
|
||||
$noteText = 'I are a note ' . rand(1, 10000);
|
||||
Note::create(
|
||||
[
|
||||
'noteable_id' => $bill->id,
|
||||
'noteable_type' => Bill::class,
|
||||
@@ -118,7 +118,7 @@ class BillTransformerTest extends TestCase
|
||||
// mock stuff
|
||||
$repository = $this->mock(BillRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->andReturnSelf();
|
||||
$repository->shouldReceive('getPaidDatesInRange')->andReturn(new Collection([new Carbon]));
|
||||
$repository->shouldReceive('getPaidDatesInRange')->andReturn(new Collection([new Carbon('2018-01-02')]));
|
||||
$bill = Bill::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
@@ -127,7 +127,7 @@ class BillTransformerTest extends TestCase
|
||||
'amount_min' => 12.34,
|
||||
'amount_max' => 45.67,
|
||||
'date' => '2018-01-02',
|
||||
'repeat_freq' => 'weekly',
|
||||
'repeat_freq' => 'monthly',
|
||||
'skip' => 0,
|
||||
'active' => 1,
|
||||
]
|
||||
@@ -140,6 +140,10 @@ class BillTransformerTest extends TestCase
|
||||
|
||||
$this->assertEquals($bill->name, $result['name']);
|
||||
$this->assertTrue($result['active']);
|
||||
$this->assertCount(1, $result['pay_dates']);
|
||||
$this->assertEquals('2018-01-02', $result['pay_dates'][0]);
|
||||
$this->assertCount(1, $result['paid_dates']);
|
||||
$this->assertEquals('2018-01-02', $result['paid_dates'][0]);
|
||||
}
|
||||
|
||||
}
|
||||
58
tests/Unit/Transformers/BudgetTransformerTest.php
Normal file
58
tests/Unit/Transformers/BudgetTransformerTest.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
/**
|
||||
* BudgetTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
use FireflyIII\Models\Budget;
|
||||
use FireflyIII\Transformers\BudgetTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Class BudgetTransformerTest
|
||||
*/
|
||||
class BudgetTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Basic coverage
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\BudgetTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
|
||||
$budget = Budget::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'name' => 'Some budget ' . rand(1, 10000),
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$transformer = new BudgetTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($budget);
|
||||
|
||||
$this->assertEquals($budget->name, $result['name']);
|
||||
$this->assertTrue($result['active']);
|
||||
}
|
||||
}
|
||||
57
tests/Unit/Transformers/CategoryTransformerTest.php
Normal file
57
tests/Unit/Transformers/CategoryTransformerTest.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
/**
|
||||
* CategoryTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
use FireflyIII\Transformers\CategoryTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
|
||||
/**
|
||||
* Class CategoryTransformerTest
|
||||
*/
|
||||
class CategoryTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Basic coverage
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\CategoryTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
|
||||
$category = Category::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'name' => 'Some budget ' . rand(1, 10000),
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$transformer = new CategoryTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($category);
|
||||
|
||||
$this->assertEquals($category->name, $result['name']);
|
||||
}
|
||||
}
|
||||
60
tests/Unit/Transformers/JournalMetaTransformerTest.php
Normal file
60
tests/Unit/Transformers/JournalMetaTransformerTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* JournalMetaTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
use FireflyIII\Models\TransactionJournalMeta;
|
||||
use FireflyIII\Transformers\JournalMetaTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class JournalMetaTransformerTest
|
||||
*/
|
||||
class JournalMetaTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Basic coverage
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\JournalMetaTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$data = 'Lots of data';
|
||||
$hash = hash('sha256', json_encode($data));
|
||||
$meta = TransactionJournalMeta::create(
|
||||
[
|
||||
'transaction_journal_id' => 1,
|
||||
'name' => 'someField',
|
||||
'data' => $data,
|
||||
]
|
||||
);
|
||||
|
||||
$transformer = new JournalMetaTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($meta);
|
||||
|
||||
$this->assertEquals($meta->name, $result['name']);
|
||||
$this->assertEquals($hash, $result['hash']);
|
||||
}
|
||||
|
||||
}
|
||||
144
tests/Unit/Transformers/PiggyBankEventTransformerTest.php
Normal file
144
tests/Unit/Transformers/PiggyBankEventTransformerTest.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**
|
||||
* PiggyBankEventTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankEvent;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Transformers\PiggyBankEventTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class PiggyBankEventTransformerTest
|
||||
*/
|
||||
class PiggyBankEventTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Basic test with no meta data.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\PiggyBankEventTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'account_type_id' => 3, // asset account
|
||||
'name' => 'Random name #' . rand(1, 10000),
|
||||
'virtual_balance' => 12.34,
|
||||
'iban' => 'NL85ABNA0466812694',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
$piggy = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'Some random piggy #' . rand(1, 10000),
|
||||
'targetamount' => '1000',
|
||||
'startdate' => '2018-01-01',
|
||||
'targetdate' => '2018-01-31',
|
||||
'order' => 1,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$event = PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $piggy->id,
|
||||
'date' => '2018-01-01',
|
||||
'amount' => '123.45',
|
||||
]
|
||||
);
|
||||
|
||||
$transformer = new PiggyBankEventTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($event);
|
||||
$this->assertEquals($event->id, $result['id']);
|
||||
$this->assertEquals(123.45, $result['amount']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic test with currency meta data.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\PiggyBankEventTransformer::transform
|
||||
*/
|
||||
public function testBasicCurrency()
|
||||
{
|
||||
// mock repository.
|
||||
$repository = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->once();
|
||||
|
||||
// make new account:
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'account_type_id' => 3, // asset account
|
||||
'name' => 'Random name #' . rand(1, 10000),
|
||||
'virtual_balance' => 12.34,
|
||||
'iban' => 'NL85ABNA0466812694',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
|
||||
// meta
|
||||
$accountMeta = AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
$piggy = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'Some random piggy #' . rand(1, 10000),
|
||||
'targetamount' => '1000',
|
||||
'startdate' => '2018-01-01',
|
||||
'targetdate' => '2018-01-31',
|
||||
'order' => 1,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$event = PiggyBankEvent::create(
|
||||
[
|
||||
'piggy_bank_id' => $piggy->id,
|
||||
'date' => '2018-01-01',
|
||||
'amount' => '123.45',
|
||||
]
|
||||
);
|
||||
|
||||
$transformer = new PiggyBankEventTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($event);
|
||||
$this->assertEquals($event->id, $result['id']);
|
||||
$this->assertEquals(123.45, $result['amount']);
|
||||
}
|
||||
|
||||
}
|
||||
208
tests/Unit/Transformers/PiggyBankTransformerTest.php
Normal file
208
tests/Unit/Transformers/PiggyBankTransformerTest.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
/**
|
||||
* PiggyBankTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountMeta;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Repositories\PiggyBank\PiggyBankRepositoryInterface;
|
||||
use FireflyIII\Transformers\PiggyBankTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class PiggyBankTransformerTest
|
||||
*/
|
||||
class PiggyBankTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic transformer.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\PiggyBankTransformer::transform()
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
// mock repository:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getCurrentAmount')->andReturn('12.34')->once();
|
||||
|
||||
// make new account and piggy
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'account_type_id' => 3, // asset account
|
||||
'name' => 'Random name #' . rand(1, 10000),
|
||||
'virtual_balance' => 12.34,
|
||||
'iban' => 'NL85ABNA0466812694',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
$piggy = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'Some random piggy #' . rand(1, 10000),
|
||||
'targetamount' => '1000',
|
||||
'startdate' => '2018-01-01',
|
||||
'targetdate' => '2018-01-31',
|
||||
'order' => 1,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$transformer = new PiggyBankTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($piggy);
|
||||
$this->assertTrue($result['active']);
|
||||
$this->assertEquals(12.34, $result['current_amount']);
|
||||
$this->assertEquals($piggy->name, $result['name']);
|
||||
$this->assertEquals('', $result['notes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic transformer with currency preference
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\PiggyBankTransformer::transform()
|
||||
*/
|
||||
public function testBasicWithCurrency()
|
||||
{
|
||||
// mock repository.
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->once();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getCurrentAmount')->andReturn('12.34')->once();
|
||||
|
||||
// make new account and piggy
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'account_type_id' => 3, // asset account
|
||||
'name' => 'Random name #' . rand(1, 10000),
|
||||
'virtual_balance' => 12.34,
|
||||
'iban' => 'NL85ABNA0466812694',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
// meta
|
||||
$accountMeta = AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
$piggy = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'Some random piggy #' . rand(1, 10000),
|
||||
'targetamount' => '1000',
|
||||
'startdate' => '2018-01-01',
|
||||
'targetdate' => '2018-01-31',
|
||||
'order' => 1,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
$transformer = new PiggyBankTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($piggy);
|
||||
$this->assertTrue($result['active']);
|
||||
$this->assertEquals(12.34, $result['current_amount']);
|
||||
$this->assertEquals($piggy->name, $result['name']);
|
||||
$this->assertEquals('', $result['notes']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic transformer with currency preference and a note
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\PiggyBankTransformer::transform()
|
||||
*/
|
||||
public function testBasicWithCurrencyAndNote()
|
||||
{
|
||||
// mock repository.
|
||||
$currencyRepos = $this->mock(CurrencyRepositoryInterface::class);
|
||||
$currencyRepos->shouldReceive('setUser')->once();
|
||||
$currencyRepos->shouldReceive('findNull')->withArgs([1])->andReturn(TransactionCurrency::find(1))->once();
|
||||
|
||||
// mock repository:
|
||||
$repository = $this->mock(PiggyBankRepositoryInterface::class);
|
||||
$repository->shouldReceive('setUser')->once();
|
||||
$repository->shouldReceive('getCurrentAmount')->andReturn('12.34')->once();
|
||||
|
||||
// make new account and piggy
|
||||
$account = Account::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'account_type_id' => 3, // asset account
|
||||
'name' => 'Random name #' . rand(1, 10000),
|
||||
'virtual_balance' => 12.34,
|
||||
'iban' => 'NL85ABNA0466812694',
|
||||
'active' => 1,
|
||||
'encrypted' => 0,
|
||||
]
|
||||
);
|
||||
// meta
|
||||
$accountMeta = AccountMeta::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'currency_id',
|
||||
'data' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
$piggy = PiggyBank::create(
|
||||
[
|
||||
'account_id' => $account->id,
|
||||
'name' => 'Some random piggy #' . rand(1, 10000),
|
||||
'targetamount' => '1000',
|
||||
'startdate' => '2018-01-01',
|
||||
'targetdate' => '2018-01-31',
|
||||
'order' => 1,
|
||||
'active' => 1,
|
||||
]
|
||||
);
|
||||
|
||||
// note:
|
||||
Note::create(
|
||||
[
|
||||
'noteable_id' => $piggy->id,
|
||||
'noteable_type' => PiggyBank::class,
|
||||
'title' => null,
|
||||
'text' => 'I am a note.',
|
||||
]
|
||||
);
|
||||
$transformer = new PiggyBankTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($piggy);
|
||||
$this->assertTrue($result['active']);
|
||||
$this->assertEquals(12.34, $result['current_amount']);
|
||||
$this->assertEquals($piggy->name, $result['name']);
|
||||
$this->assertEquals('I am a note.', $result['notes']);
|
||||
}
|
||||
}
|
||||
64
tests/Unit/Transformers/TagTransformerTest.php
Normal file
64
tests/Unit/Transformers/TagTransformerTest.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
/**
|
||||
* TagTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Transformers\TagTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class TagTransformerTest
|
||||
*/
|
||||
class TagTransformerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Test basic tag transformer
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\TagTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$tag = Tag::create(
|
||||
[
|
||||
'user_id' => $this->user()->id,
|
||||
'tag' => 'Some tag ' . rand(1, 1000),
|
||||
'tagMode' => 'nothing',
|
||||
'date' => '2018-01-01',
|
||||
'description' => 'Some tag',
|
||||
'latitude' => 5.5,
|
||||
'longitude' => '6.6',
|
||||
'zoomLevel' => 3,
|
||||
]
|
||||
);
|
||||
$transformer = new TagTransformer(new ParameterBag);
|
||||
$result = $transformer->transform($tag);
|
||||
$this->assertEquals('nothing', $result['tag_mode']);
|
||||
$this->assertEquals($tag->tag, $result['tag']);
|
||||
$this->assertEquals(5.5, $result['latitude']);
|
||||
$this->assertEquals(6.6, $result['longitude']);
|
||||
}
|
||||
|
||||
}
|
||||
1403
tests/Unit/Transformers/TransactionTransformerTest.php
Normal file
1403
tests/Unit/Transformers/TransactionTransformerTest.php
Normal file
File diff suppressed because it is too large
Load Diff
67
tests/Unit/Transformers/UserTransformerTest.php
Normal file
67
tests/Unit/Transformers/UserTransformerTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
/**
|
||||
* UserTransformerTest.php
|
||||
* Copyright (c) 2018 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\Unit\Transformers;
|
||||
|
||||
|
||||
use FireflyIII\Transformers\UserTransformer;
|
||||
use Symfony\Component\HttpFoundation\ParameterBag;
|
||||
use Tests\TestCase;
|
||||
|
||||
/**
|
||||
* Class UserTransformerTest
|
||||
*/
|
||||
class UserTransformerTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Test basic transformer.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\UserTransformer::transform
|
||||
*/
|
||||
public function testBasic()
|
||||
{
|
||||
$user = $this->user();
|
||||
$transformer = new UserTransformer(new ParameterBag());
|
||||
$result = $transformer->transform($user);
|
||||
|
||||
$this->assertEquals($user->email, $result['email']);
|
||||
$this->assertEquals('owner', $result['role']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test basic transformer.
|
||||
*
|
||||
* @covers \FireflyIII\Transformers\UserTransformer::transform
|
||||
*/
|
||||
public function testEmptyUser()
|
||||
{
|
||||
$user = $this->emptyUser();
|
||||
$transformer = new UserTransformer(new ParameterBag());
|
||||
$result = $transformer->transform($user);
|
||||
|
||||
$this->assertEquals($user->email, $result['email']);
|
||||
$this->assertNull($result['role']);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user