Implemented google chart tests.

This commit is contained in:
James Cole 2015-06-28 21:33:39 +02:00
parent e70444f19a
commit cfa67d6c0f
5 changed files with 160 additions and 28 deletions

View File

@ -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);
}
/**

View File

@ -1,4 +1,8 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Budget\GoogleBudgetChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleBudgetChartGeneratorTest
@ -6,6 +10,12 @@
class GoogleBudgetChartGeneratorTest extends TestCase
{
/** @var GoogleBudgetChartGenerator */
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
@ -14,8 +24,11 @@ class GoogleBudgetChartGeneratorTest extends TestCase
{
parent::setUp();
$this->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']);
}
}

View File

@ -1,4 +1,8 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Category\GoogleCategoryChartGenerator;
use Illuminate\Support\Collection;
use League\FactoryMuffin\Facade as FactoryMuffin;
/**
* Class GoogleCategoryChartGeneratorTest
@ -6,6 +10,10 @@
class GoogleCategoryChartGeneratorTest extends TestCase
{
/** @var GoogleCategoryChartGenerator */
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 GoogleCategoryChartGeneratorTest extends TestCase
{
parent::setUp();
$this->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']);
}
}

View File

@ -1,4 +1,7 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\PiggyBank\GooglePiggyBankChartGenerator;
use Illuminate\Support\Collection;
/**
* Class GooglePiggyBankChartGeneratorTest
@ -6,6 +9,9 @@
class GooglePiggyBankChartGeneratorTest extends TestCase
{
/** @var GooglePiggyBankChartGenerator */
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
@ -14,6 +20,8 @@ class GooglePiggyBankChartGeneratorTest extends TestCase
{
parent::setUp();
$this->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']);
}
}

View File

@ -1,10 +1,15 @@
<?php
use Carbon\Carbon;
use FireflyIII\Generator\Chart\Report\GoogleReportChartGenerator;
use Illuminate\Support\Collection;
/**
* Class GoogleReportChartGeneratorTest
*/
class GoogleReportChartGeneratorTest extends TestCase
{
/** @var GoogleReportChartGenerator */
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
@ -14,6 +19,8 @@ class GoogleReportChartGeneratorTest extends TestCase
{
parent::setUp();
$this->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']);
}
}