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:
@@ -7,7 +7,7 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Twig;
|
||||
namespace App\Tests\Command;
|
||||
|
||||
use App\Command\CreateUserCommand;
|
||||
use App\Entity\User;
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace App\Tests\Controller;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\InvoiceFixtures;
|
||||
use App\Tests\DataFixtures\TimesheetFixtures;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Controller\InvoiceController
|
||||
@@ -46,7 +47,7 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
|
||||
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
|
||||
$this->assertNotEmpty($node->text());
|
||||
$this->assertContains('Before you can create an invoice, you have to select at least a customer filter.', $node->text());
|
||||
$this->assertContains('No invoice entries were found based on your selected filters.', $node->text());
|
||||
}
|
||||
|
||||
public function testListTemplateAction()
|
||||
@@ -84,10 +85,88 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
$this->assertIsRedirect($client, $this->createUrl('/invoice/template'));
|
||||
$client->followRedirect();
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$this->assertHasFlashSuccess($client);
|
||||
}
|
||||
|
||||
public function testPrintAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new InvoiceFixtures();
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$begin = new \DateTime('first day of this month');
|
||||
$end = new \DateTime('last day of this month');
|
||||
$fixture = new TimesheetFixtures();
|
||||
$fixture
|
||||
->setUser($this->getUserByRole($em, User::ROLE_TEAMLEAD))
|
||||
->setAmount(20)
|
||||
->setStartDate($begin)
|
||||
;
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->request($client, '/invoice/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
|
||||
$client->submit($form, [
|
||||
'template' => 1,
|
||||
'user' => '',
|
||||
'begin' => $begin->format('Y-m-d'),
|
||||
'end' => $end->format('Y-m-d'),
|
||||
'customer' => 1,
|
||||
]);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$node = $client->getCrawler()->filter('div.callout.callout-warning.lead');
|
||||
$this->assertEquals(0, $node->count());
|
||||
|
||||
$node = $client->getCrawler()->filter('div.callout.callout-success.lead');
|
||||
$this->assertNotEmpty($node->text());
|
||||
$this->assertContains('This is a preview of the data that will show up in your invoice document.', $node->text());
|
||||
|
||||
$node = $client->getCrawler()->filter('section.invoice div.table-responsive table.table-striped tbody tr');
|
||||
$this->assertEquals(20, $node->count());
|
||||
|
||||
$form = $client->getCrawler()->filter('#invoice-print-form')->form();
|
||||
$form->getFormNode()->setAttribute('action', $this->createUrl('/invoice/print'));
|
||||
$client->submit($form, [
|
||||
'template' => 1,
|
||||
'user' => '',
|
||||
'begin' => $begin->format('Y-m-d'),
|
||||
'end' => $end->format('Y-m-d'),
|
||||
'customer' => 1,
|
||||
'project' => 1,
|
||||
]);
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$node = $client->getCrawler()->filter('body');
|
||||
$this->assertEquals(1, $node->count());
|
||||
$this->assertEquals('invoice_print', $node->getIterator()[0]->getAttribute('class'));
|
||||
}
|
||||
|
||||
public function testPrintActionRedirectsToCreateTemplate()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
|
||||
$this->request($client, '/invoice/print');
|
||||
$this->assertIsRedirect($client, '/invoice/template/create');
|
||||
}
|
||||
|
||||
public function testPrintActionRedirectsToIndex()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
$em = $client->getContainer()->get('doctrine.orm.entity_manager');
|
||||
|
||||
$fixture = new InvoiceFixtures();
|
||||
$this->importFixture($em, $fixture);
|
||||
|
||||
$this->request($client, '/invoice/print');
|
||||
$this->assertIsRedirect($client, '/invoice/');
|
||||
}
|
||||
|
||||
public function testEditTemplateAction()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
|
||||
@@ -30,7 +30,7 @@ class SidebarControllerTest extends ControllerBaseTest
|
||||
$content = $client->getResponse()->getContent();
|
||||
|
||||
$this->assertContains('<ul class="control-sidebar-menu">', $content);
|
||||
$this->assertContains('<a href="/en/profile/'.$user->getUsername().'">', $content);
|
||||
$this->assertContains('<a href="/en/profile/' . $user->getUsername() . '">', $content);
|
||||
$this->assertContains('<select class="pull-right" onchange="window.location.href = this.options[this.selectedIndex].value;">', $content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,34 +56,46 @@ class TimesheetFixtures extends Fixture
|
||||
|
||||
/**
|
||||
* @param int $amount
|
||||
* @return $this
|
||||
*/
|
||||
public function setAmountRunning($amount)
|
||||
{
|
||||
$this->running = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $amount
|
||||
* @return $this
|
||||
*/
|
||||
public function setAmount($amount)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Activity[] $activities
|
||||
* @return $this
|
||||
*/
|
||||
public function setActivities(array $activities)
|
||||
{
|
||||
$this->activities = $activities;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
96
tests/Invoice/Calculator/AbstractInvoiceCalculatorTest.php
Normal file
96
tests/Invoice/Calculator/AbstractInvoiceCalculatorTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?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\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Invoice\CalculatorInterface;
|
||||
use App\Model\InvoiceModel;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class AbstractCalculatorTest extends TestCase
|
||||
{
|
||||
protected function assertEmptyModel(CalculatorInterface $sut)
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
$query = new InvoiceQuery();
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
$model->setQuery($query);
|
||||
|
||||
$sut->setModel($model);
|
||||
|
||||
$this->assertEquals(0, $sut->getTotal());
|
||||
$this->assertEquals(0, $sut->getVat());
|
||||
$this->assertEquals('EUR', $sut->getCurrency());
|
||||
$this->assertEquals(0, $sut->getSubtotal());
|
||||
$this->assertEquals(0, $sut->getTimeWorked());
|
||||
$this->assertEquals(0, count($sut->getEntries()));
|
||||
$this->assertEquals(0, $sut->getTax());
|
||||
}
|
||||
|
||||
protected function assertDescription(CalculatorInterface $sut, $addProject = false, $addActivity = false)
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
$template->setVat(19);
|
||||
|
||||
$project = new Project();
|
||||
$project->setName('project description');
|
||||
$project->setCustomer($customer);
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->setName('activity description');
|
||||
$activity->setProject($project);
|
||||
|
||||
$query = new InvoiceQuery();
|
||||
if ($addProject === true) {
|
||||
$query->setProject($project);
|
||||
} elseif ($addActivity === true) {
|
||||
$query->setActivity($activity);
|
||||
}
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet
|
||||
->setDescription('timesheet description')
|
||||
->setDuration(3600)
|
||||
->setRate(293.27)
|
||||
->setUser(new User())
|
||||
->setActivity((new Activity())->setName('foo'))
|
||||
;
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
$model->setEntries([$timesheet]);
|
||||
$model->setQuery($query);
|
||||
|
||||
$sut->setModel($model);
|
||||
$this->assertEquals(1, count($sut->getEntries()));
|
||||
|
||||
/** @var Timesheet $result */
|
||||
$result = $sut->getEntries()[0];
|
||||
if ($addProject === true) {
|
||||
$this->assertEquals('project description', $result->getDescription());
|
||||
} elseif ($addActivity === true) {
|
||||
$this->assertEquals('activity description', $result->getDescription());
|
||||
} else {
|
||||
$this->assertEquals('foo', $result->getDescription());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,38 +7,23 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Invoice;
|
||||
namespace App\Tests\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\DefaultCalculator;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Model\InvoiceModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\DefaultCalculator
|
||||
* @covers \App\Invoice\Calculator\DefaultCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractCalculator
|
||||
*/
|
||||
class DefaultCalculatorTest extends TestCase
|
||||
class DefaultCalculatorTest extends AbstractCalculatorTest
|
||||
{
|
||||
public function testEmptyModel()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
|
||||
$sut = new DefaultCalculator();
|
||||
$sut->setModel($model);
|
||||
|
||||
$this->assertEquals(0, $sut->getTotal());
|
||||
$this->assertEquals(0, $sut->getVat());
|
||||
$this->assertEquals('EUR', $sut->getCurrency());
|
||||
$this->assertEquals(0, $sut->getSubtotal());
|
||||
$this->assertEquals(0, $sut->getTimeWorked());
|
||||
$this->assertEquals([], $sut->getEntries());
|
||||
$this->assertEmptyModel(new DefaultCalculator());
|
||||
}
|
||||
|
||||
public function testWithMultipleEntries()
|
||||
@@ -69,6 +54,7 @@ class DefaultCalculatorTest extends TestCase
|
||||
$sut = new DefaultCalculator();
|
||||
$sut->setModel($model);
|
||||
|
||||
$this->assertEquals('default', $sut->getId());
|
||||
$this->assertEquals(581.17, $sut->getTotal());
|
||||
$this->assertEquals(19, $sut->getVat());
|
||||
$this->assertEquals('EUR', $sut->getCurrency());
|
||||
@@ -7,43 +7,26 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Invoice;
|
||||
namespace App\Tests\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Invoice\ShortInvoiceCalculator;
|
||||
use App\Entity\User;
|
||||
use App\Invoice\Calculator\ShortInvoiceCalculator;
|
||||
use App\Model\InvoiceModel;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\ShortInvoiceCalculator
|
||||
* @covers \App\Invoice\Calculator\ShortInvoiceCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractCalculator
|
||||
*/
|
||||
class ShortInvoiceCalculatorTest extends TestCase
|
||||
class ShortInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
{
|
||||
public function testEmptyModel()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
$query = new InvoiceQuery();
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
$model->setQuery($query);
|
||||
|
||||
$sut = new ShortInvoiceCalculator();
|
||||
$sut->setModel($model);
|
||||
|
||||
$this->assertEquals(0, $sut->getTotal());
|
||||
$this->assertEquals(0, $sut->getVat());
|
||||
$this->assertEquals('EUR', $sut->getCurrency());
|
||||
$this->assertEquals(0, $sut->getSubtotal());
|
||||
$this->assertEquals(0, $sut->getTimeWorked());
|
||||
$this->assertEquals(1, count($sut->getEntries()));
|
||||
$this->assertEmptyModel(new ShortInvoiceCalculator());
|
||||
}
|
||||
|
||||
public function testWithMultipleEntries()
|
||||
@@ -56,16 +39,34 @@ class ShortInvoiceCalculatorTest extends TestCase
|
||||
$activity->setName('activity description');
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet->setDuration(3600);
|
||||
$timesheet->setRate(293.27);
|
||||
$timesheet
|
||||
->setDuration(3600)
|
||||
->setRate(293.27)
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$timesheet2 = new Timesheet();
|
||||
$timesheet2->setDuration(400);
|
||||
$timesheet2->setRate(84);
|
||||
$timesheet2
|
||||
->setDuration(400)
|
||||
->setRate(84)
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$timesheet3 = new Timesheet();
|
||||
$timesheet3->setDuration(1800);
|
||||
$timesheet3->setRate(111.11);
|
||||
$timesheet3
|
||||
->setDuration(1800)
|
||||
->setRate(111.11)
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$entries = [$timesheet, $timesheet2, $timesheet3];
|
||||
|
||||
@@ -81,6 +82,7 @@ class ShortInvoiceCalculatorTest extends TestCase
|
||||
$sut = new ShortInvoiceCalculator();
|
||||
$sut->setModel($model);
|
||||
|
||||
$this->assertEquals('short', $sut->getId());
|
||||
$this->assertEquals(581.17, $sut->getTotal());
|
||||
$this->assertEquals(19, $sut->getVat());
|
||||
$this->assertEquals('EUR', $sut->getCurrency());
|
||||
@@ -95,30 +97,18 @@ class ShortInvoiceCalculatorTest extends TestCase
|
||||
$this->assertEquals(5800, $result->getDuration());
|
||||
}
|
||||
|
||||
public function testDescriptionByTimesheet()
|
||||
{
|
||||
$this->assertDescription(new ShortInvoiceCalculator(), false, false);
|
||||
}
|
||||
|
||||
public function testDescriptionByActivity()
|
||||
{
|
||||
$this->assertDescription(new ShortInvoiceCalculator(), false, true);
|
||||
}
|
||||
|
||||
public function testDescriptionByProject()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
$template->setVat(19);
|
||||
|
||||
$project = new Project();
|
||||
$project->setName('project description');
|
||||
|
||||
$query = new InvoiceQuery();
|
||||
$query->setProject($project);
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
$model->setEntries([]);
|
||||
$model->setQuery($query);
|
||||
|
||||
$sut = new ShortInvoiceCalculator();
|
||||
$sut->setModel($model);
|
||||
$this->assertEquals(1, count($sut->getEntries()));
|
||||
|
||||
/** @var Timesheet $result */
|
||||
$result = $sut->getEntries()[0];
|
||||
$this->assertEquals('project description', $result->getDescription());
|
||||
$this->assertDescription(new ShortInvoiceCalculator(), true, false);
|
||||
}
|
||||
}
|
||||
129
tests/Invoice/Calculator/UserInvoiceCalculatorTest.php
Normal file
129
tests/Invoice/Calculator/UserInvoiceCalculatorTest.php
Normal file
@@ -0,0 +1,129 @@
|
||||
<?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\Invoice\Calculator;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Invoice\Calculator\UserInvoiceCalculator;
|
||||
use App\Model\InvoiceModel;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Calculator\UserInvoiceCalculator
|
||||
* @covers \App\Invoice\Calculator\AbstractCalculator
|
||||
*/
|
||||
class UserInvoiceCalculatorTest extends AbstractCalculatorTest
|
||||
{
|
||||
public function testEmptyModel()
|
||||
{
|
||||
$this->assertEmptyModel(new UserInvoiceCalculator());
|
||||
}
|
||||
|
||||
public function testWithMultipleEntries()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
$template->setVat(19);
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->setName('activity description');
|
||||
|
||||
$user1 = $this->getMockBuilder(User::class)->setMethods(['getId'])->disableOriginalConstructor()->getMock();
|
||||
$user1->method('getId')->willReturn(1);
|
||||
|
||||
$user2 = $this->getMockBuilder(User::class)->setMethods(['getId'])->disableOriginalConstructor()->getMock();
|
||||
$user2->method('getId')->willReturn(2);
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet
|
||||
->setDuration(3600)
|
||||
->setRate(293.27)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
;
|
||||
|
||||
$timesheet2 = new Timesheet();
|
||||
$timesheet2
|
||||
->setDuration(400)
|
||||
->setRate(84.75)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
;
|
||||
|
||||
$timesheet3 = new Timesheet();
|
||||
$timesheet3
|
||||
->setDuration(1800)
|
||||
->setRate(111.11)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
;
|
||||
|
||||
$timesheet4 = new Timesheet();
|
||||
$timesheet4
|
||||
->setDuration(400)
|
||||
->setRate(1947.99)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
;
|
||||
|
||||
$timesheet5 = new Timesheet();
|
||||
$timesheet5
|
||||
->setDuration(400)
|
||||
->setRate(84)
|
||||
->setUser(new User())
|
||||
->setActivity($activity)
|
||||
;
|
||||
|
||||
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
|
||||
|
||||
$query = new InvoiceQuery();
|
||||
$query->setActivity($activity);
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
$model->setEntries($entries);
|
||||
$model->setQuery($query);
|
||||
|
||||
$sut = new UserInvoiceCalculator();
|
||||
$sut->setModel($model);
|
||||
|
||||
$this->assertEquals('user', $sut->getId());
|
||||
$this->assertEquals(3000.13, $sut->getTotal());
|
||||
$this->assertEquals(19, $sut->getVat());
|
||||
$this->assertEquals('EUR', $sut->getCurrency());
|
||||
$this->assertEquals(2521.12, $sut->getSubtotal());
|
||||
$this->assertEquals(6600, $sut->getTimeWorked());
|
||||
$this->assertEquals(3, count($sut->getEntries()));
|
||||
|
||||
$entries = $sut->getEntries();
|
||||
$this->assertEquals(404.38, $entries[0]->getRate());
|
||||
$this->assertEquals(2032.74, $entries[1]->getRate());
|
||||
$this->assertEquals(84, $entries[2]->getRate());
|
||||
}
|
||||
|
||||
public function testDescriptionByTimesheet()
|
||||
{
|
||||
$this->assertDescription(new UserInvoiceCalculator(), false, false);
|
||||
}
|
||||
|
||||
public function testDescriptionByActivity()
|
||||
{
|
||||
$this->assertDescription(new UserInvoiceCalculator(), false, true);
|
||||
}
|
||||
|
||||
public function testDescriptionByProject()
|
||||
{
|
||||
$this->assertDescription(new UserInvoiceCalculator(), true, false);
|
||||
}
|
||||
}
|
||||
29
tests/Invoice/NumberGenerator/DateNumberGeneratorTest.php
Normal file
29
tests/Invoice/NumberGenerator/DateNumberGeneratorTest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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\Invoice\Calculator;
|
||||
|
||||
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
||||
use App\Model\InvoiceModel;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\NumberGenerator\DateNumberGenerator
|
||||
*/
|
||||
class DateNumberGeneratorTest extends TestCase
|
||||
{
|
||||
public function testGetInvoiceNumber()
|
||||
{
|
||||
$sut = new DateNumberGenerator();
|
||||
$sut->setModel(new InvoiceModel());
|
||||
|
||||
$this->assertEquals(date('ymd'), $sut->getInvoiceNumber());
|
||||
$this->assertEquals('default', $sut->getId());
|
||||
}
|
||||
}
|
||||
176
tests/Invoice/Renderer/AbstractRendererTest.php
Normal file
176
tests/Invoice/Renderer/AbstractRendererTest.php
Normal file
@@ -0,0 +1,176 @@
|
||||
<?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\Invoice\Renderer;
|
||||
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Customer;
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Entity\User;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
||||
use App\Invoice\Renderer\AbstractRenderer;
|
||||
use App\Model\InvoiceModel;
|
||||
use App\Repository\Query\InvoiceQuery;
|
||||
use App\Twig\DateExtensions;
|
||||
use App\Twig\Extensions;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\RequestStack;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
|
||||
abstract class AbstractRendererTest extends KernelTestCase
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getInvoiceTemplatePath()
|
||||
{
|
||||
return __DIR__ . '/../../../templates/invoice/renderer/';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $filename
|
||||
* @return InvoiceDocument
|
||||
*/
|
||||
protected function getInvoiceDocument(string $filename)
|
||||
{
|
||||
return new InvoiceDocument(
|
||||
new \SplFileInfo($this->getInvoiceTemplatePath() . $filename)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $classname
|
||||
* @return AbstractRenderer
|
||||
*/
|
||||
protected function getAbstractRenderer(string $classname)
|
||||
{
|
||||
$requestStack = new RequestStack();
|
||||
$dateSettings = [];
|
||||
$languages = [];
|
||||
|
||||
$request = new Request();
|
||||
$request->setLocale('en');
|
||||
$requestStack->push($request);
|
||||
|
||||
$translator = $this->getMockBuilder(TranslatorInterface::class)->getMock();
|
||||
$dateExtension = new DateExtensions($requestStack, $dateSettings);
|
||||
$extensions = new Extensions($requestStack, $languages);
|
||||
|
||||
return new $classname($translator, $dateExtension, $extensions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return InvoiceModel
|
||||
*/
|
||||
protected function getInvoiceModel()
|
||||
{
|
||||
$customer = new Customer();
|
||||
$template = new InvoiceTemplate();
|
||||
$template->setTitle('a test invoice template title');
|
||||
$template->setVat(19);
|
||||
|
||||
$project = new Project();
|
||||
$project->setName('project name');
|
||||
$project->setCustomer($customer);
|
||||
|
||||
$activity = new Activity();
|
||||
$activity->setName('activity description');
|
||||
$activity->setProject($project);
|
||||
|
||||
$userMethods = ['getId', 'getPreferenceValue', 'getUsername'];
|
||||
$user1 = $this->getMockBuilder(User::class)->setMethods($userMethods)->disableOriginalConstructor()->getMock();
|
||||
$user1->method('getId')->willReturn(1);
|
||||
$user1->method('getPreferenceValue')->willReturn('50');
|
||||
$user1->method('getUsername')->willReturn('foo-bar');
|
||||
|
||||
$user2 = $this->getMockBuilder(User::class)->setMethods($userMethods)->disableOriginalConstructor()->getMock();
|
||||
$user2->method('getId')->willReturn(2);
|
||||
$user2->method('getUsername')->willReturn('hello-world');
|
||||
|
||||
$timesheet = new Timesheet();
|
||||
$timesheet
|
||||
->setDuration(3600)
|
||||
->setRate(293.27)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$timesheet2 = new Timesheet();
|
||||
$timesheet2
|
||||
->setDuration(400)
|
||||
->setRate(84.75)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$timesheet3 = new Timesheet();
|
||||
$timesheet3
|
||||
->setDuration(1800)
|
||||
->setRate(111.11)
|
||||
->setUser($user1)
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$timesheet4 = new Timesheet();
|
||||
$timesheet4
|
||||
->setDuration(400)
|
||||
->setRate(1947.99)
|
||||
->setUser($user2)
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$timesheet5 = new Timesheet();
|
||||
$timesheet5
|
||||
->setDuration(400)
|
||||
->setFixedRate(84)
|
||||
->setUser((new User())->setUsername('kevin'))
|
||||
->setActivity($activity)
|
||||
->setBegin(new \DateTime())
|
||||
->setEnd(new \DateTime())
|
||||
;
|
||||
|
||||
$entries = [$timesheet, $timesheet2, $timesheet3, $timesheet4, $timesheet5];
|
||||
|
||||
$query = new InvoiceQuery();
|
||||
$query->setActivity($activity);
|
||||
$query->setBegin(new \DateTime());
|
||||
$query->setEnd(new \DateTime());
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$model->setCustomer($customer);
|
||||
$model->setTemplate($template);
|
||||
$model->setEntries($entries);
|
||||
$model->setQuery($query);
|
||||
|
||||
$calculator = new DefaultCalculator();
|
||||
$calculator->setModel($model);
|
||||
|
||||
$model->setCalculator($calculator);
|
||||
|
||||
$numberGenerator = new DateNumberGenerator();
|
||||
$numberGenerator->setModel($model);
|
||||
|
||||
$model->setNumberGenerator($numberGenerator);
|
||||
|
||||
return $model;
|
||||
}
|
||||
}
|
||||
67
tests/Invoice/Renderer/CsvRendererTest.php
Normal file
67
tests/Invoice/Renderer/CsvRendererTest.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?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\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\CsvRenderer;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\CsvRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
||||
*/
|
||||
class CsvRendererTest extends AbstractRendererTest
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
||||
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('foo.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('export.csv')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods')));
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
/** @var CsvRenderer $sut */
|
||||
$sut = $this->getAbstractRenderer(CsvRenderer::class);
|
||||
$model = $this->getInvoiceModel();
|
||||
$document = $this->getInvoiceDocument('export.csv');
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('text/csv', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=export.csv', $response->headers->get('Content-Disposition'));
|
||||
|
||||
$this->assertTrue(file_exists($file->getRealPath()));
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
|
||||
$this->assertNotContains('${', $content);
|
||||
$this->assertContains(',"1,947.99"', $content);
|
||||
$this->assertEquals(6, substr_count($content, PHP_EOL));
|
||||
$this->assertEquals(5, substr_count($content, 'activity description'));
|
||||
$this->assertEquals(1, substr_count($content, ',"kevin",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"hello-world",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"foo-bar",'));
|
||||
|
||||
ob_start();
|
||||
$response->sendContent();
|
||||
$content2 = ob_get_clean();
|
||||
|
||||
$this->assertEquals($content, $content2);
|
||||
$this->assertFalse(file_exists($file->getRealPath()));
|
||||
}
|
||||
}
|
||||
69
tests/Invoice/Renderer/DocxRendererTest.php
Normal file
69
tests/Invoice/Renderer/DocxRendererTest.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?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\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\DocxRenderer;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\DocxRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
*/
|
||||
class DocxRendererTest extends AbstractRendererTest
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(DocxRenderer::class);
|
||||
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('foo.html.twig')));
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('company.docx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('export.csv')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods')));
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
/** @var DocxRenderer $sut */
|
||||
$sut = $this->getAbstractRenderer(DocxRenderer::class);
|
||||
$model = $this->getInvoiceModel();
|
||||
$document = $this->getInvoiceDocument('company.docx');
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('application/vnd.openxmlformats-officedocument.wordprocessingml.document', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=company.docx', $response->headers->get('Content-Disposition'));
|
||||
|
||||
$this->assertTrue(file_exists($file->getRealPath()));
|
||||
|
||||
// TODO test document content?
|
||||
/*
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
$this->assertNotContains('${', $content);
|
||||
$this->assertContains(',"1,947.99" ', $content);
|
||||
$this->assertEquals(6, substr_count($content, PHP_EOL));
|
||||
$this->assertEquals(5, substr_count($content, 'activity description'));
|
||||
$this->assertEquals(1, substr_count($content, ',"kevin",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"hello-world",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"foo-bar",'));
|
||||
*/
|
||||
|
||||
ob_start();
|
||||
$response->sendContent();
|
||||
$content2 = ob_get_clean();
|
||||
$this->assertNotEmpty($content2);
|
||||
|
||||
$this->assertFalse(file_exists($file->getRealPath()));
|
||||
}
|
||||
}
|
||||
70
tests/Invoice/Renderer/OdsRendererTest.php
Normal file
70
tests/Invoice/Renderer/OdsRendererTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\OdsRenderer;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\OdsRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
||||
*/
|
||||
class OdsRendererTest extends AbstractRendererTest
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(OdsRenderer::class);
|
||||
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('foo.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('export.csv')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx')));
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods')));
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
/** @var OdsRenderer $sut */
|
||||
$sut = $this->getAbstractRenderer(OdsRenderer::class);
|
||||
$model = $this->getInvoiceModel();
|
||||
$document = $this->getInvoiceDocument('open-spreadsheet.ods');
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=open-spreadsheet.ods', $response->headers->get('Content-Disposition'));
|
||||
|
||||
$this->assertTrue(file_exists($file->getRealPath()));
|
||||
|
||||
// TODO test spreadsheet content?
|
||||
/*
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
$this->assertNotContains('${', $content);
|
||||
$this->assertContains(',"1,947.99" ', $content);
|
||||
$this->assertEquals(6, substr_count($content, PHP_EOL));
|
||||
$this->assertEquals(5, substr_count($content, 'activity description'));
|
||||
$this->assertEquals(1, substr_count($content, ',"kevin",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"hello-world",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"foo-bar",'));
|
||||
*/
|
||||
|
||||
ob_start();
|
||||
$response->sendContent();
|
||||
$content2 = ob_get_clean();
|
||||
$this->assertNotEmpty($content2);
|
||||
|
||||
$this->assertFalse(file_exists($file->getRealPath()));
|
||||
}
|
||||
}
|
||||
65
tests/Invoice/Renderer/TwigRendererTest.php
Normal file
65
tests/Invoice/Renderer/TwigRendererTest.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\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\TwigRenderer;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Twig\Loader\FilesystemLoader;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\TwigRenderer
|
||||
*/
|
||||
class TwigRendererTest extends AbstractRendererTest
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new FilesystemLoader();
|
||||
$env = new \Twig_Environment($loader);
|
||||
$sut = new TwigRenderer($env);
|
||||
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('default.html.twig')));
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('freelancer.html.twig')));
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('foo.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('export.csv')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods')));
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
$kernel = self::bootKernel();
|
||||
/** @var \Twig_Environment $twig */
|
||||
$twig = $kernel->getContainer()->get('twig');
|
||||
$stack = $kernel->getContainer()->get('request_stack');
|
||||
$request = new Request();
|
||||
$request->setLocale('en');
|
||||
$stack->push($request);
|
||||
|
||||
/** @var FilesystemLoader $loader */
|
||||
$loader = $twig->getLoader();
|
||||
$loader->addPath($this->getInvoiceTemplatePath(), 'invoice');
|
||||
|
||||
$sut = new TwigRenderer($twig);
|
||||
|
||||
$model = $this->getInvoiceModel();
|
||||
|
||||
$document = $this->getInvoiceDocument('timesheet.html.twig');
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$content = $response->getContent();
|
||||
|
||||
$this->assertContains('<h2 class="page-header">
|
||||
<span contenteditable="true">a test invoice template title</span>
|
||||
</h2>', $content);
|
||||
$this->assertEquals(5, substr_count($content, '<td>activity description / project name</td>'));
|
||||
}
|
||||
}
|
||||
70
tests/Invoice/Renderer/XlsxRendererTest.php
Normal file
70
tests/Invoice/Renderer/XlsxRendererTest.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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\Invoice\Renderer;
|
||||
|
||||
use App\Invoice\Renderer\XlsxRenderer;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @covers \App\Invoice\Renderer\XlsxRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractRenderer
|
||||
* @covers \App\Invoice\Renderer\AbstractSpreadsheetRenderer
|
||||
*/
|
||||
class XlsxRendererTest extends AbstractRendererTest
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$sut = $this->getAbstractRenderer(XlsxRenderer::class);
|
||||
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('default.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('freelancer.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('timesheet.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('foo.html.twig')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('company.docx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('export.csv')));
|
||||
$this->assertTrue($sut->supports($this->getInvoiceDocument('spreadsheet.xlsx')));
|
||||
$this->assertFalse($sut->supports($this->getInvoiceDocument('open-spreadsheet.ods')));
|
||||
}
|
||||
|
||||
public function testRender()
|
||||
{
|
||||
/** @var XlsxRenderer $sut */
|
||||
$sut = $this->getAbstractRenderer(XlsxRenderer::class);
|
||||
$model = $this->getInvoiceModel();
|
||||
$document = $this->getInvoiceDocument('spreadsheet.xlsx');
|
||||
/** @var BinaryFileResponse $response */
|
||||
$response = $sut->render($document, $model);
|
||||
|
||||
$file = $response->getFile();
|
||||
$this->assertEquals('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', $response->headers->get('Content-Type'));
|
||||
$this->assertEquals('attachment; filename=spreadsheet.xlsx', $response->headers->get('Content-Disposition'));
|
||||
|
||||
$this->assertTrue(file_exists($file->getRealPath()));
|
||||
|
||||
// TODO test document content?
|
||||
/*
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
$this->assertNotContains('${', $content);
|
||||
$this->assertContains(',"1,947.99" ', $content);
|
||||
$this->assertEquals(6, substr_count($content, PHP_EOL));
|
||||
$this->assertEquals(5, substr_count($content, 'activity description'));
|
||||
$this->assertEquals(1, substr_count($content, ',"kevin",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"hello-world",'));
|
||||
$this->assertEquals(2, substr_count($content, ',"foo-bar",'));
|
||||
*/
|
||||
|
||||
ob_start();
|
||||
$response->sendContent();
|
||||
$content2 = ob_get_clean();
|
||||
$this->assertNotEmpty($content2);
|
||||
|
||||
$this->assertFalse(file_exists($file->getRealPath()));
|
||||
}
|
||||
}
|
||||
77
tests/Invoice/ServiceInvoiceTest.php
Normal file
77
tests/Invoice/ServiceInvoiceTest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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\Invoice;
|
||||
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Invoice\Calculator\DefaultCalculator;
|
||||
use App\Invoice\NumberGenerator\DateNumberGenerator;
|
||||
use App\Invoice\Renderer\TwigRenderer;
|
||||
use App\Invoice\ServiceInvoice;
|
||||
use App\Repository\InvoiceDocumentRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ServiceInvoiceTest extends TestCase
|
||||
{
|
||||
public function testEmptyObject()
|
||||
{
|
||||
$repo = new InvoiceDocumentRepository([]);
|
||||
$sut = new ServiceInvoice($repo);
|
||||
|
||||
$this->assertEmpty($sut->getCalculator());
|
||||
$this->assertInternalType('array', $sut->getCalculator());
|
||||
$this->assertEmpty($sut->getRenderer());
|
||||
$this->assertInternalType('array', $sut->getRenderer());
|
||||
$this->assertEmpty($sut->getNumberGenerator());
|
||||
$this->assertInternalType('array', $sut->getNumberGenerator());
|
||||
$this->assertEmpty($sut->getDocuments());
|
||||
$this->assertInternalType('array', $sut->getDocuments());
|
||||
|
||||
$this->assertNull($sut->getCalculatorByName('default'));
|
||||
$this->assertNull($sut->getDocumentByName('default'));
|
||||
$this->assertNull($sut->getNumberGeneratorByName('default'));
|
||||
}
|
||||
|
||||
public function testWithDocumentDirectory()
|
||||
{
|
||||
$repo = new InvoiceDocumentRepository(['templates/invoice/renderer/']);
|
||||
$sut = new ServiceInvoice($repo);
|
||||
|
||||
$actual = $sut->getDocuments();
|
||||
$this->assertNotEmpty($actual);
|
||||
foreach ($actual as $document) {
|
||||
$this->assertInstanceOf(InvoiceDocument::class, $document);
|
||||
}
|
||||
|
||||
$actual = $sut->getDocumentByName('default');
|
||||
$this->assertInstanceOf(InvoiceDocument::class, $actual);
|
||||
}
|
||||
|
||||
public function testAdd()
|
||||
{
|
||||
$repo = new InvoiceDocumentRepository([]);
|
||||
$sut = new ServiceInvoice($repo);
|
||||
|
||||
$sut->addCalculator(new DefaultCalculator());
|
||||
$sut->addNumberGenerator(new DateNumberGenerator());
|
||||
$sut->addRenderer(
|
||||
new TwigRenderer(
|
||||
$this->getMockBuilder(\Twig_Environment::class)->disableOriginalConstructor()->getMock()
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertEquals(1, count($sut->getCalculator()));
|
||||
$this->assertInstanceOf(DefaultCalculator::class, $sut->getCalculatorByName('default'));
|
||||
|
||||
$this->assertEquals(1, count($sut->getNumberGenerator()));
|
||||
$this->assertInstanceOf(DateNumberGenerator::class, $sut->getNumberGeneratorByName('default'));
|
||||
|
||||
$this->assertEquals(1, count($sut->getRenderer()));
|
||||
}
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
60
tests/Repository/InvoiceDocumentRepositoryTest.php
Normal file
60
tests/Repository/InvoiceDocumentRepositoryTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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\Repository;
|
||||
|
||||
use App\Entity\InvoiceDocument;
|
||||
use App\Repository\InvoiceDocumentRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* @covers \App\Repository\InvoiceDocumentRepository
|
||||
*/
|
||||
class InvoiceDocumentRepositoryTest extends TestCase
|
||||
{
|
||||
protected static $defaultDirectories = [
|
||||
'templates/invoice/renderer'
|
||||
];
|
||||
|
||||
protected static $defaultDocuments = [
|
||||
'company.docx',
|
||||
'default.html.twig',
|
||||
'export.csv',
|
||||
'freelancer.html.twig',
|
||||
'open-spreadsheet.ods',
|
||||
'spreadsheet.xlsx',
|
||||
'timesheet.html.twig',
|
||||
];
|
||||
|
||||
public function testWithEmptyDirectory()
|
||||
{
|
||||
$sut = new InvoiceDocumentRepository([]);
|
||||
$this->assertEmpty($sut->findAll());
|
||||
$this->assertInternalType('array', $sut->findAll());
|
||||
$this->assertNull($sut->findByName('default'));
|
||||
}
|
||||
|
||||
public function testDefaultTemplatesExists()
|
||||
{
|
||||
$sut = new InvoiceDocumentRepository(self::$defaultDirectories);
|
||||
$all = $sut->findAll();
|
||||
$this->assertEquals(count(self::$defaultDocuments), count($all));
|
||||
|
||||
foreach ($all as $document) {
|
||||
$this->assertTrue(in_array($document->getName(), self::$defaultDocuments));
|
||||
}
|
||||
|
||||
foreach (self::$defaultDocuments as $filename) {
|
||||
$filename = substr($filename, 0, strpos($filename, '.'));
|
||||
$actual = $sut->findByName($filename);
|
||||
$this->assertNotNull($actual);
|
||||
$this->assertInstanceOf(InvoiceDocument::class, $actual);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,48 +157,6 @@ class RateCalculatorTest extends TestCase
|
||||
$this->assertEquals(0, $record->getRate());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getDisallowedFactors
|
||||
*/
|
||||
public function testCalculateWithInvalidFactor($factor)
|
||||
{
|
||||
$today = new \DateTime();
|
||||
$day = $today->format('l');
|
||||
$rules = [
|
||||
'default' => [
|
||||
'days' => [$day],
|
||||
'factor' => $factor
|
||||
],
|
||||
];
|
||||
$seconds = 41837;
|
||||
|
||||
$end = new \DateTime();
|
||||
$start = clone $end;
|
||||
$start->setTimestamp($end->getTimestamp() - $seconds);
|
||||
|
||||
$record = new Timesheet();
|
||||
$record->setUser($this->getTestUser());
|
||||
$record->setBegin($start);
|
||||
$record->setDuration($seconds);
|
||||
$record->setActivity(new Activity());
|
||||
|
||||
$this->assertEquals(0, $record->getRate());
|
||||
|
||||
$record->setEnd($end);
|
||||
|
||||
$sut = new RateCalculator($rules);
|
||||
$sut->calculate($record);
|
||||
}
|
||||
|
||||
public function getDisallowedFactors()
|
||||
{
|
||||
return [
|
||||
[0],
|
||||
[-1],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getRuleDefinitions
|
||||
*/
|
||||
|
||||
@@ -124,6 +124,7 @@ class ExtensionsTest extends TestCase
|
||||
public function getMoneyData()
|
||||
{
|
||||
return [
|
||||
['0 €', null, 'EUR', 'de'],
|
||||
['2.345 €', 2345, 'EUR', 'de'],
|
||||
['2,345 €', 2345, 'EUR', 'en'],
|
||||
['2,345.01 €', 2345.009, 'EUR', 'en'],
|
||||
|
||||
@@ -41,6 +41,8 @@ class MarkdownExtensionTest extends TestCase
|
||||
"- test<br />\n- foo",
|
||||
$sut->timesheetContent("- test\n- foo")
|
||||
);
|
||||
$this->assertEquals('', $sut->timesheetContent(null));
|
||||
$this->assertEquals('', $sut->timesheetContent(''));
|
||||
|
||||
$sut = new MarkdownExtension(new Markdown(), true);
|
||||
$this->assertEquals(
|
||||
|
||||
Reference in New Issue
Block a user