mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-30 02:26:58 +00:00
First test for chartJS.
This commit is contained in:
@@ -71,8 +71,8 @@ class ChartJsAccountChartGenerator implements AccountChartGenerator
|
|||||||
$current->addDay();
|
$current->addDay();
|
||||||
}
|
}
|
||||||
$data['datasets'][] = $set;
|
$data['datasets'][] = $set;
|
||||||
$data['count']++;
|
|
||||||
}
|
}
|
||||||
|
$data['count'] = count($data['datasets']);
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
1
tests/database/.gitignore
vendored
1
tests/database/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
*.sqlite
|
|
@@ -1,19 +1,32 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
use FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator;
|
||||||
|
use Illuminate\Support\Collection;
|
||||||
|
use League\FactoryMuffin\Facade as FactoryMuffin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ChartJsAccountChartGeneratorTest
|
* Class ChartJsAccountChartGeneratorTest
|
||||||
*/
|
*/
|
||||||
class ChartJsAccountChartGeneratorTest extends TestCase
|
class ChartJsAccountChartGeneratorTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var ChartJsAccountChartGenerator
|
||||||
|
*/
|
||||||
|
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.
|
||||||
*/
|
*/
|
||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
|
$this->object = new ChartJsAccountChartGenerator;
|
||||||
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,20 +39,41 @@ class ChartJsAccountChartGeneratorTest extends TestCase
|
|||||||
parent::setUpBeforeClass();
|
parent::setUpBeforeClass();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::all
|
|
||||||
*/
|
|
||||||
public function testAll()
|
|
||||||
{
|
|
||||||
$this->markTestIncomplete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::frontpage
|
* @covers FireflyIII\Generator\Chart\Account\ChartJsAccountChartGenerator::frontpage
|
||||||
*/
|
*/
|
||||||
public function testFrontpage()
|
public function testFrontpage()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
// be somebody
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
// create some accounts:
|
||||||
|
$accounts = new Collection;
|
||||||
|
for ($i = 0; $i < 5; $i++) {
|
||||||
|
$accounts->push(FactoryMuffin::create('FireflyIII\Models\Account'));
|
||||||
|
}
|
||||||
|
|
||||||
|
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$preference->data = 'en';
|
||||||
|
$preference->save();
|
||||||
|
|
||||||
|
// data for call:
|
||||||
|
$start = Carbon::createFromDate(2015, 1, 1);
|
||||||
|
$end = Carbon::createFromDate(2015, 1, 15);
|
||||||
|
|
||||||
|
// mock language preference:
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||||
|
|
||||||
|
// mock Steam::balance
|
||||||
|
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
|
||||||
|
|
||||||
|
// call
|
||||||
|
$result = $this->object->frontpage($accounts, $start, $end);
|
||||||
|
|
||||||
|
$this->assertEquals($accounts->count(), $result['count']);
|
||||||
|
$this->assertCount(15, $result['labels']);
|
||||||
|
$this->assertCount($accounts->count(), $result['datasets']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,6 +81,34 @@ class ChartJsAccountChartGeneratorTest extends TestCase
|
|||||||
*/
|
*/
|
||||||
public function testSingle()
|
public function testSingle()
|
||||||
{
|
{
|
||||||
$this->markTestIncomplete();
|
// be somebody
|
||||||
|
$user = FactoryMuffin::create('FireflyIII\User');
|
||||||
|
$this->be($user);
|
||||||
|
|
||||||
|
$preference = FactoryMuffin::create('FireflyIII\Models\Preference');
|
||||||
|
$preference->data = 'en';
|
||||||
|
$preference->save();
|
||||||
|
|
||||||
|
// mock language preference:
|
||||||
|
Preferences::shouldReceive('get')->withArgs(['language', 'en'])->andReturn($preference);
|
||||||
|
|
||||||
|
// mock Steam::balance
|
||||||
|
Steam::shouldReceive('balance')->withAnyArgs()->andReturn(0);
|
||||||
|
|
||||||
|
// data for call:
|
||||||
|
$start = Carbon::createFromDate(2015, 1, 1);
|
||||||
|
$end = Carbon::createFromDate(2015, 1, 15);
|
||||||
|
$account = FactoryMuffin::create('FireflyIII\Models\Account');
|
||||||
|
|
||||||
|
// call
|
||||||
|
$result = $this->object->single($account, $start, $end);
|
||||||
|
|
||||||
|
|
||||||
|
// test
|
||||||
|
$this->assertCount(15, $result['labels']);
|
||||||
|
$this->assertEquals($account->name, $result['datasets'][0]['label']);
|
||||||
|
$this->assertCount(15, $result['datasets'][0]['data']);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user