mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New tests.
This commit is contained in:
parent
a650fa51f7
commit
70eed5cb5e
@ -45,6 +45,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
*
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
@ -62,7 +63,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
public function frontpage(Collection $entries)
|
||||
{
|
||||
$data = [
|
||||
'count' => 2,
|
||||
'count' => 0,
|
||||
'labels' => [],
|
||||
'datasets' => [],
|
||||
];
|
||||
@ -119,7 +120,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
|
||||
foreach ($budgets as $budget) {
|
||||
$data['labels'][] = $budget->name;
|
||||
$data['count']++;
|
||||
}
|
||||
/** @var array $entry */
|
||||
foreach ($entries as $entry) {
|
||||
@ -132,6 +132,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
|
||||
$data['datasets'][] = $array;
|
||||
|
||||
}
|
||||
$data['count'] = count($data['datasets']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @param Collection $entries
|
||||
*
|
||||
* @return array
|
||||
|
@ -10,7 +10,7 @@ use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
class ChartJsBillChartGeneratorTest extends TestCase
|
||||
{
|
||||
|
||||
/** @var \FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator */
|
||||
/** @var ChartJsBillChartGenerator */
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,8 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class ChartJsBudgetChartGeneratorTest
|
||||
@ -6,6 +10,10 @@
|
||||
class ChartJsBudgetChartGeneratorTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/** @var ChartJsBudgetChartGenerator */
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -14,6 +22,8 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->object = new ChartJsBudgetChartGenerator();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,15 +41,17 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testBudget()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
// make a collection with some amounts in them.
|
||||
$collection = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$collection->push([null, 100]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::budgetLimit
|
||||
*/
|
||||
public function testBudgetLimit()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$data = $this->object->budget($collection);
|
||||
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertCount(5, $data['datasets'][0]['data']);
|
||||
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,7 +59,20 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testFrontpage()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
// make a collection with some amounts in them.
|
||||
$collection = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$collection->push(['Some label', 100, 200, 300]);
|
||||
}
|
||||
|
||||
$data = $this->object->frontpage($collection);
|
||||
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertCount(5, $data['datasets'][0]['data']);
|
||||
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
|
||||
$this->assertEquals(200, $data['datasets'][1]['data'][0]);
|
||||
$this->assertEquals(300, $data['datasets'][2]['data'][0]);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,6 +80,27 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testYear()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||
$preference->data = 'en';
|
||||
$preference->save();
|
||||
|
||||
$budgets = new Collection;
|
||||
$entries = new Collection;
|
||||
|
||||
// make some budgets:
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$budgets->push(FactoryMuffin::create('FireflyIII\Models\Budget'));
|
||||
$entries->push([new Carbon, 100, 100, 100]);
|
||||
}
|
||||
|
||||
// mock language preference:
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||
|
||||
$data = $this->object->year($budgets, $entries);
|
||||
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertCount(5, $data['datasets']);
|
||||
$this->assertCount(3, $data['datasets'][0]['data']);
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
|
||||
/**
|
||||
* Class ChartJsCategoryChartGeneratorTest
|
||||
@ -6,6 +11,10 @@
|
||||
class ChartJsCategoryChartGeneratorTest extends TestCase
|
||||
{
|
||||
|
||||
|
||||
/** @var ChartJsCategoryChartGenerator */
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -14,6 +23,8 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->object = new ChartJsCategoryChartGenerator;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,7 +42,17 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testAll()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
// make a collection of stuff:
|
||||
$collection = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$collection->push([null, 100]);
|
||||
}
|
||||
|
||||
$data = $this->object->all($collection);
|
||||
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertCount(5, $data['datasets'][0]['data']);
|
||||
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,15 +60,18 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testFrontpage()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
}
|
||||
// make a collection of stuff:
|
||||
$collection = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$collection->push(['name' => 'Something', 'sum' => 100]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator::month
|
||||
*/
|
||||
public function testMonth()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$data = $this->object->frontpage($collection);
|
||||
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertCount(5, $data['datasets'][0]['data']);
|
||||
$this->assertEquals('Something', $data['labels'][0]);
|
||||
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -55,6 +79,27 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testYear()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||
$preference->data = 'en';
|
||||
$preference->save();
|
||||
|
||||
// mock language preference:
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||
|
||||
// make a collection of stuff:
|
||||
$collection = new Collection;
|
||||
$categories = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$categories->push(FactoryMuffin::create('FireflyIII\Models\Category'));
|
||||
$collection->push([new Carbon, 100, 100, 100]);
|
||||
}
|
||||
|
||||
$data = $this->object->year($categories, $collection);
|
||||
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertEquals($categories->first()->name, $data['labels'][0]);
|
||||
$this->assertCount(3, $data['datasets'][0]['data']);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,10 +1,16 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
/**
|
||||
* Class ChartJsPiggyBankChartGeneratorTest
|
||||
*/
|
||||
class ChartJsPiggyBankChartGeneratorTest extends TestCase
|
||||
{
|
||||
/** @var ChartJsPiggyBankChartGenerator */
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
@ -14,6 +20,8 @@ class ChartJsPiggyBankChartGeneratorTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->object = new ChartJsPiggyBankChartGenerator;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,6 +39,28 @@ class ChartJsPiggyBankChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testHistory()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||
$preference->data = 'en';
|
||||
$preference->save();
|
||||
|
||||
// mock language preference:
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||
|
||||
// create a set
|
||||
$set = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$obj = new stdClass;
|
||||
$obj->date = new Carbon;
|
||||
$obj->sum = 100;
|
||||
$set->push($obj);
|
||||
}
|
||||
|
||||
$data = $this->object->history($set);
|
||||
$this->assertCount(5, $data['labels']);
|
||||
$this->assertCount(5, $data['datasets'][0]['data']);
|
||||
$this->assertEquals(100, $data['datasets'][0]['data'][0]);
|
||||
$this->assertEquals(500, $data['datasets'][0]['data'][4]);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,9 @@
|
||||
<?php
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||
|
||||
|
||||
/**
|
||||
* Class ChartJsReportChartGeneratorTest
|
||||
@ -6,6 +11,9 @@
|
||||
class ChartJsReportChartGeneratorTest extends TestCase
|
||||
{
|
||||
|
||||
/** @var ChartJsReportChartGenerator */
|
||||
protected $object;
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
@ -14,6 +22,8 @@ class ChartJsReportChartGeneratorTest extends TestCase
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->object = new ChartJsReportChartGenerator;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -31,7 +41,25 @@ class ChartJsReportChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testYearInOut()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||
$preference->data = 'en';
|
||||
$preference->save();
|
||||
|
||||
// mock language preference:
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||
|
||||
// make set:
|
||||
$collection = new Collection;
|
||||
for ($i = 0; $i < 5; $i++) {
|
||||
$collection->push([new Carbon, 200, 100]);
|
||||
}
|
||||
|
||||
$data = $this->object->yearInOut($collection);
|
||||
|
||||
$this->assertEquals(200, $data['datasets'][0]['data'][0]);
|
||||
$this->assertEquals(100, $data['datasets'][1]['data'][0]);
|
||||
$this->assertCount(5, $data['labels']);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,6 +67,21 @@ class ChartJsReportChartGeneratorTest extends TestCase
|
||||
*/
|
||||
public function testYearInOutSummarized()
|
||||
{
|
||||
$this->markTestIncomplete();
|
||||
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||
$preference->data = 'en';
|
||||
$preference->save();
|
||||
|
||||
// mock language preference:
|
||||
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||
|
||||
// make set:
|
||||
$income = 2400;
|
||||
$expense = 1200;
|
||||
|
||||
$data = $this->object->yearInOutSummarized($income, $expense, 12);
|
||||
|
||||
$this->assertEquals(200, $data['datasets'][0]['data'][1]);
|
||||
$this->assertEquals(100, $data['datasets'][1]['data'][1]);
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user