improved invoices with new renderer (#306)
* added docx renderer and demo template * added csv renderer and demo template * added xlsx renderer and demo template * added ods renderer and demo template * added user calculator * added invoice documentation
This commit is contained in:
39
tests/Model/ActivityStatisticTest.php
Normal file
39
tests/Model/ActivityStatisticTest.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\ActivityStatistic;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\ActivityStatistic
|
||||
*/
|
||||
class ActivityStatisticTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new ActivityStatistic();
|
||||
$this->assertEquals(0, $sut->getCount());
|
||||
$this->assertEquals(0, $sut->getRecordAmount());
|
||||
$this->assertEquals(0, $sut->getRecordDuration());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new ActivityStatistic();
|
||||
$sut->setCount(123);
|
||||
$sut->setRecordAmount(7654.298);
|
||||
$sut->setRecordDuration(826.10);
|
||||
|
||||
$this->assertEquals(123, $sut->getCount());
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
}
|
||||
}
|
||||
45
tests/Model/CustomerStatisticTest.php
Normal file
45
tests/Model/CustomerStatisticTest.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\CustomerStatistic;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\CustomerStatistic
|
||||
*/
|
||||
class CustomerStatisticTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new CustomerStatistic();
|
||||
$this->assertEquals(0, $sut->getActivityAmount());
|
||||
$this->assertEquals(0, $sut->getProjectAmount());
|
||||
$this->assertEquals(0, $sut->getCount());
|
||||
$this->assertEquals(0, $sut->getRecordAmount());
|
||||
$this->assertEquals(0, $sut->getRecordDuration());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new CustomerStatistic();
|
||||
$sut->setCount(123);
|
||||
$sut->setRecordAmount(7654.298);
|
||||
$sut->setRecordDuration(826.10);
|
||||
$sut->setActivityAmount(13);
|
||||
$sut->setProjectAmount(2);
|
||||
|
||||
$this->assertEquals(13, $sut->getActivityAmount());
|
||||
$this->assertEquals(2, $sut->getProjectAmount());
|
||||
$this->assertEquals(123, $sut->getCount());
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
}
|
||||
}
|
||||
42
tests/Model/DashboardSectionTest.php
Normal file
42
tests/Model/DashboardSectionTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\DashboardSection;
|
||||
use App\Model\Widget;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\DashboardSection
|
||||
*/
|
||||
class DashboardSectionTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new DashboardSection('test');
|
||||
$this->assertEquals('test', $sut->getTitle());
|
||||
$this->assertEquals(0, $sut->getOrder());
|
||||
$this->assertEquals([], $sut->getWidgets());
|
||||
$this->assertEquals(DashboardSection::TYPE_SIMPLE, $sut->getType());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new DashboardSection('hello-world');
|
||||
$sut->setType(DashboardSection::TYPE_CHART);
|
||||
$sut->setOrder(13);
|
||||
$sut->addWidget(new Widget('bar', []));
|
||||
|
||||
$this->assertCount(1, $sut->getWidgets());
|
||||
$this->assertEquals(DashboardSection::TYPE_CHART, $sut->getType());
|
||||
$this->assertEquals(13, $sut->getOrder());
|
||||
$this->assertEquals('bar', $sut->getWidgets()[0]->getTitle());
|
||||
}
|
||||
}
|
||||
65
tests/Model/InvoiceModelTest.php
Normal file
65
tests/Model/InvoiceModelTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
||||
use App\Model\InvoiceModel;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\InvoiceModel
|
||||
*/
|
||||
class InvoiceModelTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new InvoiceModel();
|
||||
$this->assertNull($sut->getNumberGenerator());
|
||||
$this->assertNull($sut->getCalculator());
|
||||
$this->assertNull($sut->getTemplate());
|
||||
$this->assertNull($sut->getCustomer());
|
||||
$this->assertNull($sut->getQuery());
|
||||
$this->assertNull($sut->getDueDate());
|
||||
$this->assertEmpty($sut->getEntries());
|
||||
$this->assertInternalType('array', $sut->getEntries());
|
||||
$this->assertInstanceOf(\DateTime::class, $sut->getInvoiceDate());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new InvoiceModel();
|
||||
|
||||
$sut->setTemplate((new InvoiceTemplate())->setDueDays(10));
|
||||
$sut->setCustomer(new Customer());
|
||||
$sut->setQuery(new InvoiceQuery());
|
||||
$sut->setEntries([new Timesheet()]);
|
||||
$sut->setNumberGenerator(new DateNumberGenerator());
|
||||
$sut->setCalculator(new DefaultCalculator());
|
||||
|
||||
$this->assertInstanceOf(DateNumberGenerator::class, $sut->getNumberGenerator());
|
||||
$this->assertInstanceOf(DefaultCalculator::class, $sut->getCalculator());
|
||||
$this->assertInstanceOf(InvoiceTemplate::class, $sut->getTemplate());
|
||||
$this->assertInstanceOf(Customer::class, $sut->getCustomer());
|
||||
$this->assertInstanceOf(InvoiceQuery::class, $sut->getQuery());
|
||||
$this->assertInstanceOf(\DateTime::class, $sut->getDueDate());
|
||||
$this->assertInstanceOf(Timesheet::class, $sut->getEntries()[0]);
|
||||
$this->assertInstanceOf(\DateTime::class, $sut->getInvoiceDate());
|
||||
|
||||
$this->assertEquals(
|
||||
(new \DateTime('+10 days'))->format('Y-m-d'),
|
||||
$sut->getDueDate()->format('Y-m-d')
|
||||
);
|
||||
}
|
||||
}
|
||||
42
tests/Model/ProjectStatisticTest.php
Normal file
42
tests/Model/ProjectStatisticTest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\ProjectStatistic;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\ProjectStatistic
|
||||
*/
|
||||
class ProjectStatisticTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new ProjectStatistic();
|
||||
$this->assertEquals(0, $sut->getActivityAmount());
|
||||
$this->assertEquals(0, $sut->getCount());
|
||||
$this->assertEquals(0, $sut->getRecordAmount());
|
||||
$this->assertEquals(0, $sut->getRecordDuration());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new ProjectStatistic();
|
||||
$sut->setCount(123);
|
||||
$sut->setRecordAmount(7654.298);
|
||||
$sut->setRecordDuration(826.10);
|
||||
$sut->setActivityAmount(13);
|
||||
|
||||
$this->assertEquals(13, $sut->getActivityAmount());
|
||||
$this->assertEquals(123, $sut->getCount());
|
||||
$this->assertEquals(7654, $sut->getRecordAmount());
|
||||
$this->assertEquals(826, $sut->getRecordDuration());
|
||||
}
|
||||
}
|
||||
65
tests/Model/Statistic/MonthTest.php
Normal file
65
tests/Model/Statistic/MonthTest.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Month;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Month
|
||||
*/
|
||||
class MonthTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new Month('01');
|
||||
$this->assertEquals('01', $sut->getMonth());
|
||||
$this->assertEquals(0, $sut->getTotalDuration());
|
||||
$this->assertEquals(0, $sut->getTotalRate());
|
||||
}
|
||||
|
||||
public function testAllowedMonths()
|
||||
{
|
||||
for ($i = 1; $i < 10; $i++) {
|
||||
new Month('0' . $i);
|
||||
}
|
||||
for ($i = 10; $i < 13; $i++) {
|
||||
new Month((string) $i);
|
||||
}
|
||||
$this->assertTrue(true);
|
||||
}
|
||||
|
||||
public function testInvalidMonths()
|
||||
{
|
||||
foreach (['00', '13', '99', '0.9'] as $month) {
|
||||
$ex = null;
|
||||
try {
|
||||
new Month($month);
|
||||
} catch (\Exception $e) {
|
||||
$ex = $e;
|
||||
}
|
||||
$this->assertInstanceOf(\InvalidArgumentException::class, $ex);
|
||||
$this->assertEquals(
|
||||
'Invalid month given, expected 01-12 but given: ' . ((int) $month),
|
||||
$ex->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new Month('01');
|
||||
$sut->setTotalDuration(999.27);
|
||||
$sut->setTotalRate(0.123456789);
|
||||
|
||||
$this->assertEquals(999.27, $sut->getTotalDuration());
|
||||
$this->assertEquals(0.123456789, $sut->getTotalRate());
|
||||
}
|
||||
}
|
||||
48
tests/Model/Statistic/YearTest.php
Normal file
48
tests/Model/Statistic/YearTest.php
Normal file
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model\Statistic;
|
||||
|
||||
use App\Model\Statistic\Month;
|
||||
use App\Model\Statistic\Year;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\Statistic\Year
|
||||
*/
|
||||
class YearTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new Year('1999');
|
||||
$this->assertNull($sut->getMonth('01'));
|
||||
$this->assertEmpty($sut->getMonths());
|
||||
$this->assertInternalType('array', $sut->getMonths());
|
||||
$this->assertEquals('1999', $sut->getYear());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$sut = new Year('1999');
|
||||
|
||||
$sut->setMonth(new Month('01'));
|
||||
$sut->setMonth(new Month('02'));
|
||||
$sut->setMonth(new Month('03'));
|
||||
$this->assertEquals(3, count($sut->getMonths()));
|
||||
|
||||
$sut->setMonth(new Month('01'));
|
||||
|
||||
$this->assertEquals(3, count($sut->getMonths()));
|
||||
|
||||
$this->assertInstanceOf(Month::class, $sut->getMonth(1));
|
||||
$this->assertInstanceOf(Month::class, $sut->getMonth(2));
|
||||
$this->assertInstanceOf(Month::class, $sut->getMonth(3));
|
||||
$this->assertNull($sut->getMonth(4));
|
||||
}
|
||||
}
|
||||
50
tests/Model/TimesheetStatisticTest.php
Normal file
50
tests/Model/TimesheetStatisticTest.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai time-tracking app.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\TimesheetStatistic;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Model\TimesheetStatistic
|
||||
*/
|
||||
class TimesheetStatisticTest extends TestCase
|
||||
{
|
||||
public function testDefaultValues()
|
||||
{
|
||||
$sut = new TimesheetStatistic();
|
||||
$this->assertEquals(0, $sut->getRecordsTotal());
|
||||
$this->assertEquals(0, $sut->getAmountTotal());
|
||||
$this->assertEquals(0, $sut->getAmountThisMonth());
|
||||
$this->assertEquals(0, $sut->getDurationTotal());
|
||||
$this->assertEquals(0, $sut->getDurationThisMonth());
|
||||
$this->assertNull($sut->getFirstEntry());
|
||||
}
|
||||
|
||||
public function testSetter()
|
||||
{
|
||||
$date = new \DateTime();
|
||||
|
||||
$sut = new TimesheetStatistic();
|
||||
$sut->setRecordsTotal(2);
|
||||
$sut->setAmountTotal(7654.298);
|
||||
$sut->setAmountThisMonth(826.10);
|
||||
$sut->setDurationTotal(13);
|
||||
$sut->setDurationThisMonth(200);
|
||||
$sut->setFirstEntry($date);
|
||||
|
||||
$this->assertEquals(2, $sut->getRecordsTotal());
|
||||
$this->assertEquals(7654, $sut->getAmountTotal());
|
||||
$this->assertEquals(826, $sut->getAmountThisMonth());
|
||||
$this->assertEquals(13, $sut->getDurationTotal());
|
||||
$this->assertEquals(200, $sut->getDurationThisMonth());
|
||||
$this->assertSame($date, $sut->getFirstEntry());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user