From cfa67d6c0f66ab732257cecac345c54917143541 Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 28 Jun 2015 21:33:39 +0200 Subject: [PATCH] Implemented google chart tests. --- .../Budget/GoogleBudgetChartGenerator.php | 13 +--- .../GoogleBudgetChartGeneratorTest.php | 58 ++++++++++++++--- .../GoogleCategoryChartGeneratorTest.php | 63 +++++++++++++++++-- .../GooglePiggyBankChartGeneratorTest.php | 25 +++++++- .../GoogleReportChartGeneratorTest.php | 29 ++++++++- 5 files changed, 160 insertions(+), 28 deletions(-) diff --git a/app/Generator/Chart/Budget/GoogleBudgetChartGenerator.php b/app/Generator/Chart/Budget/GoogleBudgetChartGenerator.php index 858859f18d..a463a6b296 100644 --- a/app/Generator/Chart/Budget/GoogleBudgetChartGenerator.php +++ b/app/Generator/Chart/Budget/GoogleBudgetChartGenerator.php @@ -36,23 +36,14 @@ class GoogleBudgetChartGenerator implements BudgetChartGenerator } /** + * @codeCoverageIgnore * @param Collection $entries * * @return array */ public function budgetLimit(Collection $entries) { - $chart = new GChart; - $chart->addColumn(trans('firefly.day'), 'date'); - $chart->addColumn(trans('firefly.left'), 'number'); - - foreach ($entries as $entry) { - - $chart->addRow($entry[0], $entry[1]); - } - $chart->generate(); - - return $chart->getData(); + return $this->budget($entries); } /** diff --git a/tests/generators/GoogleBudgetChartGeneratorTest.php b/tests/generators/GoogleBudgetChartGeneratorTest.php index 0316c4da34..13b3cb54bc 100644 --- a/tests/generators/GoogleBudgetChartGeneratorTest.php +++ b/tests/generators/GoogleBudgetChartGeneratorTest.php @@ -1,4 +1,8 @@ object = new GoogleBudgetChartGenerator(); + } + /** * This method is called before the first test of this test class is run. * @@ -32,15 +45,17 @@ class GoogleBudgetChartGeneratorTest 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([new Carbon, 100]); + } - /** - * @covers FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator::budgetLimit - */ - public function testBudgetLimit() - { - $this->markTestIncomplete(); + $data = $this->object->budget($collection); + + $this->assertCount(5, $data['rows']); + $this->assertCount(2, $data['cols']); + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); } /** @@ -48,7 +63,18 @@ class GoogleBudgetChartGeneratorTest 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['rows']); + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); + $this->assertEquals(200, $data['rows'][0]['c'][2]['v']); + $this->assertEquals(300, $data['rows'][0]['c'][3]['v']); } /** @@ -56,6 +82,18 @@ class GoogleBudgetChartGeneratorTest extends TestCase */ public function testYear() { - $this->markTestIncomplete(); + $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]); + } + + $data = $this->object->year($budgets, $entries); + + $this->assertCount(5, $data['rows']); + $this->assertCount(6, $data['cols']); } } \ No newline at end of file diff --git a/tests/generators/GoogleCategoryChartGeneratorTest.php b/tests/generators/GoogleCategoryChartGeneratorTest.php index 875652633a..78f0ffde39 100644 --- a/tests/generators/GoogleCategoryChartGeneratorTest.php +++ b/tests/generators/GoogleCategoryChartGeneratorTest.php @@ -1,4 +1,8 @@ object = new GoogleCategoryChartGenerator(); + } /** @@ -32,7 +42,17 @@ class GoogleCategoryChartGeneratorTest extends TestCase */ public function testAll() { - $this->markTestIncomplete(); + // make a collection of stuff: + $collection = new Collection; + for ($i = 0; $i < 5; $i++) { + $collection->push([new Carbon, 100]); + } + + $data = $this->object->all($collection); + + $this->assertCount(5, $data['rows']); + $this->assertCount(2, $data['cols']); + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); } /** @@ -40,7 +60,19 @@ class GoogleCategoryChartGeneratorTest 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]); + } + + $data = $this->object->frontpage($collection); + + $this->assertCount(5, $data['rows']); + $this->assertCount(2, $data['cols']); + $this->assertEquals('Something', $data['rows'][0]['c'][0]['v']); + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); + } /** @@ -48,7 +80,17 @@ class GoogleCategoryChartGeneratorTest extends TestCase */ public function testMonth() { - $this->markTestIncomplete(); + // make a collection of stuff: + $collection = new Collection; + for ($i = 0; $i < 5; $i++) { + $collection->push([new Carbon, 100]); + } + + $data = $this->object->month($collection); + + $this->assertCount(5, $data['rows']); + $this->assertCount(2, $data['cols']); + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); } /** @@ -56,6 +98,19 @@ class GoogleCategoryChartGeneratorTest extends TestCase */ public function testYear() { - $this->markTestIncomplete(); + // 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['rows']); + $this->assertEquals($categories->first()->name, $data['cols'][1]['label']); + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); + } } \ No newline at end of file diff --git a/tests/generators/GooglePiggyBankChartGeneratorTest.php b/tests/generators/GooglePiggyBankChartGeneratorTest.php index 15f467291a..7c1daf7a9f 100644 --- a/tests/generators/GooglePiggyBankChartGeneratorTest.php +++ b/tests/generators/GooglePiggyBankChartGeneratorTest.php @@ -1,4 +1,7 @@ object = new GooglePiggyBankChartGenerator(); + } /** @@ -25,11 +33,26 @@ class GooglePiggyBankChartGeneratorTest extends TestCase { parent::setUpBeforeClass(); } + /** * @covers FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator::history */ public function testHistory() { - $this->markTestIncomplete(); + // 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['rows']); + $this->assertCount(2, $data['cols']); + + $this->assertEquals(100, $data['rows'][0]['c'][1]['v']); + $this->assertEquals(500, $data['rows'][4]['c'][1]['v']); } } \ No newline at end of file diff --git a/tests/generators/GoogleReportChartGeneratorTest.php b/tests/generators/GoogleReportChartGeneratorTest.php index f130e77594..57c715ad02 100644 --- a/tests/generators/GoogleReportChartGeneratorTest.php +++ b/tests/generators/GoogleReportChartGeneratorTest.php @@ -1,10 +1,15 @@ object = new GoogleReportChartGenerator; + } /** @@ -31,7 +38,18 @@ class GoogleReportChartGeneratorTest extends TestCase */ public function testYearInOut() { - $this->markTestIncomplete(); + // make set: + $collection = new Collection; + for ($i = 0; $i < 5; $i++) { + $collection->push([new Carbon, 200, 100]); + } + + $data = $this->object->yearInOut($collection); + + $this->assertCount(5, $data['rows']); + + $this->assertEquals(200, $data['rows'][0]['c'][1]['v']); + $this->assertEquals(100, $data['rows'][0]['c'][2]['v']); } /** @@ -39,6 +57,13 @@ class GoogleReportChartGeneratorTest extends TestCase */ public function testYearInOutSummarized() { - $this->markTestIncomplete(); + // make set: + $income = 2400; + $expense = 1200; + + $data = $this->object->yearInOutSummarized($income, $expense, 12); + + $this->assertEquals(200, $data['rows'][1]['c'][1]['v']); + $this->assertEquals(100, $data['rows'][1]['c'][2]['v']); } } \ No newline at end of file