3 Commits

Author SHA1 Message Date
  raphael 74e8fc791b BGC-192 @fixed image des sequences 3 years ago
  raphael 88b43215ed merge branche 3 years ago
  raphael 50d86f6bb7 BGC-171 3 years ago

+ 8
- 8
.env.test View File

@@ -1,10 +1,10 @@
1
-    APP_ENV=test
2
-    APP_URL_PREFIX="/phoenix"
3
-    APP_LANGUAGE="fr"
1
+APP_ENV=test
2
+APP_URL_PREFIX="/phoenix"
3
+APP_LANGUAGE="fr"
4 4
 
5
-    # define your env variables for the test env here
6
-    KERNEL_CLASS='Logipro\Phoenix\Kernel\AppKernel'
7
-    APP_SECRET='s$cretf0rt3st'
8
-    SYMFONY_DEPRECATIONS_HELPER=999999
5
+# define your env variables for the test env here
6
+KERNEL_CLASS='Logipro\Phoenix\Kernel\AppKernel'
7
+APP_SECRET='s$cretf0rt3st'
8
+SYMFONY_DEPRECATIONS_HELPER=999999
9 9
 
10
-    DATABASE_TEST_URL="sqlite:///%kernel.project_dir%/var/app.db"
10
+DATABASE_TEST_URL="sqlite:///%kernel.project_dir%/var/app.db"

+ 4
- 3
assets/exclusive/js/back-office/learning_path/learning_path_editor.js View File

@@ -1188,9 +1188,10 @@ function showFormEditSequenceItem(action, sequenceItem) {
1188 1188
 
1189 1189
         // Dévérouillage de la page
1190 1190
         $(document).phxUnlock();
1191
-        
1192
-        // Envoi event pour informer que le formulaire est affiché
1193
-        sequenceItem.trigger("logiprolearningpathsequenceformopen");
1191
+        if (sequenceItem)
1192
+        {
1193
+            sequenceItem.trigger("logiprolearningpathsequenceformopen");
1194
+        }
1194 1195
     });
1195 1196
 }
1196 1197
 

+ 2
- 2
composer.json View File

@@ -12,7 +12,7 @@
12 12
 	},
13 13
 	"autoload-dev": {
14 14
         "psr-4": {
15
-            "Logipro\\Phoenix\\tests\\": "tests/"
15
+            "Logipro\\Phoenix\\tests\\": "tests"
16 16
         }
17 17
     },
18 18
 	"require" : {
@@ -48,7 +48,7 @@
48 48
 		"stripe/stripe-php": "^6.37",
49 49
 		"symfony/http-client": "~4.0",
50 50
 		"logipro/scormbundle": "dev-master",
51
-		"sensio/framework-extra-bundle": "^5.4",
51
+		"sensio/framework-extra-bundle": "^5.5",
52 52
 		"php-translation/symfony-bundle": "^0.9.1",
53 53
 		"wikimedia/composer-merge-plugin": "dev-master",
54 54
 		"symfony/filesystem": "~4.0"

+ 0
- 5
config/services.yaml View File

@@ -120,11 +120,6 @@ services:
120 120
     tags:
121 121
         - { name: twig.extension }
122 122
 
123
-  # Service de duplication des entités
124
-  Logipro\Phoenix\Service\EntityDuplicator:
125
-    public: true
126
-    arguments: ['@service_container']
127
-
128 123
   Logipro\Phoenix\EntityListener\ImageListener:
129 124
 
130 125
   phoenix.bundle.learningpath:

+ 17
- 23
src/Phoenix/Component/PhxCrypt.php View File

@@ -1,4 +1,5 @@
1 1
 <?php
2
+
2 3
 namespace Logipro\Phoenix\Component;
3 4
 
4 5
 class PhxCrypt
@@ -11,58 +12,51 @@ class PhxCrypt
11 12
         return serialize($data);
12 13
     }
13 14
 
