|
@@ -0,0 +1,141 @@
|
|
1
|
+<?php
|
|
2
|
+
|
|
3
|
+namespace Muzich\CoreBundle\Tests\Controller;
|
|
4
|
+
|
|
5
|
+use Muzich\CoreBundle\lib\FunctionalTest;
|
|
6
|
+
|
|
7
|
+class FavoriteControllerTest extends FunctionalTest
|
|
8
|
+{
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+ * Test du listing de ses favoris
|
|
12
|
+ */
|
|
13
|
+ public function testMyFavorites()
|
|
14
|
+ {
|
|
15
|
+ $this->connectUser('bux', 'toor');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+ $this->exist('a[href="'.($url = $this->generateUrl('favorites_my_list')).'"]');
|
|
19
|
+ $link = $this->selectLink('a[href="'.$url.'"]');
|
|
20
|
+
|
|
21
|
+ $this->clickOnLink($link);
|
|
22
|
+ $this->isResponseSuccess();
|
|
23
|
+
|
|
24
|
+ $elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
|
25
|
+ SELECT e FROM MuzichCoreBundle:Element e
|
|
26
|
+ LEFT JOIN e.elements_favorites ef
|
|
27
|
+ WHERE ef.user = :uid
|
|
28
|
+ ")->setParameter('uid', $this->getUser()->getId())
|
|
29
|
+ ->getResult()
|
|
30
|
+ ;
|
|
31
|
+
|
|
32
|
+ $this->assertTrue(!is_null($elements));
|
|
33
|
+
|
|
34
|
+ if (count($elements))
|
|
35
|
+ {
|
|
36
|
+ foreach ($elements as $element)
|
|
37
|
+ {
|
|
38
|
+ $this->exist('li:contains("'.$element->getName().'")');
|
|
39
|
+ }
|
|
40
|
+ }
|
|
41
|
+ }
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+ * Test de la page listant les favoris d'un utilisateur
|
|
45
|
+ */
|
|
46
|
+ public function testHisFavorites()
|
|
47
|
+ {
|
|
48
|
+ $this->connectUser('bob', 'toor');
|
|
49
|
+
|
|
50
|
+ $bux = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
51
|
+ ->findOneByUsername('bux')
|
|
52
|
+ ;
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('favorite_user_list', array('slug' => 'bux')));
|
|
56
|
+
|
|
57
|
+ $elements = $this->getDoctrine()->getEntityManager()->createQuery("
|
|
58
|
+ SELECT e FROM MuzichCoreBundle:Element e
|
|
59
|
+ LEFT JOIN e.elements_favorites ef
|
|
60
|
+ WHERE ef.user = :uid
|
|
61
|
+ ")->setParameter('uid', $bux->getId())
|
|
62
|
+ ->getResult()
|
|
63
|
+ ;
|
|
64
|
+
|
|
65
|
+ $this->assertTrue(!is_null($elements));
|
|
66
|
+
|
|
67
|
+ if (count($elements))
|
|
68
|
+ {
|
|
69
|
+ foreach ($elements as $element)
|
|
70
|
+ {
|
|
71
|
+ $this->exist('li:contains("'.$element->getName().'")');
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+ }
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+ * Test d'ajout en favori un element, puis son retrait
|
|
78
|
+ * Ce test dépend actuellement du fait que l'élément testé se truove sur la
|
|
79
|
+ * page du groupe en question
|
|
80
|
+ */
|
|
81
|
+ public function testFavoritesManagement()
|
|
82
|
+ {
|
|
83
|
+ $this->connectUser('bob', 'toor');
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+ $DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Group')
|
|
87
|
+ ->findOneBySlug('dudeldrum')
|
|
88
|
+ ->getSingleResult()
|
|
89
|
+ ;
|
|
90
|
+
|
|
91
|
+ $element_DUDELDRUM = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
92
|
+ ->findOneByName('DUDELDRUM')
|
|
93
|
+ ;
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+ $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
|
97
|
+ 'user' => $this->getUser()->getId(),
|
|
98
|
+ 'element' => $element_DUDELDRUM->getId()
|
|
99
|
+ ));
|
|
100
|
+
|
|
101
|
+ $this->assertTrue(is_null($favorite));
|
|
102
|
+
|
|
103
|
+ $this->crawler = $this->client->request(
|
|
104
|
+ 'GET',
|
|
105
|
+ $this->generateUrl('show_group', array('slug' => $DUDELDRUM->getSlug()))
|
|
106
|
+ );
|
|
107
|
+
|
|
108
|
+ $this->isResponseSuccess();
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+ $this->exist('li:contains("DUDELDRUM")');
|
|
112
|
+ $this->exist('a[href="'.($url = $this->generateUrl('favorite_add', array(
|
|
113
|
+ 'id' => $element_DUDELDRUM->getId(),
|
|
114
|
+ 'token' => $this->getUser()->getPersonalHash()
|
|
115
|
+ ))).'"]');
|
|
116
|
+ $link = $this->selectLink('a[href="'.$url.'"]');
|
|
117
|
+ $this->clickOnLink($link);
|
|
118
|
+ $this->outputDebug();
|
|
119
|
+ $this->isResponseRedirection();
|
|
120
|
+ $this->followRedirection();
|
|
121
|
+ $this->isResponseSuccess();
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+ $this->exist('li:contains("DUDELDRUM")');
|
|
125
|
+ $this->notExist('a[href="'.$url.'"]');
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+ $favorite = $this->getDoctrine()->getRepository('MuzichCoreBundle:UsersElementsFavorites')->findOneBy(array(
|
|
129
|
+ 'user' => $this->getUser()->getId(),
|
|
130
|
+ 'element' => $element_DUDELDRUM->getId()
|
|
131
|
+ ));
|
|
132
|
+
|
|
133
|
+ $this->assertTrue(!is_null($favorite));
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+ $this->crawler = $this->client->request('GET', $this->generateUrl('favorites_my_list'));
|
|
137
|
+
|
|
138
|
+ $this->exist('li:contains("DUDELDRUM")');
|
|
139
|
+ }
|
|
140
|
+
|
|
141
|
+}
|