mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-31 01:08:26 +00:00 
			
		
		
		
	Merge branch 'master' into _31_interface_creation_parcours
This commit is contained in:
		| @@ -30,6 +30,10 @@ variables: | ||||
|   POSTGRES_PASSWORD: postgres | ||||
|   # fetch the chill-app using git submodules | ||||
|   GIT_SUBMODULE_STRATEGY: recursive | ||||
|   REDIS_HOST: redis | ||||
|   REDIS_PORT: 6379 | ||||
|   REDIS_URL: redis://redis:6379 | ||||
|  | ||||
|  | ||||
| # Run our tests | ||||
| test: | ||||
|   | ||||
							
								
								
									
										9
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,9 @@ | ||||
| # Chill framework | ||||
|  | ||||
| Documentation of the Chill software. | ||||
|  | ||||
| The online documentation can be found at http://docs.chill.social | ||||
|  | ||||
| See the [`docs`][1] directory for more. | ||||
|  | ||||
| [1]: docs/README.md | ||||
| @@ -18,11 +18,11 @@ | ||||
|        <testsuite name="MainBundle"> | ||||
|          <directory suffix="Test.php">src/Bundle/ChillMainBundle/Tests/</directory> | ||||
|        </testsuite> | ||||
|  | ||||
|        <!-- | ||||
|        <testsuite name="PersonBundle"> | ||||
|          <directory suffix="Test.php">src/Bundle/ChillPersonBundle/Tests/</directory> | ||||
|         </testsuite> | ||||
|  | ||||
|       --> | ||||
|       </testsuites> | ||||
|  | ||||
|     <listeners> | ||||
|   | ||||
| @@ -204,7 +204,7 @@ class SearchProvider | ||||
|     } | ||||
|      | ||||
|     public function getResultByName($pattern, $name, $start = 0, $limit = 50, | ||||
|           array $options = array(), $format)  | ||||
|           array $options = array(), $format = 'html')  | ||||
|     { | ||||
|         $terms = $this->parse($pattern); | ||||
|         $search = $this->getByName($name); | ||||
|   | ||||
| @@ -9,15 +9,7 @@ class LoginControllerTest extends WebTestCase | ||||
| { | ||||
|     public function testLogin() | ||||
|     { | ||||
|         $client = static::createClient(array( | ||||
|             'framework' => array( | ||||
|                 'default_locale' => 'en', | ||||
|                 'translator' => array( | ||||
|                     'fallback' => 'en' | ||||
|                 ) | ||||
|             ), | ||||
|              | ||||
|         )); | ||||
|         $client = static::createClient(); | ||||
|  | ||||
|         //load login page and submit form | ||||
|         $crawler = $client->request('GET', '/login'); | ||||
| @@ -42,17 +34,17 @@ class LoginControllerTest extends WebTestCase | ||||
|         //on the home page, there must be a logout link | ||||
|         $client->followRedirects(true); | ||||
|         $crawler = $client->request('GET', '/'); | ||||
|          | ||||
|   | ||||
|         $this->assertRegExp('/center a_social/', $client->getResponse() | ||||
|                                     ->getContent()); | ||||
|         $logoutLinkFilter = $crawler->filter('a:contains("Logout")'); | ||||
|         $logoutLinkFilter = $crawler->filter('a:contains("Se déconnecter")'); | ||||
|          | ||||
|         //check there is > 0 logout link | ||||
|         $this->assertGreaterThan(0, $logoutLinkFilter->count(), 'check that a logout link is present'); | ||||
|          | ||||
|         //click on logout link | ||||
|         $client->followRedirects(false); | ||||
|         $client->click($crawler->selectLink('Logout')->link()); | ||||
|         $client->click($crawler->selectLink('Se déconnecter')->link()); | ||||
|          | ||||
|         $this->assertTrue($client->getResponse()->isRedirect()); | ||||
|         $client->followRedirect(); #redirect to login page | ||||
|   | ||||
| @@ -32,21 +32,7 @@ use Chill\MainBundle\Search\SearchInterface; | ||||
|  */ | ||||
| class SearchControllerTest extends WebTestCase | ||||
| { | ||||
|     /* | ||||
|     public function setUp() | ||||
|     { | ||||
|         static::bootKernel(); | ||||
|          | ||||
|         //add a default service | ||||
|         $this->addSearchService( | ||||
|               $this->createDefaultSearchService('<p>I am default</p>', 10), 'default' | ||||
|               ); | ||||
|         //add a domain service | ||||
|         $this->addSearchService( | ||||
|               $this->createDefaultSearchService('<p>I am domain bar</p>', 20), 'bar' | ||||
|               ); | ||||
|     } | ||||
|      | ||||
|     | ||||
|     /** | ||||
|      * Test the behaviour when no domain is provided in the search pattern :  | ||||
|      * the default search should be enabled | ||||
| @@ -105,29 +91,6 @@ class SearchControllerTest extends WebTestCase | ||||
|         $this->assertTrue($client->getResponse()->isNotFound()); | ||||
|     } | ||||
|      | ||||
|      | ||||
|     public function testSearchWithinSpecificSearchName() | ||||
|     { | ||||
|         /* | ||||
|         //add a search service which will be supported | ||||
|         $this->addSearchService( | ||||
|               $this->createNonDefaultDomainSearchService("<p>I am domain foo</p>", 100, TRUE), 'foo' | ||||
|               ); | ||||
|          | ||||
|         $client = $this->getAuthenticatedClient(); | ||||
|         $crawler = $client->request('GET', '/fr/search',  | ||||
|               array('q' => '@foo default search', 'name' => 'foo')); | ||||
|  | ||||
|         //$this->markTestSkipped(); | ||||
|         $this->assertEquals(0, $crawler->filter('p:contains("I am default")')->count(),  | ||||
|               "The mocked default results are not shown"); | ||||
|         $this->assertEquals(0, $crawler->filter('p:contains("I am domain bar")')->count(), | ||||
|               "The mocked non-default results are not shown"); | ||||
|         $this->assertEquals(1, $crawler->filter('p:contains("I am domain foo")')->count(),  | ||||
|               "The mocked nnon default results for foo are shown"); | ||||
|         */ | ||||
|     } | ||||
|      | ||||
|     private function getAuthenticatedClient() | ||||
|     { | ||||
|         return static::createClient(array(), array( | ||||
|   | ||||
| @@ -37,11 +37,12 @@ class UserControllerTest extends WebTestCase | ||||
|          | ||||
|         $username = 'Test_user'.  uniqid(); | ||||
|         $password = 'Password1234!'; | ||||
|         dump($crawler->text()); | ||||
|         // Fill in the form and submit it | ||||
|         $form = $crawler->selectButton('Créer')->form(array( | ||||
|             'chill_mainbundle_user[username]'  => $username, | ||||
|             'chill_mainbundle_user[plainPassword][password][first]' => $password, | ||||
|             'chill_mainbundle_user[plainPassword][password][second]' => $password | ||||
|             'chill_mainbundle_user[plainPassword][first]' => $password, | ||||
|             'chill_mainbundle_user[plainPassword][second]' => $password | ||||
|         )); | ||||
|  | ||||
|         $this->client->submit($form); | ||||
| @@ -119,8 +120,8 @@ class UserControllerTest extends WebTestCase | ||||
|         $crawler = $this->client->click($link); | ||||
|          | ||||
|         $form = $crawler->selectButton('Changer le mot de passe')->form(array( | ||||
|             'chill_mainbundle_user_password[password][first]' => $newPassword, | ||||
|             'chill_mainbundle_user_password[password][second]' => $newPassword, | ||||
|             'chill_mainbundle_user_password[new_password][first]' => $newPassword, | ||||
|             'chill_mainbundle_user_password[new_password][second]' => $newPassword, | ||||
|         )); | ||||
|          | ||||
|         $this->client->submit($form); | ||||
|   | ||||
| @@ -1,179 +0,0 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * Chill is a software for social workers | ||||
|  * Copyright (C) 2015 Champs-Libres Coopérative <info@champs-libres.coop> | ||||
|  * | ||||
|  * This program is free software: you can redistribute it and/or modify | ||||
|  * it under the terms of the GNU Affero General Public License as published by | ||||
|  * the Free Software Foundation, either version 3 of the License, or | ||||
|  * (at your option) any later version. | ||||
|  * | ||||
|  * This program is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
|  * GNU Affero General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Affero General Public License | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| namespace Chill\MainBundle\Tests\DependencyInjection; | ||||
|  | ||||
| use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass; | ||||
| use Symfony\Component\DependencyInjection\ContainerBuilderInterface; | ||||
|  | ||||
| /** | ||||
|  * Description of ConfigConsistencyCompilerPassTest | ||||
|  * | ||||
|  * @author Julien Fastré <julien.fastre@champs-libres.coop> | ||||
|  */ | ||||
| class ConfigConsistencyCompilerPassTest extends \PHPUnit\Framework\TestCase | ||||
| { | ||||
|      | ||||
|     /** | ||||
|      *  | ||||
|      * | ||||
|      * @var \Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass  | ||||
|      */ | ||||
|     private $configConsistencyCompilerPass; | ||||
|      | ||||
|     public function setUp() | ||||
|     { | ||||
|         $this->configConsistencyCompilerPass = new ConfigConsistencyCompilerPass(); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Test that everything is fine is configuration is correct | ||||
|      *  | ||||
|      */ | ||||
|     public function testLanguagesArePresent() | ||||
|     { | ||||
|         try { | ||||
|             $this ->configConsistencyCompilerPass | ||||
|                   ->process( | ||||
|                         $this->mockContainer( | ||||
|                               $this->mockTranslatorDefinition(array('fr')), | ||||
|                               array('fr', 'nl') | ||||
|                         ) | ||||
|                     ); | ||||
|             $this->assertTrue(TRUE, 'the config consistency can process'); | ||||
|         } catch (\Exception $ex) { | ||||
|             $this->assertTrue(FALSE,  | ||||
|                   'the config consistency can process'); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Test that everything is fine is configuration is correct | ||||
|      * if multiple fallback languages are present | ||||
|      *  | ||||
|      */ | ||||
|     public function testMultiplesLanguagesArePresent() | ||||
|     { | ||||
|         try { | ||||
|             $this ->configConsistencyCompilerPass | ||||
|                   ->process( | ||||
|                         $this->mockContainer( | ||||
|                               $this->mockTranslatorDefinition(array('fr', 'nl')), | ||||
|                               array('fr', 'nl', 'en') | ||||
|                         ) | ||||
|                     ); | ||||
|             $this->assertTrue(TRUE, 'the config consistency can process'); | ||||
|         } catch (\Exception $ex) { | ||||
|             $this->assertTrue(FALSE,  | ||||
|                   'the config consistency can process'); | ||||
|         } | ||||
|     } | ||||
|      | ||||
|      | ||||
|      | ||||
|     /** | ||||
|      * Test that a runtime exception is throw if the available language does  | ||||
|      * not contains the fallback locale | ||||
|      *  | ||||
|      * @expectedException \RuntimeException | ||||
|      * @expectedExceptionMessageRegExp /The chill_main.available_languages parameter does not contains fallback locales./ | ||||
|      */ | ||||
|     public function testLanguageNotPresent() | ||||
|     { | ||||
|         $container = $this->mockContainer( | ||||
|               $this->mockTranslatorDefinition(array('en')), array('fr') | ||||
|               ); | ||||
|          | ||||
|         $this->configConsistencyCompilerPass->process($container); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * Test that a logic exception is thrown if the setFallbackLocale | ||||
|      * method is not defined in translator definition | ||||
|      *  | ||||
|      * @expectedException \LogicException | ||||
|      */ | ||||
|     public function testSetFallbackNotDefined() | ||||
|     { | ||||
|         $container = $this->mockContainer( | ||||
|               $this->mockTranslatorDefinition(NULL), array('fr') | ||||
|               ); | ||||
|         $this->configConsistencyCompilerPass->process($container); | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      * @return ContainerBuilder | ||||
|      */ | ||||
|     private function mockContainer($definition, $availableLanguages) | ||||
|     { | ||||
|         $container = $this | ||||
|               ->getMockBuilder('Symfony\Component\DependencyInjection\ContainerBuilder') | ||||
|               ->getMock(); | ||||
|          | ||||
|         $container->method('getParameter') | ||||
|               ->will($this->returnCallback( | ||||
|                         function($parameter) use ($availableLanguages) { | ||||
|                             if ($parameter === 'chill_main.available_languages') { | ||||
|                                 return $availableLanguages; | ||||
|                             } else { | ||||
|                                 throw new \LogicException("the parameter '$parameter' " | ||||
|                                       . "is not defined in stub test"); | ||||
|                             } | ||||
|                         } | ||||
|                     )); | ||||
|          | ||||
|         $container->method('findDefinition') | ||||
|               ->will($this->returnCallback( | ||||
|                     function($id) use ($definition) {  | ||||
|                         if (in_array($id, array('translator', 'translator.default'))) { | ||||
|                             return $definition; | ||||
|                         } else { | ||||
|                             throw new \LogicException("the id $id is not defined in test"); | ||||
|                         } | ||||
|                   })); | ||||
|                    | ||||
|          | ||||
|         return $container; | ||||
|     } | ||||
|      | ||||
|     /** | ||||
|      *  | ||||
|      * @param type $languages | ||||
|      * @return 'Symfony\Component\DependencyInjection\Definition' | ||||
|      */ | ||||
|     private function mockTranslatorDefinition(array $languages = NULL) | ||||
|     { | ||||
|         $definition = $this | ||||
|               ->getMockBuilder('Symfony\Component\DependencyInjection\Definition') | ||||
|               ->getMock(); | ||||
|          | ||||
|         if (NULL !== $languages) { | ||||
|             $definition->method('getMethodCalls') | ||||
|                   ->willReturn(array( | ||||
|                     ['setFallbackLocales', array($languages)] | ||||
|                      )); | ||||
|         } else { | ||||
|             $definition->method('getMethodCalls') | ||||
|                   ->willReturn(array(['nothing', array()])); | ||||
|         } | ||||
|          | ||||
|         return $definition; | ||||
|     } | ||||
| } | ||||
| @@ -624,8 +624,9 @@ class ExportManagerTest extends KernelTestCase | ||||
|         $exportManager->addFormatter($formatter, 'spreadsheet'); | ||||
|          | ||||
|         //ob_start(); | ||||
|         $response = $exportManager->generate('dummy',  | ||||
|                 array(PickCenterType::CENTERS_IDENTIFIERS => array($center)),  | ||||
|         $response = $exportManager->generate( | ||||
|                 'dummy',  | ||||
|                 array($center),  | ||||
|                 array( | ||||
|                     ExportType::FILTER_KEY => array( | ||||
|                         'filter_foo' => array( | ||||
|   | ||||
| @@ -54,13 +54,20 @@ class PageTest extends KernelTestCase | ||||
|           $number = 1,  | ||||
|           $itemPerPage = 10, | ||||
|           $route = 'route', | ||||
|           array $routeParameters = array() | ||||
|           array $routeParameters = array(), | ||||
|           $totalItems = 100 | ||||
|     ) { | ||||
|         $urlGenerator = $this->prophet->prophesize(); | ||||
|         $urlGenerator->willImplement(UrlGeneratorInterface::class); | ||||
|          | ||||
|         return new Page($number, $itemPerPage, $urlGenerator->reveal(), $route,  | ||||
|               $routeParameters); | ||||
|         return new Page( | ||||
|             $number,  | ||||
|             $itemPerPage,  | ||||
|             $urlGenerator->reveal(),  | ||||
|             $route,  | ||||
|             $routeParameters, | ||||
|             $totalItems | ||||
|         ); | ||||
|     } | ||||
|      | ||||
|     public function testPageNumber() { | ||||
|   | ||||
| @@ -21,9 +21,10 @@ namespace Chill\MainBundle\Test\Search; | ||||
|  | ||||
| use Chill\MainBundle\Search\SearchProvider; | ||||
| use Chill\MainBundle\Search\SearchInterface; | ||||
| use PHPUnit\Framework\TestCase; | ||||
|  | ||||
|  | ||||
| class SearchProviderTest extends \PHPUnit\Framework\TestCase | ||||
| class SearchProviderTest extends TestCase | ||||
| { | ||||
|      | ||||
|     /** | ||||
| @@ -311,4 +312,4 @@ class SearchProviderTest extends \PHPUnit\Framework\TestCase | ||||
|          | ||||
|         return $mock; | ||||
|     } | ||||
| } | ||||
| } | ||||
|   | ||||
| @@ -50,7 +50,7 @@ class AuthorizationHelperTest extends KernelTestCase | ||||
|      */ | ||||
|     private function getAuthorizationHelper() | ||||
|     { | ||||
|         return static::$kernel->getContainer() | ||||
|         return static::$container | ||||
|                 ->get('chill.main.security.authorization.helper') | ||||
|                 ; | ||||
|     } | ||||
|   | ||||
| @@ -39,8 +39,7 @@ class TokenManagerTest extends KernelTestCase | ||||
|     { | ||||
|         self::bootKernel(); | ||||
|          | ||||
|         $logger = self::$kernel | ||||
|             ->getContainer() | ||||
|         $logger = self::$container | ||||
|             ->get('logger'); | ||||
|          | ||||
|         $this->tokenManager = new TokenManager('secret', $logger); | ||||
|   | ||||
| @@ -36,53 +36,19 @@ class ChillMenuTwigFunctionTest extends KernelTestCase | ||||
|     public static function setUpBeforeClass() | ||||
|     { | ||||
|         self::bootKernel(array('environment' => 'test')); | ||||
|         static::$templating = static::$kernel | ||||
|                 ->getContainer()->get('templating'); | ||||
|         static::$templating = static::$container | ||||
|             ->get('templating'); | ||||
|         $pathToBundle = static::$container->getParameter('kernel.bundles_metadata')['ChillMainBundle']['path']; | ||||
|         //load templates in Tests/Resources/views | ||||
|         static::$kernel->getContainer()->get('twig.loader') | ||||
|                 ->addPath(static::$kernel->getContainer()->getParameter('kernel.root_dir') | ||||
|                     .'/Resources/views/', $namespace = 'tests'); | ||||
|         static::$container->get('twig.loader') | ||||
|             ->addPath($pathToBundle.'/Resources/test/views/', $namespace = 'tests'); | ||||
|     } | ||||
|      | ||||
|     public function testNormalMenu() | ||||
|     { | ||||
|         $content = static::$templating->render('@tests/menus/normalMenu.html.twig'); | ||||
|         $crawler = new Crawler($content); | ||||
|          | ||||
|         $ul = $crawler->filter('ul')->getNode(0); | ||||
|         $this->assertEquals( 'ul', $ul->tagName); | ||||
|          | ||||
|         $lis = $crawler->filter('ul')->children(); | ||||
|         $this->assertEquals(3, count($lis)); | ||||
|          | ||||
|         $lis->each(function(Crawler $node, $i) { | ||||
|                 $this->assertEquals('li', $node->getNode(0)->tagName); | ||||
|                  | ||||
|                 $a = $node->children()->getNode(0); | ||||
|                 $this->assertEquals('a', $a->tagName); | ||||
|                 switch($i) { | ||||
|                     case 0:  | ||||
|                         $this->assertEquals('/dummy?param=fake', $a->getAttribute('href')); | ||||
|                         $this->assertEquals('active', $a->getAttribute('class')); | ||||
|                         $this->assertEquals('test0', $a->nodeValue); | ||||
|                         break; | ||||
|                     case 1: | ||||
|                         $this->assertEquals('/dummy1?param=fake', $a->getAttribute('href')); | ||||
|                         $this->assertEmpty($a->getAttribute('class')); | ||||
|                         $this->assertEquals('test1', $a->nodeValue); | ||||
|                         break; | ||||
|                     case 3: | ||||
|                         $this->assertEquals('/dummy2/fake', $a->getAttribute('href')); | ||||
|                         $this->assertEmpty($a->getAttribute('class')); | ||||
|                         $this->assertEquals('test2', $a->nodeValue); | ||||
|                 } | ||||
|         }); | ||||
|     } | ||||
|      | ||||
|     public function testMenuOverrideTemplate() | ||||
|     { | ||||
|         $this->markTestSkipped("this hacks seems not working now"); | ||||
|         $content = static::$templating->render('@tests/menus/overrideTemplate.html.twig'); | ||||
|         $this->assertEquals('fake template', $content); | ||||
|         $this->assertContains('ul', $content,  | ||||
|             "test that the file contains an ul tag" | ||||
|         ); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -28,7 +28,7 @@ class MenuComposerTest extends KernelTestCase | ||||
|     public function setUp() | ||||
|     { | ||||
|         self::bootKernel(array('environment' => 'test')); | ||||
|         $this->menuComposer = static::$kernel->getContainer() | ||||
|         $this->menuComposer = static::$container | ||||
|                 ->get('chill.main.menu_composer'); | ||||
|     } | ||||
|      | ||||
| @@ -42,50 +42,5 @@ class MenuComposerTest extends KernelTestCase | ||||
|         $routes = $this->menuComposer->getRoutesFor('dummy0'); | ||||
|          | ||||
|         $this->assertInternalType('array', $routes); | ||||
|         $this->assertCount(3, $routes); | ||||
|         //check that the keys are sorted | ||||
|         $orders = array_keys($routes); | ||||
|         foreach ($orders as $key => $order){ | ||||
|             if (array_key_exists($key + 1, $orders)) { | ||||
|                 $this->assertGreaterThan($order, $orders[$key + 1], | ||||
|                         'Failing to assert that routes are ordered'); | ||||
|             } | ||||
|         } | ||||
|          | ||||
|         //check that the array are identical, order is not important : | ||||
|          | ||||
|         $expected = array( | ||||
|             50 => array( | ||||
|                 'key'   => 'chill_main_dummy_0', | ||||
|                 'label' => 'test0', | ||||
|                 'otherkey' => 'othervalue' | ||||
|                 ), | ||||
|             51 => array( | ||||
|                 'key'   => 'chill_main_dummy_1', | ||||
|                 'label' => 'test1', | ||||
|                 'helper'=> 'great helper' | ||||
|             ), | ||||
|             52 => array( | ||||
|                 'key'   => 'chill_main_dummy_2', | ||||
|                 'label' => 'test2' | ||||
|             )); | ||||
|          | ||||
|          | ||||
|         foreach ($expected as $order => $route ){ | ||||
|              | ||||
|         } | ||||
|          | ||||
|         //compare arrays | ||||
|         foreach($expected as $order => $route) { | ||||
|             //check the key are the one expected | ||||
|             $this->assertTrue(isset($routes[$order])); | ||||
|              | ||||
|             if (isset($routes[$order])){ #avoid an exception if routes with order does not exists | ||||
|                 //sort arrays. Order matters for phpunit::assertSame | ||||
|                 ksort($route); | ||||
|                 ksort($routes[$order]); | ||||
|                 $this->assertSame($route, $routes[$order]); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -86,7 +86,3 @@ login_check: | ||||
|  | ||||
| logout: | ||||
|     path:    /logout | ||||
|  | ||||
| chill_main_test: | ||||
|     path: /{_locale}/main/test | ||||
|     controller: Chill\MainBundle\Controller\DefaultController::testAction | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| namespace Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\Result; | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\SocialAction; | ||||
| use App\Repository\Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkRepository; | ||||
| use Chill\PersonBundle\Entity\SocialWork\Result; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialAction; | ||||
| use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkRepository; | ||||
| use Chill\MainBundle\Entity\User; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use Chill\ThirdPartyBundle\Entity\ThirdParty; | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| namespace Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\Goal; | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\Result; | ||||
| use App\Repository\Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoalRepository; | ||||
| use Chill\PersonBundle\Entity\SocialWork\Goal; | ||||
| use Chill\PersonBundle\Entity\SocialWork\Result; | ||||
| use Chill\PersonBundle\Repository\AccompanyingPeriod\AccompanyingPeriodWorkGoalRepository; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|   | ||||
| @@ -22,15 +22,17 @@ namespace Chill\PersonBundle\Entity; | ||||
|  * along with this program.  If not, see <http://www.gnu.org/licenses/>. | ||||
|  */ | ||||
|  | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Criteria; | ||||
| use ArrayIterator; | ||||
| use Chill\MainBundle\Entity\Center; | ||||
| use Chill\MainBundle\Entity\Country; | ||||
| use Chill\PersonBundle\Entity\MaritalStatus; | ||||
| use Chill\MainBundle\Entity\HasCenterInterface; | ||||
| use Chill\MainBundle\Entity\Address; | ||||
| use DateTime; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Criteria; | ||||
| use Symfony\Component\Validator\Context\ExecutionContextInterface; | ||||
|  | ||||
| /** | ||||
| @@ -1008,32 +1010,28 @@ class Person implements HasCenterInterface | ||||
|     /** | ||||
|      * By default, the addresses are ordered by date, descending (the most | ||||
|      * recent first) | ||||
|      * | ||||
|      * @return \Chill\MainBundle\Entity\Address[] | ||||
|      */ | ||||
|     public function getAddresses() | ||||
|     public function getAddresses(): ArrayCollection | ||||
|     { | ||||
|         return $this->addresses; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @param \DateTime|null $date | ||||
|      * @return null | ||||
|      */ | ||||
|     public function getLastAddress(\DateTime $date = null) | ||||
|     public function getLastAddress(DateTime $from = null) | ||||
|     { | ||||
|         if ($date === null) { | ||||
|             $date = new \DateTime('now'); | ||||
|         } | ||||
|         $from ??= new DateTime('now'); | ||||
|  | ||||
|         $addresses = $this->getAddresses(); | ||||
|         /** @var ArrayIterator $addressesIterator */ | ||||
|         $addressesIterator = $this->getAddresses() | ||||
|             ->filter(static fn (Address $address): bool => $address->getValidFrom() <= $from) | ||||
|             ->getIterator(); | ||||
|  | ||||
|         if ($addresses == null) { | ||||
|         $addressesIterator->uasort( | ||||
|             static fn (Address $left, Address $right): int => $right->getValidFrom() <=> $left->getValidFrom() | ||||
|         ); | ||||
|  | ||||
|             return null; | ||||
|         } | ||||
|  | ||||
|         return $addresses->first(); | ||||
|         return [] === ($addresses = iterator_to_array($addressesIterator)) ? | ||||
|             null : | ||||
|             current($addresses); | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Entity\SocialWork; | ||||
|  | ||||
| use App\Repository\Chill\PersonBundle\Entity\SocialWork\EvaluationRepository; | ||||
| use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|  | ||||
| /** | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Entity\SocialWork; | ||||
|  | ||||
| use App\Repository\Chill\PersonBundle\Entity\SocialWork\GoalRepository; | ||||
| use Chill\PersonBundle\Repository\SocialWork\GoalRepository; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|   | ||||
| @@ -1,10 +1,10 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Entity\SocialWork; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; | ||||
| use App\Entity\Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; | ||||
| use App\Repository\Chill\PersonBundle\Entity\SocialWork\ResultRepository; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; | ||||
| use Chill\PersonBundle\Repository\SocialWork\ResultRepository; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Entity\SocialWork; | ||||
|  | ||||
| use App\Repository\Chill\PersonBundle\Entity\SocialWork\SocialActionRepository; | ||||
| use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
| namespace Chill\PersonBundle\Entity\SocialWork; | ||||
|  | ||||
| namespace App\Entity\Chill\PersonBundle\Entity\SocialWork; | ||||
|  | ||||
| use App\Repository\Chill\PersonBundle\Entity\SocialWork\SocialIssueRepository; | ||||
| use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository; | ||||
| use Doctrine\Common\Collections\ArrayCollection; | ||||
| use Doctrine\Common\Collections\Collection; | ||||
| use Doctrine\ORM\Mapping as ORM; | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| namespace Chill\PersonBundle\Repository\AccompanyingPeriod; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkGoal; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| namespace Chill\PersonBundle\Repository\AccompanyingPeriod; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -23,6 +23,7 @@ | ||||
| namespace Chill\PersonBundle\Repository; | ||||
|  | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Repository\SocialWork; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\Evaluation; | ||||
| use Chill\PersonBundle\Entity\SocialWork\Evaluation; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Repository\SocialWork; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\Goal; | ||||
| use Chill\PersonBundle\Entity\SocialWork\Goal; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Repository\SocialWork; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\Result; | ||||
| use Chill\PersonBundle\Entity\SocialWork\Result; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Repository\SocialWork; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\SocialAction; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialAction; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -1,8 +1,8 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Repository\Chill\PersonBundle\Entity\SocialWork; | ||||
| namespace Chill\PersonBundle\Repository\SocialWork; | ||||
|  | ||||
| use App\Entity\Chill\PersonBundle\Entity\SocialWork\SocialIssue; | ||||
| use Chill\PersonBundle\Entity\SocialWork\SocialIssue; | ||||
| use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||||
| use Doctrine\Persistence\ManagerRegistry; | ||||
|  | ||||
|   | ||||
| @@ -38,7 +38,7 @@ class AccompanyingPeriodNormalizer implements NormalizerInterface, NormalizerAwa | ||||
|             'remark' => $period->getRemark(), | ||||
|             'participations' => $this->normalizer->normalize($period->getParticipations(), $format), | ||||
|             'closingMotive' => $this->normalizer->normalize($period->getClosingMotive(), $format), | ||||
|             'user' => $period->getUser() ? $this->normalize($period->getUser(), $format) : null, | ||||
|             'user' => $this->normalizer->normalize($period->getUser(), $format), | ||||
|             'step' => $period->getStep(), | ||||
|             'origin' => $this->normalizer->normalize($period->getOrigin(), $format), | ||||
|             'intensity' => $period->getIntensity(), | ||||
|   | ||||
| @@ -55,7 +55,7 @@ class PersonNormalizer implements | ||||
|             'id' => $person->getId(), | ||||
|             'firstName' => $person->getFirstName(), | ||||
|             'lastName' => $person->getLastName(), | ||||
|             'birthdate' => $person->getBirthdate(), | ||||
|             'birthdate' => $person->getBirthdate() ? $this->normalizer->normalize($person->getBirthdate()) : null, | ||||
|             'center' => $this->normalizer->normalize($person->getCenter()) | ||||
|         ]; | ||||
|     } | ||||
|   | ||||
| @@ -24,6 +24,10 @@ namespace Chill\PersonBundle\Tests\Entity; | ||||
|  | ||||
| use Chill\PersonBundle\Entity\Person; | ||||
| use Chill\PersonBundle\Entity\AccompanyingPeriod; | ||||
| use Chill\MainBundle\Entity\Address; | ||||
| use DateInterval; | ||||
| use DateTime; | ||||
| use Generator; | ||||
|  | ||||
| /** | ||||
|  * Unit tests for the person Entity | ||||
| @@ -151,4 +155,54 @@ class PersonTest extends \PHPUnit\Framework\TestCase | ||||
|          | ||||
|         $this->assertEquals($r['result'], Person::ERROR_ADDIND_PERIOD_AFTER_AN_OPEN_PERIOD); | ||||
|     } | ||||
|  | ||||
|     public function dateProvider(): Generator | ||||
|     { | ||||
|         yield [(DateTime::createFromFormat('Y-m-d', '2021-01-05'))->settime(0, 0)]; | ||||
|         yield [(DateTime::createFromFormat('Y-m-d', '2021-02-05'))->settime(0, 0)]; | ||||
|         yield [(DateTime::createFromFormat('Y-m-d', '2021-03-05'))->settime(0, 0)]; | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|      * @dataProvider dateProvider | ||||
|      */ | ||||
|     public function testGetLastAddress(DateTime $date) | ||||
|     { | ||||
|         $p = new Person($date); | ||||
|  | ||||
|         // Make sure that there is no last address. | ||||
|         $this::assertNull($p->getLastAddress()); | ||||
|  | ||||
|         // Take an arbitrary date before the $date in parameter. | ||||
|         $addressDate = clone $date; | ||||
|  | ||||
|         // 1. Smoke test: Test that the first address added is the last one. | ||||
|         $address1 = (new Address())->setValidFrom($addressDate->sub(new DateInterval('PT180M'))); | ||||
|         $p->addAddress($address1); | ||||
|  | ||||
|         $this::assertCount(1, $p->getAddresses()); | ||||
|         $this::assertSame($address1, $p->getLastAddress()); | ||||
|  | ||||
|         // 2. Add an older address, which should not be the last address. | ||||
|         $addressDate2 = clone $addressDate; | ||||
|         $address2 = (new Address())->setValidFrom($addressDate2->sub(new DateInterval('PT30M'))); | ||||
|         $p->addAddress($address2); | ||||
|  | ||||
|         $this::assertCount(2, $p->getAddresses()); | ||||
|         $this::assertSame($address1, $p->getLastAddress()); | ||||
|  | ||||
|         // 3. Add a newer address, which should be the last address. | ||||
|         $addressDate3 = clone $addressDate; | ||||
|         $address3 = (new Address())->setValidFrom($addressDate3->add(new DateInterval('PT30M'))); | ||||
|         $p->addAddress($address3); | ||||
|  | ||||
|         $this::assertCount(3, $p->getAddresses()); | ||||
|         $this::assertSame($address3, $p->getLastAddress()); | ||||
|  | ||||
|         // 4. Get the last address from a specific date. | ||||
|         $this::assertEquals($address1, $p->getLastAddress($addressDate)); | ||||
|         $this::assertEquals($address2, $p->getLastAddress($addressDate2)); | ||||
|         $this::assertEquals($address3, $p->getLastAddress($addressDate3)); | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
 Submodule tests/app updated: f15fff5f2a...8e74ea90b1
									
								
							
		Reference in New Issue
	
	Block a user