mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-17 12:14:58 +00:00
Compare commits
3 Commits
fix-tests-
...
behaviour/
Author | SHA1 | Date | |
---|---|---|---|
81a8a6ed03 | |||
19bfeacc9a | |||
692e63aba3 |
@@ -22,7 +22,6 @@ class LoadActivityNotifications extends AbstractFixture implements DependentFixt
|
|||||||
'entityRef' => 'activity_gerard depardieu',
|
'entityRef' => 'activity_gerard depardieu',
|
||||||
'sender' => 'center a_social',
|
'sender' => 'center a_social',
|
||||||
'addressees' => [
|
'addressees' => [
|
||||||
'center a_social',
|
|
||||||
'center a_administrative',
|
'center a_administrative',
|
||||||
'center a_direction',
|
'center a_direction',
|
||||||
'multi_center'
|
'multi_center'
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\ActivityBundle\Notification;
|
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Notification;
|
|
||||||
use Chill\ActivityBundle\Entity\Activity;
|
|
||||||
|
|
||||||
final class ActivityNotificationRenderer
|
|
||||||
{
|
|
||||||
public function supports(Notification $notification, array $options = []): bool
|
|
||||||
{
|
|
||||||
return $notification->getRelatedEntityClass() == Activity::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplate()
|
|
||||||
{
|
|
||||||
return '@ChillActivity/Activity/showInNotification.html.twig';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplateData(Notification $notification)
|
|
||||||
{
|
|
||||||
return ['notification' => $notification];
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,4 +0,0 @@
|
|||||||
|
|
||||||
{{ dump(notification) }}
|
|
||||||
|
|
||||||
<a href="{{ path('chill_activity_activity_show', {'id': notification.relatedEntityId }) }}">Go to Activity</a>
|
|
@@ -1,4 +1,4 @@
|
|||||||
services:
|
services:
|
||||||
chill.activity.security.authorization.activity_voter:
|
chill.activity.security.authorization.activity_voter:
|
||||||
class: Chill\ActivityBundle\Security\Authorization\ActivityVoter
|
class: Chill\ActivityBundle\Security\Authorization\ActivityVoter
|
||||||
arguments:
|
arguments:
|
||||||
@@ -6,7 +6,7 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: security.voter }
|
- { name: security.voter }
|
||||||
- { name: chill.role }
|
- { name: chill.role }
|
||||||
|
|
||||||
chill.activity.security.authorization.activity_stats_voter:
|
chill.activity.security.authorization.activity_stats_voter:
|
||||||
class: Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter
|
class: Chill\ActivityBundle\Security\Authorization\ActivityStatsVoter
|
||||||
arguments:
|
arguments:
|
||||||
@@ -14,8 +14,8 @@ services:
|
|||||||
tags:
|
tags:
|
||||||
- { name: security.voter }
|
- { name: security.voter }
|
||||||
- { name: chill.role }
|
- { name: chill.role }
|
||||||
|
|
||||||
|
|
||||||
chill.activity.timeline:
|
chill.activity.timeline:
|
||||||
class: Chill\ActivityBundle\Timeline\TimelineActivityProvider
|
class: Chill\ActivityBundle\Timeline\TimelineActivityProvider
|
||||||
arguments:
|
arguments:
|
||||||
@@ -33,8 +33,3 @@ services:
|
|||||||
autoconfigure: true
|
autoconfigure: true
|
||||||
resource: '../Menu/'
|
resource: '../Menu/'
|
||||||
tags: ['chill.menu_builder']
|
tags: ['chill.menu_builder']
|
||||||
|
|
||||||
Chill\ActivityBundle\Notification\:
|
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
resource: '../Notification'
|
|
||||||
|
@@ -1,59 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Controller;
|
|
||||||
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
use Chill\MainBundle\Repository\NotificationRepository;
|
|
||||||
use Chill\MainBundle\Notification\NotificationRenderer;
|
|
||||||
use Symfony\Component\Security\Core\Security;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
|
||||||
use Chill\MainBundle\Pagination\PaginatorFactory;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route("/{_locale}/notification")
|
|
||||||
*/
|
|
||||||
class NotificationController extends AbstractController
|
|
||||||
{
|
|
||||||
private $security;
|
|
||||||
|
|
||||||
public function __construct(Security $security)
|
|
||||||
{
|
|
||||||
$this->security = $security;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @Route("/show", name="chill_main_notification_show")
|
|
||||||
*/
|
|
||||||
public function showAction(
|
|
||||||
NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer,
|
|
||||||
PaginatorFactory $paginatorFactory)
|
|
||||||
{
|
|
||||||
$currentUser = $this->security->getUser();
|
|
||||||
|
|
||||||
$notificationsNbr = $notificationRepository->countAllForAttendee(($currentUser));
|
|
||||||
$paginator = $paginatorFactory->create($notificationsNbr);
|
|
||||||
|
|
||||||
$notifications = $notificationRepository->findAllForAttendee(
|
|
||||||
$currentUser,
|
|
||||||
$limit=$paginator->getItemsPerPage(),
|
|
||||||
$offset= $paginator->getCurrentPage()->getFirstItemNumber());
|
|
||||||
|
|
||||||
$templateData = array();
|
|
||||||
foreach ($notifications as $notification) {
|
|
||||||
$data = [
|
|
||||||
'template' => $notificationRenderer->getTemplate($notification),
|
|
||||||
'template_data' => $notificationRenderer->getTemplateData($notification),
|
|
||||||
'notification' => $notification
|
|
||||||
];
|
|
||||||
$templateData[] = $data;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->render('@ChillMain/Notification/show.html.twig', [
|
|
||||||
'datas' => $templateData,
|
|
||||||
'notifications' => $notifications,
|
|
||||||
'paginator' => $paginator,
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\MainBundle\Notification;
|
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Notification;
|
|
||||||
use Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer;
|
|
||||||
use Chill\ActivityBundle\Notification\ActivityNotificationRenderer;
|
|
||||||
|
|
||||||
final class NotificationRenderer
|
|
||||||
{
|
|
||||||
private array $renderers;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
AccompanyingPeriodNotificationRenderer $accompanyingPeriodNotificationRenderer,
|
|
||||||
ActivityNotificationRenderer $activityNotificationRenderer)
|
|
||||||
{
|
|
||||||
// TODO configure automatically
|
|
||||||
// TODO CREER UNE INTERFACE POUR ETRE SUR QUE LES RENDERERS SONT OK
|
|
||||||
|
|
||||||
$this->renderers[] = $accompanyingPeriodNotificationRenderer;
|
|
||||||
$this->renderers[] = $activityNotificationRenderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getRenderer(Notification $notification)
|
|
||||||
{
|
|
||||||
foreach ($this->renderers as $renderer) {
|
|
||||||
if($renderer->supports($notification)) {
|
|
||||||
return $renderer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception('No renderer for '. $notification);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplate(Notification $notification)
|
|
||||||
{
|
|
||||||
return $this->getRenderer($notification)->getTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplateData(Notification $notification)
|
|
||||||
{
|
|
||||||
return $this->getRenderer($notification)->getTemplateData($notification);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -23,8 +23,6 @@ use Chill\MainBundle\Entity\Notification;
|
|||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\ORM\EntityRepository;
|
use Doctrine\ORM\EntityRepository;
|
||||||
use Doctrine\Persistence\ObjectRepository;
|
use Doctrine\Persistence\ObjectRepository;
|
||||||
use Chill\MainBundle\Entity\User;
|
|
||||||
use Doctrine\ORM\Query;
|
|
||||||
|
|
||||||
final class NotificationRepository implements ObjectRepository
|
final class NotificationRepository implements ObjectRepository
|
||||||
{
|
{
|
||||||
@@ -61,54 +59,8 @@ final class NotificationRepository implements ObjectRepository
|
|||||||
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function queryAllForAttendee(User $addressee, bool $countQuery=False): Query
|
|
||||||
{
|
|
||||||
$qb = $this->repository->createQueryBuilder('n');
|
|
||||||
|
|
||||||
$select = 'n';
|
|
||||||
if($countQuery) {
|
|
||||||
$select = 'count(n)';
|
|
||||||
}
|
|
||||||
|
|
||||||
$qb
|
|
||||||
->select($select)
|
|
||||||
->join('n.addressees', 'a')
|
|
||||||
->where('a = :addressee')
|
|
||||||
->setParameter('addressee', $addressee);
|
|
||||||
|
|
||||||
return $qb->getQuery();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return int
|
|
||||||
*/
|
|
||||||
public function countAllForAttendee(User $addressee): int // TODO passer à attendees avec S
|
|
||||||
{
|
|
||||||
$query = $this->queryAllForAttendee($addressee, $countQuery=True);
|
|
||||||
|
|
||||||
return $query->getSingleScalarResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Notification[]
|
|
||||||
*/
|
|
||||||
public function findAllForAttendee(User $addressee, $limit = null, $offset = null): array // TODO passer à attendees avec S
|
|
||||||
{
|
|
||||||
$query = $this->queryAllForAttendee($addressee);
|
|
||||||
|
|
||||||
if($limit) {
|
|
||||||
$query = $query->setMaxResults($limit);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($offset) {
|
|
||||||
$query = $query->setFirstResult($offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $query->getResult();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getClassName() {
|
public function getClassName() {
|
||||||
return Notification::class;
|
return Notification::class;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -1,42 +0,0 @@
|
|||||||
{% extends "@ChillMain/layout.html.twig" %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
<div id="container content">
|
|
||||||
<div class="grid-8 centered">
|
|
||||||
<h1>{{ "Notifications list" | trans }}</h1>
|
|
||||||
<!-- TODO : UNREAD & READ -->
|
|
||||||
|
|
||||||
{%for data in datas %}
|
|
||||||
{% set notification = data.notification %}
|
|
||||||
|
|
||||||
<dl class="chill_view_data">
|
|
||||||
<dt class="inline">{{ 'Message'|trans }}</dt>
|
|
||||||
<dd>{{ notification.message }}</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<dl class="chill_view_data">
|
|
||||||
<dt class="inline">{{ 'Date'|trans }}</dt>
|
|
||||||
<dd>{{ notification.date | date('long') }}</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
|
|
||||||
<dl class="chill_view_data">
|
|
||||||
<dt class="inline">{{ 'Sender'|trans }}</dt>
|
|
||||||
<dd>{{ notification.sender }}</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<dl class="chill_view_data">
|
|
||||||
<dt class="inline">{{ 'Addressees'|trans }}</dt>
|
|
||||||
<dd>{{ notification.addressees |join(', ') }}</dd>
|
|
||||||
</dl>
|
|
||||||
|
|
||||||
<dl class="chill_view_data">
|
|
||||||
<dt class="inline">{{ 'Entity'|trans }}</dt>
|
|
||||||
<dd>
|
|
||||||
{% include data.template with data.template_data %}
|
|
||||||
</dd>
|
|
||||||
</dl>
|
|
||||||
{% endfor %}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock content %}
|
|
@@ -26,7 +26,7 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* This class provide a set of tests for exports.
|
* This class provide a set of tests for exports.
|
||||||
*
|
*
|
||||||
* The tests provided by this class will check basic things, like
|
* The tests provided by this class will check basic things, like
|
||||||
* the type of value are conform to the expected, etc.
|
* the type of value are conform to the expected, etc.
|
||||||
*
|
*
|
||||||
@@ -34,45 +34,45 @@ use Symfony\Component\HttpFoundation\Request;
|
|||||||
*/
|
*/
|
||||||
abstract class AbstractExportTest extends WebTestCase
|
abstract class AbstractExportTest extends WebTestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
use PrepareClientTrait;
|
use PrepareClientTrait;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create an instance of the report to test
|
* Create an instance of the report to test
|
||||||
*
|
*
|
||||||
* @return \Chill\MainBundle\Export\ExportInterface an instance of the export to test
|
* @return \Chill\MainBundle\Export\ExportInterface an instance of the export to test
|
||||||
*/
|
*/
|
||||||
public abstract function getExport();
|
public abstract function getExport();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create possible combinaison of data (produced by the form).
|
* Create possible combinaison of data (produced by the form).
|
||||||
*
|
*
|
||||||
* This data will be used to generate data providers using this data.
|
* This data will be used to generate data providers using this data.
|
||||||
*
|
*
|
||||||
* @return array an array of data. Example : `array( array(), array('fields' => array(1,2,3), ...)` where an empty array and `array(1,2,3)` are possible values
|
* @return array an array of data. Example : `array( array(), array('fields' => array(1,2,3), ...)` where an empty array and `array(1,2,3)` are possible values
|
||||||
*/
|
*/
|
||||||
public abstract function getFormData();
|
public abstract function getFormData();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* get the possible modifiers which could apply in combination to this
|
* get the possible modifiers which could apply in combination to this
|
||||||
* export.
|
* export.
|
||||||
* .
|
* .
|
||||||
*
|
*
|
||||||
* @return array of string[] an array which contains an array of possible modifiers. Example : `array( array('modifier_1', 'modifier_2'), array('modifier_1'), ...)`
|
* @return array of string[] an array which contains an array of possible modifiers. Example : `array( array('modifier_1', 'modifier_2'), array('modifier_1'), ...)`
|
||||||
*/
|
*/
|
||||||
abstract public function getModifiersCombination();
|
abstract public function getModifiersCombination();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return an array usable as ACL
|
* Return an array usable as ACL
|
||||||
*
|
*
|
||||||
* If this method is overridden, the returned result must be an array
|
* If this method is overridden, the returned result must be an array
|
||||||
* with this form :
|
* with this form :
|
||||||
*
|
*
|
||||||
* ```
|
* ```
|
||||||
* array(
|
* array(
|
||||||
* array(
|
* array(
|
||||||
* 'center' => //center instance
|
* 'center' => //center instance
|
||||||
* 'circles' => array(// array of circles instances )
|
* 'circles' => array(// array of circles instances )
|
||||||
* )
|
* )
|
||||||
* );
|
* );
|
||||||
@@ -84,15 +84,15 @@ abstract class AbstractExportTest extends WebTestCase
|
|||||||
if (static::$kernel === null) {
|
if (static::$kernel === null) {
|
||||||
static::bootKernel();
|
static::bootKernel();
|
||||||
}
|
}
|
||||||
|
|
||||||
$em = static::$kernel->getContainer()
|
$em = static::$kernel->getContainer()
|
||||||
->get('doctrine.orm.entity_manager');
|
->get('doctrine.orm.entity_manager');
|
||||||
|
|
||||||
$centers = $em->getRepository('ChillMainBundle:Center')
|
$centers = $em->getRepository('ChillMainBundle:Center')
|
||||||
->findAll();
|
->findAll();
|
||||||
$circles = $em->getRepository('ChillMainBundle:Scope')
|
$circles = $em->getRepository('ChillMainBundle:Scope')
|
||||||
->findAll();
|
->findAll();
|
||||||
|
|
||||||
if (count($centers) === 0) {
|
if (count($centers) === 0) {
|
||||||
throw new \RuntimeException("No center found. Did you forget to "
|
throw new \RuntimeException("No center found. Did you forget to "
|
||||||
. "run `doctrine:fixtures:load` command before ?");
|
. "run `doctrine:fixtures:load` command before ?");
|
||||||
@@ -101,7 +101,7 @@ abstract class AbstractExportTest extends WebTestCase
|
|||||||
throw new \RuntimeException("No circle found. Did you forget to "
|
throw new \RuntimeException("No circle found. Did you forget to "
|
||||||
. "run `doctrine:fixtures:load` command before ?");
|
. "run `doctrine:fixtures:load` command before ?");
|
||||||
}
|
}
|
||||||
|
|
||||||
return array([
|
return array([
|
||||||
'center' => $centers[0],
|
'center' => $centers[0],
|
||||||
'circles' => [
|
'circles' => [
|
||||||
@@ -115,203 +115,204 @@ abstract class AbstractExportTest extends WebTestCase
|
|||||||
public function testGetType()
|
public function testGetType()
|
||||||
{
|
{
|
||||||
$export = $this->getExport();
|
$export = $this->getExport();
|
||||||
|
|
||||||
$this->assertInternalType('string', $export->getType(),
|
$this->assertInternalType('string', $export->getType(),
|
||||||
"Assert that the `getType` method return a string");
|
"Assert that the `getType` method return a string");
|
||||||
$this->assertNotEmpty($export->getType(), "Assert that the `getType` method"
|
$this->assertNotEmpty($export->getType(), "Assert that the `getType` method"
|
||||||
. " does not return an empty string.");
|
. " does not return an empty string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the description is not empty
|
* Test that the description is not empty
|
||||||
*/
|
*/
|
||||||
public function testGetDescription()
|
public function testGetDescription()
|
||||||
{
|
{
|
||||||
$export = $this->getExport();
|
$export = $this->getExport();
|
||||||
|
|
||||||
$this->assertInternalType('string', $export->getDescription(),
|
$this->assertInternalType('string', $export->getDescription(),
|
||||||
"Assert that the `getDescription` method return a string");
|
"Assert that the `getDescription` method return a string");
|
||||||
$this->assertNotEmpty($export->getDescription(),
|
$this->assertNotEmpty($export->getDescription(),
|
||||||
"Assert that the `getDescription` method does not return an empty "
|
"Assert that the `getDescription` method does not return an empty "
|
||||||
. "string.");
|
. "string.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create data for `ìnitiateQuery` method
|
* create data for `ìnitiateQuery` method
|
||||||
*/
|
*/
|
||||||
public function dataProviderInitiateQuery()
|
public function dataProviderInitiateQuery()
|
||||||
{
|
{
|
||||||
$acl = $this->getAcl();
|
$acl = $this->getAcl();
|
||||||
|
|
||||||
foreach($this->getModifiersCombination() as $modifiers) {
|
foreach($this->getModifiersCombination() as $modifiers) {
|
||||||
|
|
||||||
foreach($this->getFormData() as $data) {
|
foreach($this->getFormData() as $data) {
|
||||||
|
|
||||||
yield array($modifiers, $acl, $data);
|
yield array($modifiers, $acl, $data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function dataProviderGetQueryKeys()
|
public function dataProviderGetQueryKeys()
|
||||||
{
|
{
|
||||||
foreach($this->getFormData() as $data) {
|
foreach($this->getFormData() as $data) {
|
||||||
yield array($data);
|
yield array($data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* test that the query returned is a QueryBuilder or a NativeQuery.
|
* test that the query returned is a QueryBuilder or a NativeQuery.
|
||||||
*
|
*
|
||||||
* If the query is a QueryBuilder, test that select and from is not empty.
|
* If the query is a QueryBuilder, test that select and from is not empty.
|
||||||
*
|
*
|
||||||
* If the query is a native sql, test the query is not empty (length is
|
* If the query is a native sql, test the query is not empty (length is
|
||||||
* > 0).
|
* > 0).
|
||||||
*
|
*
|
||||||
* @dataProvider dataProviderInitiateQuery
|
* @dataProvider dataProviderInitiateQuery
|
||||||
*/
|
*/
|
||||||
public function testInitiateQuery($modifiers, $acl, $data)
|
public function testInitiateQuery($modifiers, $acl, $data)
|
||||||
{
|
{
|
||||||
|
var_dump($data);
|
||||||
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data);
|
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data);
|
||||||
|
|
||||||
$this->assertTrue($query instanceof QueryBuilder || $query instanceof NativeQuery,
|
$this->assertTrue($query instanceof QueryBuilder || $query instanceof NativeQuery,
|
||||||
sprintf("Assert that the returned query is an instance of %s or %s",
|
sprintf("Assert that the returned query is an instance of %s or %s",
|
||||||
QueryBuilder::class, Query::class));
|
QueryBuilder::class, Query::class));
|
||||||
|
|
||||||
if ($query instanceof QueryBuilder) {
|
if ($query instanceof QueryBuilder) {
|
||||||
|
|
||||||
$this->assertGreaterThanOrEqual(1, count($query->getDQLPart('select')),
|
$this->assertGreaterThanOrEqual(1, count($query->getDQLPart('select')),
|
||||||
"assert there is at least one 'select' part");
|
"assert there is at least one 'select' part");
|
||||||
|
|
||||||
$this->assertGreaterThanOrEqual(1, count($query->getDQLPart('from')),
|
$this->assertGreaterThanOrEqual(1, count($query->getDQLPart('from')),
|
||||||
"assert there is at least one 'from' part");
|
"assert there is at least one 'from' part");
|
||||||
|
|
||||||
} elseif ($query instanceof NativeQuery) {
|
} elseif ($query instanceof NativeQuery) {
|
||||||
$this->assertNotEmpty($query->getSQL(),
|
$this->assertNotEmpty($query->getSQL(),
|
||||||
"check that the SQL query is not empty");
|
"check that the SQL query is not empty");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that supportsModifier return :
|
* Test that supportsModifier return :
|
||||||
*
|
*
|
||||||
* - an array of string, if the query is a QueryBuilder ;
|
* - an array of string, if the query is a QueryBuilder ;
|
||||||
* - nothing, if the query is a native SQL
|
* - nothing, if the query is a native SQL
|
||||||
*
|
*
|
||||||
* @dataProvider dataProviderInitiateQuery
|
* @dataProvider dataProviderInitiateQuery
|
||||||
*/
|
*/
|
||||||
public function testSupportsModifier($modifiers, $acl, $data)
|
public function testSupportsModifier($modifiers, $acl, $data)
|
||||||
{
|
{
|
||||||
$export = $this->getExport();
|
$export = $this->getExport();
|
||||||
$query = $export->initiateQuery($modifiers, $acl, $data);
|
$query = $export->initiateQuery($modifiers, $acl, $data);
|
||||||
|
|
||||||
if ($query instanceof QueryBuilder) {
|
if ($query instanceof QueryBuilder) {
|
||||||
$this->assertContainsOnly('string', $export->supportsModifiers(),
|
$this->assertContainsOnly('string', $export->supportsModifiers(),
|
||||||
"Test that the `supportsModifiers` method returns only strings");
|
"Test that the `supportsModifiers` method returns only strings");
|
||||||
} elseif ($query instanceof NativeQuery) {
|
} elseif ($query instanceof NativeQuery) {
|
||||||
$this->assertTrue($export->supportsModifiers() === null ||
|
$this->assertTrue($export->supportsModifiers() === null ||
|
||||||
count($export->supportsModifiers()) === 0,
|
count($export->supportsModifiers()) === 0,
|
||||||
"Test that the `supportsModifier` methods returns null or an empty array");
|
"Test that the `supportsModifier` methods returns null or an empty array");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test required role is an instance of Role
|
* Test required role is an instance of Role
|
||||||
*/
|
*/
|
||||||
public function testRequiredRole()
|
public function testRequiredRole()
|
||||||
{
|
{
|
||||||
$role = $this->getExport()->requiredRole();
|
$role = $this->getExport()->requiredRole();
|
||||||
|
|
||||||
$this->assertInstanceOf(Role::class, $role,
|
$this->assertInstanceOf(Role::class, $role,
|
||||||
sprintf("test that the returned value of `requiredRole` is an instance "
|
sprintf("test that the returned value of `requiredRole` is an instance "
|
||||||
. "of %s", Role::class));
|
. "of %s", Role::class));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test the formatters type are string
|
* Test the formatters type are string
|
||||||
*/
|
*/
|
||||||
public function testGetAllowedFormattersType()
|
public function testGetAllowedFormattersType()
|
||||||
{
|
{
|
||||||
$formattersTypes = $this->getExport()->getAllowedFormattersTypes();
|
$formattersTypes = $this->getExport()->getAllowedFormattersTypes();
|
||||||
|
|
||||||
$this->assertContainsOnly("string", $formattersTypes,
|
$this->assertContainsOnly("string", $formattersTypes,
|
||||||
"Test that the method `getAllowedFormattersTypes` returns an array of string");
|
"Test that the method `getAllowedFormattersTypes` returns an array of string");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the query keys are strings
|
* Test that the query keys are strings
|
||||||
*
|
*
|
||||||
* @param array $data
|
* @param array $data
|
||||||
* @dataProvider dataProviderGetQueryKeys
|
* @dataProvider dataProviderGetQueryKeys
|
||||||
*/
|
*/
|
||||||
public function testGetQueryKeys(array $data)
|
public function testGetQueryKeys(array $data)
|
||||||
{
|
{
|
||||||
$queryKeys = $this->getExport()->getQueryKeys($data);
|
$queryKeys = $this->getExport()->getQueryKeys($data);
|
||||||
|
|
||||||
$this->assertContainsOnly("string", $queryKeys,
|
$this->assertContainsOnly("string", $queryKeys,
|
||||||
"test that the query keys returned by `getQueryKeys` are only strings");
|
"test that the query keys returned by `getQueryKeys` are only strings");
|
||||||
$this->assertGreaterThanOrEqual(1, count($queryKeys),
|
$this->assertGreaterThanOrEqual(1, count($queryKeys),
|
||||||
"test that there are at least one query key returned");
|
"test that there are at least one query key returned");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Test that
|
* Test that
|
||||||
*
|
*
|
||||||
* - the results have a correct form (are arrays or traversable)
|
* - the results have a correct form (are arrays or traversable)
|
||||||
* - each key in a row are present in getQueryKeys ;
|
* - each key in a row are present in getQueryKeys ;
|
||||||
* - each returned object of the `getLabels` method is callable
|
* - each returned object of the `getLabels` method is callable
|
||||||
* - each result can be converted to string using this callable
|
* - each result can be converted to string using this callable
|
||||||
* - each of this callable can provide a string for '_header'
|
* - each of this callable can provide a string for '_header'
|
||||||
*
|
*
|
||||||
* @param string[] $modifiers
|
* @param string[] $modifiers
|
||||||
* @param array $acl
|
* @param array $acl
|
||||||
* @param array $data
|
* @param array $data
|
||||||
*
|
*
|
||||||
* @dataProvider dataProviderInitiateQuery
|
* @dataProvider dataProviderInitiateQuery
|
||||||
*/
|
*/
|
||||||
public function testGetResultsAndLabels($modifiers, $acl, array $data)
|
public function testGetResultsAndLabels($modifiers, $acl, array $data)
|
||||||
{
|
{
|
||||||
// it is more convenient to group the `getResult` and `getLabels` test
|
// it is more convenient to group the `getResult` and `getLabels` test
|
||||||
// due to the fact that testing both methods use the same tools.
|
// due to the fact that testing both methods use the same tools.
|
||||||
|
|
||||||
$queryKeys = $this->getExport()->getQueryKeys($data);
|
$queryKeys = $this->getExport()->getQueryKeys($data);
|
||||||
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data);
|
$query = $this->getExport()->initiateQuery($modifiers, $acl, $data);
|
||||||
|
|
||||||
// limit the result for the query for performance reason (only for QueryBuilder,
|
// limit the result for the query for performance reason (only for QueryBuilder,
|
||||||
// not possible in NativeQuery)
|
// not possible in NativeQuery)
|
||||||
if ($query instanceof QueryBuilder) {
|
if ($query instanceof QueryBuilder) {
|
||||||
$query->setMaxResults(1);
|
$query->setMaxResults(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
$results = $this->getExport()->getResult($query, $data);
|
$results = $this->getExport()->getResult($query, $data);
|
||||||
|
|
||||||
$this->assertInternalType('array', $results,
|
$this->assertInternalType('array', $results,
|
||||||
"assert that the returned result is an array");
|
"assert that the returned result is an array");
|
||||||
|
|
||||||
if (count($results) === 0) {
|
if (count($results) === 0) {
|
||||||
$this->markTestIncomplete("The result is empty. We cannot process tests "
|
$this->markTestIncomplete("The result is empty. We cannot process tests "
|
||||||
. "on results");
|
. "on results");
|
||||||
}
|
}
|
||||||
|
|
||||||
// testing the result
|
// testing the result
|
||||||
$result = $results[0];
|
$result = $results[0];
|
||||||
|
|
||||||
$this->assertTrue( $result instanceof \Traversable || is_array($result),
|
$this->assertTrue( $result instanceof \Traversable || is_array($result),
|
||||||
"test that each row in the result is traversable or an array");
|
"test that each row in the result is traversable or an array");
|
||||||
|
|
||||||
foreach ($result as $key => $value) {
|
foreach ($result as $key => $value) {
|
||||||
$this->assertContains($key, $queryKeys,
|
$this->assertContains($key, $queryKeys,
|
||||||
"test that each key is present in `getQueryKeys`");
|
"test that each key is present in `getQueryKeys`");
|
||||||
|
|
||||||
$closure = $this->getExport()->getLabels($key, array($value), $data);
|
$closure = $this->getExport()->getLabels($key, array($value), $data);
|
||||||
|
|
||||||
$this->assertTrue(is_callable($closure, false),
|
$this->assertTrue(is_callable($closure, false),
|
||||||
"test that the `getLabels` for key is a callable");
|
"test that the `getLabels` for key is a callable");
|
||||||
$this->assertTrue(is_string((string) call_user_func($closure, $value)),
|
$this->assertTrue(is_string((string) call_user_func($closure, $value)),
|
||||||
sprintf("test that the callable return by `getLabels` for key %s "
|
sprintf("test that the callable return by `getLabels` for key %s "
|
||||||
. "is a string or an be converted to a string", $key));
|
. "is a string or an be converted to a string", $key));
|
||||||
|
|
||||||
$this->assertTrue(
|
$this->assertTrue(
|
||||||
// conditions
|
// conditions
|
||||||
is_string((string) call_user_func($closure, '_header'))
|
is_string((string) call_user_func($closure, '_header'))
|
||||||
@@ -321,13 +322,13 @@ abstract class AbstractExportTest extends WebTestCase
|
|||||||
sprintf("Test that the callable return by `getLabels` for key %s "
|
sprintf("Test that the callable return by `getLabels` for key %s "
|
||||||
. "can provide an header", $key)
|
. "can provide an header", $key)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that the translated title of the export is present the list,
|
* Test that the translated title of the export is present the list,
|
||||||
* and that the list of exports (under `/fr/exports/`) is still successfull
|
* and that the list of exports (under `/fr/exports/`) is still successfull
|
||||||
*/
|
*/
|
||||||
public function testListExportPage()
|
public function testListExportPage()
|
||||||
@@ -337,17 +338,17 @@ abstract class AbstractExportTest extends WebTestCase
|
|||||||
$export = $this->getExport();
|
$export = $this->getExport();
|
||||||
$prophet= new \Prophecy\Prophet;
|
$prophet= new \Prophecy\Prophet;
|
||||||
$container = static::$kernel->getContainer();
|
$container = static::$kernel->getContainer();
|
||||||
|
|
||||||
// store the locale in a request
|
// store the locale in a request
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request->setLocale('fr');
|
$request->setLocale('fr');
|
||||||
$container->get('request_stack')->push($request);
|
$container->get('request_stack')->push($request);
|
||||||
// translate the title
|
// translate the title
|
||||||
$title = $container->get('translator')->trans($export->getTitle());
|
$title = $container->get('translator')->trans($export->getTitle());
|
||||||
|
|
||||||
// performs the request to /fr/exports
|
// performs the request to /fr/exports
|
||||||
$crawler = $client->request('GET', '/fr/exports/');
|
$crawler = $client->request('GET', '/fr/exports/');
|
||||||
|
|
||||||
// and finally make tests
|
// and finally make tests
|
||||||
$this->assertTrue($client->getResponse()->isSuccessful(),
|
$this->assertTrue($client->getResponse()->isSuccessful(),
|
||||||
"test that the response of /fr/exports/ is successful");
|
"test that the response of /fr/exports/ is successful");
|
||||||
|
@@ -34,10 +34,6 @@ chill_password_recover:
|
|||||||
resource: "@ChillMainBundle/config/routes/password_recover.yaml"
|
resource: "@ChillMainBundle/config/routes/password_recover.yaml"
|
||||||
prefix: "public/{_locale}/password"
|
prefix: "public/{_locale}/password"
|
||||||
|
|
||||||
chill_main_notification:
|
|
||||||
resource: "@ChillMainBundle/config/routes/notification.yaml"
|
|
||||||
prefix: "{_locale}/notification"
|
|
||||||
|
|
||||||
chill_crud:
|
chill_crud:
|
||||||
resource: "@ChillMainBundle"
|
resource: "@ChillMainBundle"
|
||||||
type: CRUD
|
type: CRUD
|
||||||
|
@@ -33,8 +33,3 @@ services:
|
|||||||
$logger: '@Psr\Log\LoggerInterface'
|
$logger: '@Psr\Log\LoggerInterface'
|
||||||
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
||||||
tags: ['controller.service_arguments']
|
tags: ['controller.service_arguments']
|
||||||
|
|
||||||
Chill\MainBundle\Controller\NotificationController:
|
|
||||||
arguments:
|
|
||||||
$security: '@Symfony\Component\Security\Core\Security'
|
|
||||||
tags: ['controller.service_arguments']
|
|
||||||
|
@@ -4,11 +4,7 @@ services:
|
|||||||
$logger: '@Psr\Log\LoggerInterface'
|
$logger: '@Psr\Log\LoggerInterface'
|
||||||
$twig: '@Twig\Environment'
|
$twig: '@Twig\Environment'
|
||||||
$mailer: '@swiftmailer.mailer.default'
|
$mailer: '@swiftmailer.mailer.default'
|
||||||
# $mailerTransporter: '@swiftmailer.transport'
|
# $mailerTransporter: '@swiftmailer.transport'
|
||||||
$router: '@Symfony\Component\Routing\RouterInterface'
|
$router: '@Symfony\Component\Routing\RouterInterface'
|
||||||
$translator: '@Symfony\Component\Translation\TranslatorInterface'
|
$translator: '@Symfony\Component\Translation\TranslatorInterface'
|
||||||
$routeParameters: '%chill_main.notifications%'
|
$routeParameters: '%chill_main.notifications%'
|
||||||
|
|
||||||
Chill\MainBundle\Notification\NotificationRenderer:
|
|
||||||
autoconfigure: true
|
|
||||||
autowire: true
|
|
||||||
|
@@ -2,15 +2,13 @@ services:
|
|||||||
chill_main.paginator_factory:
|
chill_main.paginator_factory:
|
||||||
class: Chill\MainBundle\Pagination\PaginatorFactory
|
class: Chill\MainBundle\Pagination\PaginatorFactory
|
||||||
public: true
|
public: true
|
||||||
autowire: true
|
|
||||||
autoconfigure: true
|
|
||||||
arguments:
|
arguments:
|
||||||
- "@request_stack"
|
- "@request_stack"
|
||||||
- "@router"
|
- "@router"
|
||||||
- "%chill_main.pagination.item_per_page%"
|
- "%chill_main.pagination.item_per_page%"
|
||||||
|
|
||||||
Chill\MainBundle\Pagination\PaginatorFactory: '@chill_main.paginator_factory'
|
Chill\MainBundle\Pagination\PaginatorFactory: '@chill_main.paginator_factory'
|
||||||
|
|
||||||
chill_main.paginator.twig_extensions:
|
chill_main.paginator.twig_extensions:
|
||||||
class: Chill\MainBundle\Pagination\ChillPaginationTwig
|
class: Chill\MainBundle\Pagination\ChillPaginationTwig
|
||||||
tags:
|
tags:
|
||||||
|
@@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
|
||||||
|
|
||||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
||||||
use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait;
|
|
||||||
use Chill\PersonBundle\DataFixtures\ORM\LoadAccompanyingPeriod;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load notififications into database
|
|
||||||
*/
|
|
||||||
class LoadAccompanyingPeriodNotifications extends AbstractFixture implements DependentFixtureInterface
|
|
||||||
{
|
|
||||||
use LoadAbstractNotificationsTrait;
|
|
||||||
|
|
||||||
public $notifs = [
|
|
||||||
[
|
|
||||||
'message' => 'Hello !',
|
|
||||||
'entityClass' => AccompanyingPeriod::class,
|
|
||||||
'entityRef' => LoadAccompanyingPeriod::ACCOMPANYING_PERIOD,
|
|
||||||
'sender' => 'center a_social',
|
|
||||||
'addressees' => [
|
|
||||||
'center a_social',
|
|
||||||
'center a_administrative',
|
|
||||||
'center a_direction',
|
|
||||||
'multi_center'
|
|
||||||
],
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
public function getDependencies()
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
LoadAccompanyingPeriod::class,
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@@ -74,7 +74,6 @@ class ChillPersonExtension extends Extension implements PrependExtensionInterfac
|
|||||||
$loader->load('services/form.yaml');
|
$loader->load('services/form.yaml');
|
||||||
$loader->load('services/alt_names.yaml');
|
$loader->load('services/alt_names.yaml');
|
||||||
$loader->load('services/household.yaml');
|
$loader->load('services/household.yaml');
|
||||||
$loader->load('services/notification.yaml');
|
|
||||||
// We can get rid of this file when the service 'chill.person.repository.person' is no more used.
|
// We can get rid of this file when the service 'chill.person.repository.person' is no more used.
|
||||||
// We should use the PersonRepository service instead of a custom service name.
|
// We should use the PersonRepository service instead of a custom service name.
|
||||||
$loader->load('services/repository.yaml');
|
$loader->load('services/repository.yaml');
|
||||||
|
@@ -1,24 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\PersonBundle\Notification;
|
|
||||||
|
|
||||||
use Chill\MainBundle\Entity\Notification;
|
|
||||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
|
||||||
|
|
||||||
final class AccompanyingPeriodNotificationRenderer
|
|
||||||
{
|
|
||||||
public function supports(Notification $notification)
|
|
||||||
{
|
|
||||||
return $notification->getRelatedEntityClass() == AccompanyingPeriod::class;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplate()
|
|
||||||
{
|
|
||||||
return 'ChillPersonBundle:AccompanyingPeriod:showInNotification.html.twig';
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getTemplateData(Notification $notification)
|
|
||||||
{
|
|
||||||
return ['notification' => $notification];
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,3 +0,0 @@
|
|||||||
<a href="{{ path('chill_person_accompanying_course_index', {'accompanying_period_id': notification.relatedEntityId }) }}">
|
|
||||||
Go to Acc. period.
|
|
||||||
</a>
|
|
@@ -529,9 +529,8 @@ class AccompanyingCourseApiControllerTest extends WebTestCase
|
|||||||
->find($id);
|
->find($id);
|
||||||
$periods = $person->getAccompanyingPeriods();
|
$periods = $person->getAccompanyingPeriods();
|
||||||
|
|
||||||
if(sizeof($periods) > 0) {
|
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)] ];
|
||||||
yield [$periods[\array_rand($periods)], $socialIssues[\array_rand($socialIssues)] ];
|
|
||||||
}
|
|
||||||
$nbGenerated++;
|
$nbGenerated++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -1,3 +0,0 @@
|
|||||||
services:
|
|
||||||
Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer:
|
|
||||||
autowire: true
|
|
Reference in New Issue
Block a user