14
-    public static function crypt($data,$withDate = true)
15
+    public static function crypt($data, $withDate = true) : string
15 16
     {
16
-        if (is_string($data))
17
-        {
17
+        if (is_string($data)) {
18 18
             $data = array('_s_' => $data);
19 19
         }
20
-        
20
+
21 21
         $data['_d_'] = time();
22 22
 
23 23
         $data = self::serialize($data);
24
-		$openSslCrypt = openssl_encrypt($data, 'aes128',self::$cryptPassword,0,self::$cryptIV);
24
+        $openSslCrypt = openssl_encrypt($data, 'aes128', self::$cryptPassword, 0, self::$cryptIV);
25 25
         return rtrim(strtr(($openSslCrypt), '+/', '-_'), '=');
26 26
     }
27 27
 
28
-    public static function decrypt($data,$duration = null)
28
+    public static function decrypt($data, $duration = null)
29 29
     {
30 30
         $padding = str_repeat('=', 4 - (strlen($data) % 4));
31
-        
31
+
32 32
         // décodage base64
33
-        $decoded = (strtr($data.$padding, '-_', '+/'));
34
-        if (!$decoded)
35
-        {
33
+        $decoded = (strtr($data . $padding, '-_', '+/'));
34
+        if (!$decoded) {
36 35
             return null;
37 36
         }
38 37
 
39 38
         // décodage ssl
40
-        $decoded = openssl_decrypt ($decoded, 'aes128',self::$cryptPassword,0,self::$cryptIV);
41
-        if (!$decoded)
42
-        {
39
+        $decoded = openssl_decrypt($decoded, 'aes128', self::$cryptPassword, 0, self::$cryptIV);
40
+        if (!$decoded) {
43 41
             return null;
44 42
         }
45 43
 
46 44
         // désérialization
47 45
         $decoded = unserialize($decoded);
48
-        if (!is_array($decoded))
49
-        {
46
+        if (!is_array($decoded)) {
50 47
             return null;
51 48
         }
52
-        
53
-        if ($duration)
54
-        {
55
-            if ($decoded['_d_'] + $duration <= time())
56
-            {
49
+
50
+        if ($duration) {
51
+            if ($decoded['_d_'] + $duration <= time()) {
57 52
                 return null;
58 53
             }
59 54
         }
60 55
 
61
-        if (isset($decoded['_s_']))
62
-        {
56
+        if (isset($decoded['_s_'])) {
63 57
             return $decoded['_s_'];
64 58
         }
65 59
         unset($decoded['_d_']);
66 60
         return $decoded;
67 61
     }
68
-}
62
+}

+ 3
- 1
src/Phoenix/Controller/LearningSpace/LoginController.php View File

@@ -118,13 +118,15 @@ class LoginController extends LearningSpaceController
118 118
 		}
119 119
 		$token = $request->get('token');
120 120
 
121
+		$tokenData = null;
121 122
 		if (!$token) {
122 123
 			throw $this->createNotFoundException($this->translate('error_403_message'));
123 124
 		}
124
-
125 125
 		$tokenData = PasswordRecoverNotifyLearner::decrytUrlArg($token);
126 126
 		if (!$tokenData) {
127
+
127 128
 			$response = new Response('', 404);
129
+
128 130
 			// token expiré
129 131
 			$parameters = array(
130 132
 				'text' => $this->translate('ls_password_expired'),

+ 40
- 58
src/Phoenix/Service/EntityDuplicator.php View File

@@ -9,36 +9,40 @@ use Logipro\Phoenix\Entity\SequenceItem\ActivityPackage;
9 9
 use Logipro\Phoenix\Entity\SequenceItem\SequenceItem;
10 10
 use Logipro\Phoenix\Exception\PhoenixException;
11 11
 use Logipro\Phoenix\Package\Common\AbstractPackageFile;
12
-use Symfony\Component\DependencyInjection\ContainerAwareInterface;
13
-use Symfony\Component\DependencyInjection\ContainerAwareTrait;
14
-use Symfony\Component\DependencyInjection\ContainerInterface;
15 12
 use Logipro\Phoenix\Entity\Session\Session;
16 13
 use Symfony\Component\Security\Core\Security;
17 14
 use Logipro\Phoenix\Entity\ProgramItem;
18 15
 use Doctrine\Common\Collections\ArrayCollection;
16
+use Logipro\Bundle\SCORMBundle\Services\ScormEngine;
17
+use Symfony\Component\Translation\TranslatorInterface;
18
+use Doctrine\ORM\EntityManagerInterface;
19 19
 
20 20
 /**
21 21
  * Service de duplication des entités.
22 22
  */
23
-class EntityDuplicator implements ContainerAwareInterface
23
+class EntityDuplicator
24 24
 {
25
-    use ContainerAwareTrait;
26
-
27 25
     private $security;
28 26
     private $fileUploader;
27
+    private $entityManager;
28
+    private $translator;
29
+    private $scormEngine;
29 30
 
30 31
     /**
31 32
      * Constructeur.
32
-     * @param ContainerInterface $container
33 33
      */
34 34
     public function __construct(
35
-        ContainerInterface $container,
36 35
         Security $security,
37
-        FileUploader $fileUploader
36
+        FileUploader $fileUploader,
37
+        EntityManagerInterface $entityManager,
38
+        TranslatorInterface $translator,
39
+        ScormEngine $scormEngine
38 40
     ) {
39
-        $this->setContainer($container);
40 41
         $this->security = $security;
41 42
         $this->fileUploader = $fileUploader;
43
+        $this->entityManager = $entityManager;
44
+        $this->translator = $translator;
45
+        $this->scormEngine = $scormEngine;
42 46
     }
43 47
 
44 48
     /**
@@ -49,29 +53,7 @@ class EntityDuplicator implements ContainerAwareInterface
49 53
      */
50 54
     public function duplicateLearningPath(LearningPath $learningPath, Session $session = null, bool $isTemplate = false): LearningPath
51 55
     {
52
-        $em = $this->getDoctrine()->getManager();
53
-
54
-        $newLearningPath = null;
55
-
56
-        // Si c'est une duplication de template
57
-        if ($isTemplate) {
58
-            $title = '[copie] ' . $learningPath->getTitle();
59
-            $newLearningPath = $this->cloneLearningPath($learningPath, true);
60
-            $newLearningPath->setTitle($title);
61
-        } else {
62
-            $newLearningPath = $this->cloneLearningPath($learningPath);
63
-        }
64
-
65
-        $autor = $this->security->getUser();
66
-        $newLearningPath->setCreatingUser($autor);
67
-
68
-        if ($session) {
69
-            $newLearningPath->setSession($session);
70
-            $session->setLearningPath($newLearningPath);
71
-        }
72
-
73
-        $em->persist($newLearningPath);
74
-        $em->flush();
56
+        $newLearningPath = $this->cloneLearningPath($learningPath, $session, $isTemplate);
75 57
 
76 58
         // Duplication des cours au niveau du moteur SCORM
77 59
         $this->duplicateScormCoursesFromPaths($learningPath, $newLearningPath);
@@ -79,7 +61,7 @@ class EntityDuplicator implements ContainerAwareInterface
79 61
         return $newLearningPath;
80 62
     }
81 63
 
82
-    private function cloneLearningPath(LearningPath $learningPath, bool $isTemplate = false): LearningPath
64
+    protected function cloneLearningPath(LearningPath $learningPath, Session $session = null, bool $isTemplate = false): LearningPath
83 65
     {
84 66
         //FIXME Peut-on copier un parcours qui n'est pas un gabarit ?
85 67
         if (!$learningPath->isTemplate()) {
@@ -89,6 +71,9 @@ class EntityDuplicator implements ContainerAwareInterface
89 71
         // Clonage du parcours (et de ses éléments enfants en cascade)
90 72
         $pathCopy = clone $learningPath;
91 73
 
74
+        $autor = $this->security->getUser();
75
+        $pathCopy->setCreatingUser($autor);
76
+
92 77
         // Copie les séquences
93 78
         $sequences = new ArrayCollection();
94 79
         foreach ($learningPath->getSequences() as $sequence) {
@@ -112,10 +97,22 @@ class EntityDuplicator implements ContainerAwareInterface
112 97
         $pathCopy->setTemplate($learningPath);
113 98
         $pathCopy->setIsTemplate($isTemplate);
114 99
 
100
+        if ($isTemplate) {
101
+            $pathCopy->setTitle('[copie] ' . $learningPath->getTitle());
102
+        }
103
+
104
+        if ($session) {
105
+            $pathCopy->setSession($session);
106
+            $session->setLearningPath($pathCopy);
107
+        }
108
+
109
+        $this->entityManager->persist($pathCopy);
110
+        $this->entityManager->flush();
111
+
115 112
         return $pathCopy;
116 113
     }
117 114
 
118
-    private function cloneSequence(Sequence $sequence): Sequence
115
+    protected function cloneSequence(Sequence $sequence): Sequence
119 116
     {
120 117
         $sequenceCopy = clone $sequence;
121 118
         // Copie les éléments
@@ -144,13 +141,13 @@ class EntityDuplicator implements ContainerAwareInterface
144 141
         return $sequenceCopy;
145 142
     }
146 143
 
147
-    private function cloneProgramItem(ProgramItem $programItem): ProgramItem
144
+    protected function cloneProgramItem(ProgramItem $programItem): ProgramItem
148 145
     {
149 146
         // FIXME à corriger
150 147
         return clone $programItem;
151 148
     }
152 149
 
153
-    private function cloneSequenceItem(SequenceItem $sequenceItem): SequenceItem
150
+    protected function cloneSequenceItem(SequenceItem $sequenceItem): SequenceItem
154 151
     {
155 152
         // FIXME à corriger
156 153
         return clone $sequenceItem;
@@ -168,14 +165,13 @@ class EntityDuplicator implements ContainerAwareInterface
168 165
     {
169 166
         // Vérification de l'existance des parcours
170 167
         if (empty($originalPath) || empty($newPath)) {
171
-            throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_no_learning_path'));
168
+            throw new PhoenixException($this->translator->trans('exception_duplicator_no_learning_path'));
172 169
         }
173 170
 
174
-        $em = $this->getDoctrine()->getManager();
175
-        $sequenceRepository = $em->getRepository(Sequence::class);
171
+        $sequenceRepository = $this->entityManager->getRepository(Sequence::class);
176 172
 
177 173
         // Récupération du service ScormEngine
178
-        $scormEngine = $this->container->get('scorm.services.engine');
174
+        $scormEngine = $this->scormEngine;
179 175
 
180 176
         // On récupère les séquences par repository avec classement croissant des id
181 177
         $originalSequences = $sequenceRepository->findBy(array('learningPath' => $originalPath), array('sequenceId' => 'asc'));
@@ -183,7 +179,7 @@ class EntityDuplicator implements ContainerAwareInterface
183 179
 
184 180
         // Vérification de l'existance des séquences
185 181
         if (empty($originalSequences) || empty($newSequences)) {
186
-            throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_no_sequences'));
182
+            throw new PhoenixException($this->translator->trans('exception_duplicator_no_sequences'));
187 183
         }
188 184
 
189 185
         // Pour chaque Sequence
@@ -197,7 +193,7 @@ class EntityDuplicator implements ContainerAwareInterface
197 193
 
198 194
             // Vérification de l'existance des items
199 195
             if (empty($originalItems) || empty($newItems)) {
200
-                throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_no_items'));
196
+                throw new PhoenixException($this->translator->trans('exception_duplicator_no_items'));
201 197
             }
202 198
 
203 199
             // Pour chaque item
@@ -208,24 +204,10 @@ class EntityDuplicator implements ContainerAwareInterface
208 204
                     $new  = $newItems[$j];
209 205
                     $response = $scormEngine->duplicateCourse($original->getSequenceItemId(), $new->getSequenceItemId());
210 206
                     if (400 == $response['code']) {
211
-                        throw new PhoenixException($this->container->get('translator')->trans('exception_duplicator_engine_course'));
207
+                        throw new PhoenixException($this->translator->trans('exception_duplicator_engine_course'));
212 208
                     }
213 209
                 }
214 210
             }
215 211
         }
216 212
     }
217
-
218
-    /**
219
-     *
220
-     * @throws \LogicException
221
-     * @return ManagerRegistry
222
-     */
223
-    protected function getDoctrine(): ManagerRegistry
224
-    {
225
-        if (!$this->container->has('doctrine')) {
226
-            throw new \LogicException('The DoctrineBundle is not registered in your application. Try running "composer require symfony/orm-pack".');
227
-        }
228
-
229
-        return $this->container->get('doctrine');
230
-    }
231 213
 }

+ 15
- 10
src/Phoenix/Service/FileUploader.php View File

@@ -175,20 +175,25 @@ implements FileUploaderInterface
175 175
 		return uniqid() . '.' . pathinfo($oldFileName, PATHINFO_EXTENSION);
176 176
 	}
177 177
 
178
-	public function cloneFile(AbstractEntity $entity, string $propertyName): string
178
+	public function cloneFile(AbstractEntity $entity, string $propertyName)
179 179
 	{
180 180
 		$filesystem = new Filesystem();
181 181
 		$oldFileName = $this->getEntityValue($entity, $propertyName);
182
-		$newFileName = $this->generateNewName($oldFileName);
183
-
184
-		try {
185
-			$filesystem->copy(
186
-				$this->buildUploadPublicPath($oldFileName, $entity, $propertyName),
187
-				$this->buildUploadPublicPath($newFileName, $entity, $propertyName)
188
-			);
189
-		} catch (\Exception $exp) {
190
-			dd($exp->getMessage());
182
+		$newFileName = null;
183
+		if ($oldFileName)
184
+		{
185
+			$newFileName = $this->generateNewName($oldFileName);
186
+
187
+			try {
188
+				$filesystem->copy(
189
+					$this->buildUploadPublicPath($oldFileName, $entity, $propertyName),
190
+					$this->buildUploadPublicPath($newFileName, $entity, $propertyName)
191
+				);
192
+			} catch (\Exception $exp) {
193
+				dd($exp->getMessage());
194
+			}
191 195
 		}
196
+		
192 197
 
193 198
 		return $newFileName;
194 199
 	}

+ 2
- 1
tests/Phoenix/Component/ExpiredPhxCrypt.php View File

@@ -6,9 +6,10 @@ use Logipro\Phoenix\Component\PhxCrypt;
6 6
 
7 7
 class ExpiredPhxCrypt extends PhxCrypt
8 8
 {
9
-    protected static function serialize(array $data):string
9
+    protected static function serialize($data): string
10 10
     {
11 11
         $data['_d_'] = 0;
12
+
12 13
         return parent::serialize($data);
13 14
     }
14 15
 }

+ 38
- 62
tests/Phoenix/Controller/LearningSpace/LoginControllerTest.php View File

@@ -1,99 +1,75 @@
1 1
 <?php
2 2
 
3
-namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice\Session\Follow;
3
+namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice;
4 4
 
5
+
6
+use Symfony\Component\Routing\Exception\RouteNotFoundException;
7
+use Logipro\Phoenix\EventSubscriber\LearningSpace\PasswordRecoverNotifyLearner;
5 8
 use Logipro\Phoenix\Component\PhxCrypt;
6 9
 use Logipro\Phoenix\tests\Phoenix\Component\ExpiredPhxCrypt;
7 10
 use Logipro\Phoenix\tests\PhxWebTestCase;
8
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
-
10 11
 
11 12
 class LoginControllerTest extends PhxWebTestCase
12 13
 {
13
-    /*
14
-    sera développé quand les fatory seront présents
15
-    public function testManageDefinePasswordWithUser()
16
-    { }*/
17
-
18
-    public function testManageDefinePasswordWithoutToken()
14
+    public function testManageDefinePasswordWitoutToken()
19 15
     {
20 16
         $client = static::createClient();
21
-
22
-        $params = array();
23
-        $crawler = $client->request(
24
-            'GET',
25
-            $this->getRoutePath('ls_password_define'),
26
-            $params
27
-        );
28
-
29
-        $this->assertSame(404, $client->getResponse()->getStatusCode());
17
+        $client->request('GET', $this->getRoutePath('ls_password_define'));
18
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
30 19
     }
31
-    public function testManageDefinePasswordWithEmptyToken()
20
+
21
+    public function testManageDefinePasswordWithEmpty()
32 22
     {
33 23
         $client = static::createClient();
34 24
 
35
-        $params = array(
36
-            'token' =>  ''
37
-        );
38
-        $crawler = $client->request(
39
-            'GET',
40
-            $this->getRoutePath('ls_password_define'),
41
-            $params
42
-        );
25
+        $parameters['token'] = '';
26
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
43 27
 
44
-        $this->assertSame(404, $client->getResponse()->getStatusCode());
28
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
45 29
     }
46 30
 
47
-    public function testManageDefinePasswordWithoutLearner()
31
+    public function testManageDefinePasswordWithExpiredToken()
48 32
     {
49 33
         $client = static::createClient();
50 34
 
51
-        $params = array(
52
-            'token' =>  PhxCrypt::crypt(array(
53
-                'learnerAccountId' => 0,
54
-                'route' => 'ls_homepage'
55
-            ))
56
-        );
57
-        $crawler = $client->request(
58
-            'GET',
59
-            $this->getRoutePath('ls_password_define'),
60
-            $params
35
+        $tokenData = array(
36
+            'learnerAccountId' => 0,
37
+            'route' => 'ls_homepage'
61 38
         );
39
+        $parameters['token'] = ExpiredPhxCrypt::crypt($tokenData);
40
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
62 41
 
63
-        $this->assertSame(404, $client->getResponse()->getStatusCode());
42
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
64 43
     }
65 44
 
66
-    public function testManageDefinePasswordWithExpiredToken()
45
+    public function testManageDefinePasswordWitoutLearnerAccount()
67 46
     {
68 47
         $client = static::createClient();
69 48
 
70
-        $params = array(
71
-            'token' =>  ExpiredPhxCrypt::crypt(array(
72
-                'learnerAccountId' => 0,
73
-                'route' => 'ls_homepage'
74
-            ))
49
+        $tokenData = array(
50
+            'learnerAccountId' => 0,
51
+            'route' => 'ls_homepage'
75 52
         );
76
-        $crawler = $client->request(
77
-            'GET',
78
-            $this->getRoutePath('ls_password_define'),
79
-            $params
80
-        );
81
-
82
-        $this->assertSame(404, $client->getResponse()->getStatusCode());
53
+        $parameters['token'] = PhxCrypt::crypt($tokenData);
54
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
55
+        $this->assertEquals(404, $client->getResponse()->getStatusCode());
83 56
     }
84 57
 
85
-    /*
86
-    // A TERMINER IL Y A UN PB AVEC L'AUTHENTIFCATION
87
-    public function testList()
58
+
59
+    /**
60
+     * sera développé quand on aura les fixtures de dev dans cette branche
61
+     */
62
+    /*public function testManageDefinePasswordWithLearnerAccount()
88 63
     {
89 64
         $client = static::createClient();
90 65
 
91
-        $crawler = $client->request(
92
-            'GET',
93
-            '/follow/sessions'
66
+        $tokenData = array(
67
+            'learnerAccountId' => ,
68
+            'route' => 'ls_homepage'
94 69
         );
70
+        $parameters['token'] = PhxCrypt::crypt($tokenData);
71
+        $client->request('GET', $this->getRoutePath('ls_password_define'), $parameters);
95 72
 
96
-        $this->assertSame(200, $client->getResponse()->getStatusCode());
97
-    }
98
-    */
73
+        $this->assertEquals(200, $client->getResponse()->getStatusCode());;
74
+    }*/
99 75
 }

+ 0
- 1
tests/Phoenix/Controller/NewBackOffice/Session/Follow/SessionFixedControllerTest.php View File

@@ -4,7 +4,6 @@ namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice\Session\Follow;
4 4
 
5 5
 use Logipro\Phoenix\tests\PhxWebTestCase;
6 6
 
7
-
8 7
 class SessionFiexedControllerTest extends PhxWebTestCase
9 8
 {
10 9
 

+ 1
- 1
tests/Phoenix/Service/AuthTokenGeneratorTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\tests\Service;
2
+namespace Logipro\Phoenix\tests\Phoenix\Service;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Service\AuthTokenGenerator;

+ 15
- 0
tests/Phoenix/Service/EntityDuplicatorForTest.php View File

@@ -0,0 +1,15 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Service;
4
+
5
+use Logipro\Phoenix\Service\EntityDuplicator;
6
+use Logipro\Phoenix\Entity\LearningPath;
7
+use Logipro\Phoenix\Entity\Session\Session;
8
+
9
+class EntityDuplicatorForTest extends EntityDuplicator
10
+{
11
+    public function cloneLearningPath(LearningPath $learningPath, Session $session = null, bool $isTemplate = false): LearningPath
12
+    {
13
+        return parent::cloneLearningPath($learningPath, $session, $isTemplate);
14
+    }
15
+}

+ 65
- 0
tests/Phoenix/Service/EntityDuplicatorTest.php View File

@@ -0,0 +1,65 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Service;
4
+
5
+use PHPUnit\Framework\TestCase;
6
+use Logipro\Phoenix\Entity\LearningPath;
7
+use Symfony\Component\DependencyInjection\ContainerInterface;
8
+use Symfony\Component\Security\Core\Security;
9
+use Logipro\Phoenix\Service\FileUploader;
10
+use Logipro\Phoenix\Repository\SequenceRepository;
11
+use Logipro\Bundle\SCORMBundle\Services\ScormEngine;
12
+use Symfony\Component\Translation\TranslatorInterface;
13
+use Logipro\Phoenix\Exception\PhoenixException;
14
+use Logipro\Phoenix\Entity\Sequence;
15
+use Logipro\Phoenix\tests\Phoenix\Service\EntityDuplicatorForTest;
16
+use Doctrine\ORM\EntityManagerInterface;
17
+
18
+/**
19
+ * Service de duplication des entités.
20
+ */
21
+class EntityDuplicatEntityDuplicatorTest extends TestCase
22
+{
23
+    /**
24
+     * test si le nom de l'image d'une sequence dupliqué est différent après le clonnage
25
+     * et si le nom est donné par le service fileUploader
26
+     */
27
+    public function testDuplicateLearningPathCopySequenceImage()
28
+    {
29
+        $securityMock = $this->createMock(Security::class);
30
+        $fileUploaderMock = $this->createMock(FileUploader::class);
31
+
32
+        $newName = 'newName';
33
+        $fileUploaderMock->method('cloneFile')->willReturn($newName);
34
+
35
+        $entityManagerMock = $this->createMock(EntityManagerInterface::class);
36
+        $repositoryMock = $this->createMock(SequenceRepository::class);
37
+        $translatorMock = $this->createMock(TranslatorInterface::class);
38
+        $scormEngineMock = $this->createMock(ScormEngine::class);
39
+
40
+        $learningPath = new LearningPath();
41
+        $learningPath->setIsTemplate(true);
42
+
43
+        $sequence = new Sequence();
44
+        $sequence->setImage('oldName');
45
+        $learningPath->setSequences([
46
+            $sequence
47
+        ]);
48
+        $service = new EntityDuplicatorForTest(
49
+            $securityMock,
50
+            $fileUploaderMock,
51
+            $entityManagerMock,
52
+            $translatorMock,
53
+            $scormEngineMock
54
+        );
55
+
56
+        $learningPathCopy = $service->cloneLearningPath($learningPath);
57
+
58
+        $sequencesClone = $learningPathCopy->getSequences();
59
+        $firstSequenceClone = $sequencesClone->first();
60
+        $this->assertSame(
61
+            $firstSequenceClone->getImage(),
62
+            $newName
63
+        );
64
+    }
65
+}

+ 1
- 1
tests/Phoenix/Service/SetupDocumentTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\tests\Service;
2
+namespace Logipro\Phoenix\tests\Phoenix\Service;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Service\AuthTokenGenerator;

+ 12
- 4
tests/PhxWebTestCase.php View File

@@ -3,19 +3,27 @@
3 3
 namespace Logipro\Phoenix\tests;
4 4
 
5 5
 use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
7 6
 
8 7
 class PhxWebTestCase extends WebTestCase
9 8
 {
10
-    protected function getRoutePath(string $path): string
9
+    /**
10
+     * retourne le chemin d'une route à partir de son nom
11
+     * @param string
12
+     * 
13
+     * @return string
14
+     */
15
+    protected function getRoutePath($name): string
11 16
     {
12 17
         self::bootKernel();
13 18
 
19
+        // returns the real and unchanged service container
14 20
         $container = self::$kernel->getContainer();
15 21
 
16
-        $route = $container->get('router')->getRouteCollection()->get($path);
22
+        $router = $container->get('router');
23
+
24
+        $route = $router->getRouteCollection()->get($name);
17 25
         if (!$route) {
18
-            throw new NotFoundHttpException();
26
+            throw new RouteNotFoundException('Aucune route ne correspond à ' . $name);
19 27
         }
20 28
         return $route->getPath();
21 29
     }

Loading…
Cancel
Save