From 70eed5cb5ef75b5df28ad0f568c93d7c7fe46f4c Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 28 Jun 2015 18:00:11 +0200 Subject: [PATCH] New tests. --- .../Budget/ChartJsBudgetChartGenerator.php | 5 +- .../ChartJsCategoryChartGenerator.php | 1 + .../ChartJsBillChartGeneratorTest.php | 2 +- .../ChartJsBudgetChartGeneratorTest.php | 66 ++++++++++++++++--- .../ChartJsCategoryChartGeneratorTest.php | 65 +++++++++++++++--- .../ChartJsPiggyBankChartGeneratorTest.php | 32 ++++++++- .../ChartJsReportChartGeneratorTest.php | 47 ++++++++++++- 7 files changed, 192 insertions(+), 26 deletions(-) diff --git a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php index b17cfe7f04..f6af9c4568 100644 --- a/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php +++ b/app/Generator/Chart/Budget/ChartJsBudgetChartGenerator.php @@ -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; } diff --git a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php index 91a8aef3e7..c2feb4c660 100644 --- a/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php +++ b/app/Generator/Chart/Category/ChartJsCategoryChartGenerator.php @@ -69,6 +69,7 @@ class ChartJsCategoryChartGenerator implements CategoryChartGenerator } /** + * @codeCoverageIgnore * @param Collection $entries * * @return array diff --git a/tests/generators/ChartJsBillChartGeneratorTest.php b/tests/generators/ChartJsBillChartGeneratorTest.php index 53cdb49c69..62485e9c84 100644 --- a/tests/generators/ChartJsBillChartGeneratorTest.php +++ b/tests/generators/ChartJsBillChartGeneratorTest.php @@ -10,7 +10,7 @@ use League\FactoryMuffin\Facade as FactoryMuffin; class ChartJsBillChartGeneratorTest extends TestCase { - /** @var \FireflyIII\Generator\Chart\Bill\ChartJsBillChartGenerator */ + /** @var ChartJsBillChartGenerator */ protected $object; /** diff --git a/tests/generators/ChartJsBudgetChartGeneratorTest.php b/tests/generators/ChartJsBudgetChartGeneratorTest.php index 9749a5dd0b..7381287ad2 100644 --- a/tests/generators/ChartJsBudgetChartGeneratorTest.php +++ b/tests/generators/ChartJsBudgetChartGeneratorTest.php @@ -1,4 +1,8 @@ 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']); + } } \ No newline at end of file diff --git a/tests/generators/ChartJsCategoryChartGeneratorTest.php b/tests/generators/ChartJsCategoryChartGeneratorTest.php index 343782815d..d90276cc46 100644 --- a/tests/generators/ChartJsCategoryChartGeneratorTest.php +++ b/tests/generators/ChartJsCategoryChartGeneratorTest.php @@ -1,4 +1,9 @@ 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']); + + } } \ No newline at end of file diff --git a/tests/generators/ChartJsPiggyBankChartGeneratorTest.php b/tests/generators/ChartJsPiggyBankChartGeneratorTest.php index e684baeca8..e63b9d73fd 100644 --- a/tests/generators/ChartJsPiggyBankChartGeneratorTest.php +++ b/tests/generators/ChartJsPiggyBankChartGeneratorTest.php @@ -1,10 +1,16 @@ 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]); + + } } \ No newline at end of file diff --git a/tests/generators/ChartJsReportChartGeneratorTest.php b/tests/generators/ChartJsReportChartGeneratorTest.php index a0e624c735..28f69e8fc2 100644 --- a/tests/generators/ChartJsReportChartGeneratorTest.php +++ b/tests/generators/ChartJsReportChartGeneratorTest.php @@ -1,4 +1,9 @@ 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]); + } } \ No newline at end of file