Skip to content

Commit

Permalink
Merge pull request #86 from larriereguichet/release/v0.4.5
Browse files Browse the repository at this point in the history
v0.4.5
  • Loading branch information
johnkrovitch authored Jan 28, 2017
2 parents 473103b + a747e31 commit b7eb35a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 46 deletions.
8 changes: 2 additions & 6 deletions Event/Subscriber/TemplateSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@ public function __construct(Twig_Environment $twig, ConfigurationFactory $config
public static function getSubscribedEvents()
{
return [
KernelEvents::REQUEST => 'kernelView',
KernelEvents::CONTROLLER => 'kernelView',
];
}

/**
*
* @return null
*/

public function kernelView()
{
$this->twig->addGlobal('config', $this->configuration);
Expand Down
4 changes: 2 additions & 2 deletions Repository/DoctrineRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class DoctrineRepository extends EntityRepository implements Repository
public function save($entity)
{
$this->_em->persist($entity);
$this->_em->flush($entity);
$this->_em->flush();
}
/**
* Delete an entity.
Expand All @@ -27,6 +27,6 @@ public function save($entity)
public function delete($entity)
{
$this->_em->remove($entity);
$this->_em->flush($entity);
$this->_em->flush();
}
}
34 changes: 21 additions & 13 deletions Tests/AdminBundle/DependencyInjection/LAGAdminExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpKernel\KernelInterface;
use Twig_Loader_Array;

class LAGAdminExtensionTest extends AdminTestBase
{
Expand All @@ -40,7 +41,7 @@ public function testLoad()
'application' => []
]
], $container);
$this->assertCount(28, $container->getDefinitions());
$this->assertCount(29, $container->getDefinitions());

$eventDispatcherExtension = new FrameworkExtension();
$eventDispatcherExtension->load([], $container);
Expand Down Expand Up @@ -107,18 +108,23 @@ protected function assertServices(ContainerBuilder $container)
*/
protected function getWorkingContainer()
{
$generic = new Definition();
$generic->setClass(stdClass::class);
$fileLocator = new Definition();
$fileLocator->setClass(FileLocator::class);
$templateNameParser = new Definition();
$templateNameParser->setClass(TemplateNameParser::class);
$templateNameParser->addArgument($this->createMock(KernelInterface::class));
$logger = new Definition();
$logger->setClass(Logger::class);
$logger->addArgument('default');
$session= new Definition();
$session->setClass(Session::class);
$kernel = $this
->getMockBuilder(KernelInterface::class)
->disableOriginalConstructor()
->getMock()
;
$generic = new Definition(stdClass::class);
$fileLocator = new Definition(FileLocator::class);

$templateNameParser = new Definition(TemplateNameParser::class, [
$kernel,
]);

$logger = new Definition(Logger::class, [
'default'
]);
$session= new Definition(Session::class);
$twigLoader = new Definition(Twig_Loader_Array::class);

$entityManager = new Definition();
$entityManager->setClass(FakeEntityManager::class);
Expand All @@ -130,6 +136,7 @@ protected function getWorkingContainer()
$container->setParameter('kernel.charset', 'utf8');
$container->setParameter('kernel.secret', 'MyLittleSecret');
$container->setParameter('kernel.bundles', []);
$container->setParameter('kernel.bundles_metadata', []);
$container->setParameter('kernel.environment', 'prod');

$container->setDefinitions([
Expand All @@ -141,6 +148,7 @@ protected function getWorkingContainer()
'form.factory' => $generic,
'templating.locator' => $fileLocator,
'templating.name_parser' => $templateNameParser,
'twig.loader' => $twigLoader,
]);

return $container;
Expand Down
42 changes: 31 additions & 11 deletions Tests/AdminBundle/Field/ActionTest.php
Original file line number Diff line number Diff line change
@@ -1,40 +1,60 @@
<?php

namespace Tests\AdminBundle\Field;
namespace LAG\AdminBundle\Tests\AdminBundle\Field;

use LAG\AdminBundle\Field\Field\Action;
use LAG\AdminBundle\Tests\AdminTestBase;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\IdentityTranslator;
use Twig_Environment;

class ActionTest extends AdminTestBase
{
public function testRender()
{
$options = [];
$resolver = new OptionsResolver();

$linkField = new Action();
$linkField->setApplicationConfiguration($this->createApplicationConfiguration());
$linkField->configureOptions($resolver);

// an url or a route SHOULD be provided
$this->assertExceptionRaised(InvalidOptionsException::class, function() use ($linkField, $resolver, $options) {
$linkField->setOptions($resolver->resolve($options));
});

$options = [
'url' => 'http:/test.fr/'
'url' => 'http:/test.fr/',
'title' => 'MyAction'
];


$twig = $this
->getMockBuilder(Twig_Environment::class)
->disableOriginalConstructor()
->getMock()
;
$twig
->expects($this->once())
->method('render')
->with('LAGAdminBundle:Render:link.html.twig', [
'text' => 'MyAction',
'url' => $options['url'],
'route' => '',
'parameters' => [],
'target' => '_self',
'title' => 'MyAction',
'icon' => '',
])
->willReturn('<p>a string yeah !!! </p>')
;

$linkField->setOptions($resolver->resolve($options));
$linkField->setTranslator(new IdentityTranslator());
$linkField->setTwig($this->createTwigEnvironment());

$linkField->setTwig($twig);
$result = $linkField->render('test');

$this->assertEquals('LAGAdminBundle:Render:link.html.twig', $result['template']);
$this->assertEquals($options['url'], $result['parameters']['url']);
$this->assertInternalType('string', $result);
}
}
12 changes: 9 additions & 3 deletions Tests/AdminBundle/Field/DateTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Tests\AdminBundle\Field;
namespace LAG\AdminBundle\Tests\AdminBundle\Field;

use DateTime;
use LAG\AdminBundle\Field\Field\Date;
Expand All @@ -16,13 +16,19 @@ public function testRender()
'format' => 'd/m/Y',
];
$resolver = new OptionsResolver();


$twig = $this
->getMockBuilder(\Twig_Environment::class)
->disableOriginalConstructor()
->getMock()
;

$linkField = new Date();
$linkField->setApplicationConfiguration($this->createApplicationConfiguration());
$linkField->configureOptions($resolver);
$linkField->setOptions($resolver->resolve($options));
$linkField->setTranslator(new IdentityTranslator());
$linkField->setTwig($this->createTwigEnvironment());
$linkField->setTwig($twig);

$now = new DateTime();

Expand Down
37 changes: 26 additions & 11 deletions Tests/AdminBundle/Field/LinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Translation\IdentityTranslator;
use Test\TestBundle\Entity\TestEntity;
use Twig_Environment;

class LinkTest extends AdminTestBase
{
Expand All @@ -19,26 +20,40 @@ public function testRender()
],
'target' => '_blank',
'title' => 'MyTitle',
'icon' => 'fa-test'
'icon' => 'fa-test',
'template' => 'LAGAdminBundle:Render:link.html.twig',
];
$resolver = new OptionsResolver();


$twig = $this
->getMockBuilder(Twig_Environment::class)
->disableOriginalConstructor()
->getMock()
;
$twig
->expects($this->once())
->method('render')
->with('LAGAdminBundle:Render:link.html.twig', [
'text' => 'test',
'route' => 'route_test',
'parameters' => $options['parameters'],
'target' => '_blank',
'url' => '',
'title' => 'MyTitle',
'icon' => 'fa-test',
])
->willReturn('<p>lol man</p>')
;

$linkField = new Link();
$linkField->setApplicationConfiguration($this->createApplicationConfiguration());
$linkField->configureOptions($resolver);
$linkField->setOptions($resolver->resolve($options));
$linkField->setTranslator(new IdentityTranslator());
$linkField->setTwig($this->createTwigEnvironment());
$linkField->setTwig($twig);
$linkField->setEntity(new TestEntity());

$result = $linkField->render('test');

$this->assertEquals('LAGAdminBundle:Render:link.html.twig', $result['template']);
$this->assertEquals('test', $result['parameters']['text']);
$this->assertEquals('route_test', $result['parameters']['route']);
$this->assertEquals($options['parameters'], $result['parameters']['parameters']);
$this->assertEquals('_blank', $result['parameters']['target']);
$this->assertEquals('MyTitle', $result['parameters']['title']);
$this->assertEquals('fa-test', $result['parameters']['icon']);
$this->assertInternalType('string', $result);
}
}

0 comments on commit b7eb35a

Please sign in to comment.