added option to delete invoice template (#294)
This commit is contained in:
@@ -9,7 +9,9 @@
|
||||
|
||||
namespace App\Tests\Controller;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use App\Entity\User;
|
||||
use App\Tests\DataFixtures\InvoiceFixtures;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Controller\InvoiceController
|
||||
@@ -23,12 +25,59 @@ class InvoiceControllerTest extends ControllerBaseTest
|
||||
$this->assertUrlIsSecuredForRole(User::ROLE_USER, '/invoice/');
|
||||
}
|
||||
|
||||
public function testIndexAction()
|
||||
public function testIndexActionRedirectsToCreateTemplate()
|
||||
{
|
||||
$this->markTestSkipped('create invoice template before this test case');
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_TEAMLEAD);
|
||||
|
||||
$this->request($client, '/invoice/');
|
||||
$this->assertIsRedirect($client, '/invoice/template/create');
|
||||
}
|
||||
|
||||
public function testIndexActionHasErrorMessageOnEmptyQuery()
|
||||
{
|
||||
$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/');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertMainContentClass($client, 'dashboard');
|
||||
|
||||
$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());
|
||||
}
|
||||
|
||||
public function testListTemplateAction()
|
||||
{
|
||||
$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/template');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasDataTable($client);
|
||||
}
|
||||
|
||||
public function testDeleteTemplateAction()
|
||||
{
|
||||
$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/template/1/delete?page=1');
|
||||
$this->assertIsRedirect($client, '/invoice/template/page/1');
|
||||
$client->followRedirect();
|
||||
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
$this->assertHasFlashSuccess($client);
|
||||
|
||||
$this->assertEquals(0, $em->getRepository(InvoiceTemplate::class)->count([]));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ use App\Entity\User;
|
||||
use Symfony\Component\Security\Core\Encoder\EncoderFactoryInterface;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \App\Controller\InvoiceController
|
||||
* @coversDefaultClass \App\Controller\ProfileController
|
||||
* @group integration
|
||||
*/
|
||||
class ProfileControllerTest extends ControllerBaseTest
|
||||
|
||||
61
tests/DataFixtures/InvoiceFixtures.php
Normal file
61
tests/DataFixtures/InvoiceFixtures.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?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\DataFixtures;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\Persistence\ObjectManager;
|
||||
use Faker\Factory;
|
||||
|
||||
/**
|
||||
* Defines the sample data to load in during controller tests.
|
||||
*/
|
||||
class InvoiceFixtures extends Fixture
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$this->loadInvoiceTemplates($manager);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ObjectManager $manager
|
||||
*/
|
||||
private function loadInvoiceTemplates(ObjectManager $manager)
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
$template = new InvoiceTemplate();
|
||||
$template
|
||||
->setName('Invoice')
|
||||
->setTitle('Your company name')
|
||||
->setCompany($faker->company)
|
||||
->setVat(19)
|
||||
->setDueDays(14)
|
||||
->setPaymentTerms(
|
||||
'I would like to thank you for your confidence and will gladly be there for you in the future.' .
|
||||
PHP_EOL .
|
||||
'Please transfer the total amount within 14 days to the given account and use the invoice number ' .
|
||||
'as reference.'
|
||||
)
|
||||
->setAddress(
|
||||
$faker->streetAddress . PHP_EOL .
|
||||
$faker->city . ', ' . $faker->stateAbbr . ' ' . $faker->postcode . PHP_EOL .
|
||||
'Phone: ' . $faker->phoneNumber . PHP_EOL .
|
||||
'Email: ' . $faker->safeEmail
|
||||
)
|
||||
;
|
||||
|
||||
$manager->persist($template);
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user