New tests.

This commit is contained in:
James Cole
2015-06-28 18:00:11 +02:00
parent a650fa51f7
commit 70eed5cb5e
7 changed files with 192 additions and 26 deletions

View File

@@ -45,6 +45,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
/** /**
* @codeCoverageIgnore * @codeCoverageIgnore
*
* @param Collection $entries * @param Collection $entries
* *
* @return array * @return array
@@ -62,7 +63,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
public function frontpage(Collection $entries) public function frontpage(Collection $entries)
{ {
$data = [ $data = [
'count' => 2, 'count' => 0,
'labels' => [], 'labels' => [],
'datasets' => [], 'datasets' => [],
]; ];
@@ -119,7 +120,6 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
foreach ($budgets as $budget) { foreach ($budgets as $budget) {
$data['labels'][] = $budget->name; $data['labels'][] = $budget->name;
$data['count']++;
} }
/** @var array $entry */ /** @var array $entry */
foreach ($entries as $entry) { foreach ($entries as $entry) {
@@ -132,6 +132,7 @@ class ChartJsBudgetChartGenerator implements BudgetChartGenerator
$data['datasets'][] = $array; $data['datasets'][] = $array;
} }
$data['count'] = count($data['datasets']);
return $data; return $data;
} }

View File

@@ -69,6 +69,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator
} }
/** /**
* @codeCoverageIgnore
* @param Collection $entries * @param Collection $entries
* *
* @return array * @return array

View File

@@ -10,7 +10,7 @@ use League\FactoryMuffin\Facade as FactoryMuffin;
class ChartJsBillChartGeneratorTest extends TestCase class ChartJsBillChartGeneratorTest extends TestCase
{ {
/** @var \FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator */ /** @var ChartJsBillChartGenerator */
protected $object; protected $object;
/** /**

View File

@@ -1,4 +1,8 @@
<?php <?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/** /**
* Class ChartJsBudgetChartGeneratorTest * Class ChartJsBudgetChartGeneratorTest
@@ -6,6 +10,10 @@
class ChartJsBudgetChartGeneratorTest extends TestCase class ChartJsBudgetChartGeneratorTest extends TestCase
{ {
/** @var ChartJsBudgetChartGenerator */
protected $object;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed. * This method is called before a test is executed.
@@ -14,6 +22,8 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
{ {
parent::setUp(); parent::setUp();
$this->object = new ChartJsBudgetChartGenerator();
} }
/** /**
@@ -31,15 +41,17 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
*/ */
public function testBudget() 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]);
}
/** $data = $this->object->budget($collection);
* @covers FireflyIII\Generator\Chart\Budget\ChartJsBudgetChartGenerator::budgetLimit
*/ $this->assertCount(5, $data['labels']);
public function testBudgetLimit() $this->assertCount(5, $data['datasets'][0]['data']);
{ $this->assertEquals(100, $data['datasets'][0]['data'][0]);
$this->markTestIncomplete();
} }
/** /**
@@ -47,7 +59,20 @@ class ChartJsBudgetChartGeneratorTest extends TestCase
*/ */
public function testFrontpage() 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() 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']);
} }
} }

View File

@@ -1,4 +1,9 @@
<?php <?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/** /**
* Class ChartJsCategoryChartGeneratorTest * Class ChartJsCategoryChartGeneratorTest
@@ -6,6 +11,10 @@
class ChartJsCategoryChartGeneratorTest extends TestCase class ChartJsCategoryChartGeneratorTest extends TestCase
{ {
/** @var ChartJsCategoryChartGenerator */
protected $object;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed. * This method is called before a test is executed.
@@ -14,6 +23,8 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
{ {
parent::setUp(); parent::setUp();
$this->object = new ChartJsCategoryChartGenerator;
} }
/** /**
@@ -31,7 +42,17 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
*/ */
public function testAll() 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() 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]);
}
/** $data = $this->object->frontpage($collection);
* @covers FireflyIII\Generator\Chart\Category\ChartJsCategoryChartGenerator::month
*/ $this->assertCount(5, $data['labels']);
public function testMonth() $this->assertCount(5, $data['datasets'][0]['data']);
{ $this->assertEquals('Something', $data['labels'][0]);
$this->markTestIncomplete(); $this->assertEquals(100, $data['datasets'][0]['data'][0]);
} }
/** /**
@@ -55,6 +79,27 @@ class ChartJsCategoryChartGeneratorTest extends TestCase
*/ */
public function testYear() 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']);
} }
} }

View File

@@ -1,10 +1,16 @@
<?php <?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\PiggyBank\ChartJsPiggyBankChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/** /**
* Class ChartJsPiggyBankChartGeneratorTest * Class ChartJsPiggyBankChartGeneratorTest
*/ */
class ChartJsPiggyBankChartGeneratorTest extends TestCase class ChartJsPiggyBankChartGeneratorTest extends TestCase
{ {
/** @var ChartJsPiggyBankChartGenerator */
protected $object;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
@@ -14,6 +20,8 @@ class ChartJsPiggyBankChartGeneratorTest extends TestCase
{ {
parent::setUp(); parent::setUp();
$this->object = new ChartJsPiggyBankChartGenerator;
} }
/** /**
@@ -31,6 +39,28 @@ class ChartJsPiggyBankChartGeneratorTest extends TestCase
*/ */
public function testHistory() 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]);
} }
} }

View File

@@ -1,4 +1,9 @@
<?php <?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Report\ChartJsReportChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/** /**
* Class ChartJsReportChartGeneratorTest * Class ChartJsReportChartGeneratorTest
@@ -6,6 +11,9 @@
class ChartJsReportChartGeneratorTest extends TestCase class ChartJsReportChartGeneratorTest extends TestCase
{ {
/** @var ChartJsReportChartGenerator */
protected $object;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed. * This method is called before a test is executed.
@@ -14,6 +22,8 @@ class ChartJsReportChartGeneratorTest extends TestCase
{ {
parent::setUp(); parent::setUp();
$this->object = new ChartJsReportChartGenerator;
} }
/** /**
@@ -31,7 +41,25 @@ class ChartJsReportChartGeneratorTest extends TestCase
*/ */
public function testYearInOut() 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() 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]);
} }
} }