Browse Source

Evolution #82: Ecrire Tests pour embeds

bastien 13 years ago
parent
commit
4e75e31bb5

+ 1 - 1
src/Muzich/CoreBundle/ElementFactory/Site/DeezercomFactory.php View File

@@ -40,7 +40,7 @@ class DeezercomFactory extends BaseFactory
40 40
       $heigth = $this->container->getParameter('deezer_player_height');
41 41
       $embed = '<iframe scrolling="no" frameborder="0" allowTransparency="true" '
42 42
         .'src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true'
43
-        .'&width='.$width.'&height='.$heigth.'&cover=true&btn_popup=true&type='.$type.'&id='.$chaines[1].'&title=" '
43
+        .'&width='.$width.'&height='.$heigth.'&cover=true&btn_popup=true&type='.$type.'&id='.$element_id.'&title=" '
44 44
         .'width="'.$width.'" height="'.$heigth.'"></iframe>'
45 45
       ;
46 46
     }

+ 4 - 3
src/Muzich/CoreBundle/ElementFactory/Site/SoundcloudcomFactory.php View File

@@ -42,12 +42,13 @@ class SoundcloudcomFactory extends BaseFactory
42 42
     {
43 43
       // l'url est valide pour l'api javascript que l'on utilise
44 44
       
45
+      $id = md5($url);
45 46
       $height = $this->container->getParameter('soundcloud_player_height');
46 47
       $embed = 
47
-        '<object height="'.$height.'" width="100%" id="embed_'.$this->element->getId().'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
48
-          <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$embed_url.'&amp;enable_api=true&amp;object_id=embed_'.$this->element->getId().'"></param>
48
+        '<object height="'.$height.'" width="100%" id="embed_'.$id.'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
49
+          <param name="movie" value="http://player.soundcloud.com/player.swf?url='.$embed_url.'&amp;enable_api=true&amp;object_id=embed_'.$id.'"></param>
49 50
           <param name="allowscriptaccess" value="always"></param>
50
-          <embed allowscriptaccess="always" height="'.$height.'" src="http://player.soundcloud.com/player.swf?url='.$embed_url.'&amp;enable_api=true&amp;object_id=embed_'.$this->element->getId().'" type="application/x-shockwave-flash" width="100%" name="embed_'.$this->element->getId().'"></embed>
51
+          <embed allowscriptaccess="always" height="'.$height.'" src="http://player.soundcloud.com/player.swf?url='.$embed_url.'&amp;enable_api=true&amp;object_id=embed_'.$id.'" type="application/x-shockwave-flash" width="100%" name="embed_'.$id.'"></embed>
51 52
         </object>
52 53
         ';
53 54
       

+ 229 - 7
src/Muzich/CoreBundle/Tests/ElementFactory/ElementFactoryTest.php View File

@@ -12,6 +12,8 @@ class ElementFactoryTest extends UnitTest
12 12
   
13 13
   /**
14 14
    * Test du fonctionnement du l'usine
15
+   * C'est plus un test fusible car il ne test que la méthode proceedFill.
16
+   * 
15 17
    */
16 18
   public function testEngine()
17 19
   {
@@ -24,8 +26,8 @@ class ElementFactoryTest extends UnitTest
24 26
     $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
25 27
     $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
26 28
     
27
-    $youtube_width = '425';
28
-    $youtube_height = '350';
29
+    $youtube_width = '590';
30
+    $youtube_height = '300';
29 31
         
30 32
     $element = new Element();
31 33
     $element->setName('Mon bel element');
@@ -35,19 +37,239 @@ class ElementFactoryTest extends UnitTest
35 37
     $factory = new ElementManager($element, $r->getEntityManager(), $this->_container);
36 38
     $factory->proceedFill($bux);
37 39
     
38
-    $url = 'http://www.youtube.com/v/WC8qb_of04E&rel=1';
40
+    $url = 'http://www.youtube.com/embed/WC8qb_of04E';
39 41
     
40 42
     $this->assertEquals($element->getName(), 'Mon bel element');
41 43
     $this->assertEquals($element->getUrl(), 'http://www.youtube.com/watch?v=WC8qb_of04E');
42 44
     $this->assertEquals($element->getTags(), array($hardtek, $tribe));
43 45
     $this->assertEquals($element->getEmbed(), 
44
-      '<object width="'.$youtube_width.'" height="'.$youtube_height.'" >'
45
-     .'<param name="movie" value="'.$url.'"></param><param name="wmode" value="transparent">'
46
-     .'</param><embed src="'.$url.'" type="application/x-shockwave-flash" '
47
-     .'wmode="transparent" width="'.$youtube_width.'" height="'.$youtube_height.'"></embed></object>'
46
+      '<iframe width="'.$youtube_width.'" height="'.$youtube_height.'" src="'.$url.'" '
47
+        .'frameborder="0" allowfullscreen></iframe>'
48 48
     );
49 49
     
50 50
     
51 51
   }
52 52
   
53
+  /**
54
+   * Test des création de code embed
55
+   */
56
+  public function testEmbedsEngine()
57
+  {
58
+    $r = $this->getDoctrine();
59
+    $bux = $r->getRepository('MuzichCoreBundle:User')
60
+      ->findOneByUsername('bux')
61
+    ;
62
+    $hardtek = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek');
63
+    $tribe = $r->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe');
64
+    
65
+    /*
66
+     *   - youtube.com && youtu.be
67
+     */
68
+    $this->proceed_elementAndFill(
69
+      $bux, 
70
+      'dfd4z5d3s45sgf45645', 
71
+      'http://www.youtube.com/watch?v=Itfg7UpkcSs&feature=g-vrec&context=G2e61726RVAAAAAAAAAg', 
72
+      array($hardtek->getId(), $tribe->getId()), 
73
+      '<iframe width="'.$this->getParam('youtube_player_width').'" '
74
+        .'height="'.$this->getParam('youtube_player_height').'" '
75
+        .'src="http://www.youtube.com/embed/Itfg7UpkcSs" '
76
+        .'frameborder="0" allowfullscreen></iframe>'
77
+    );
78
+    $this->proceed_elementAndFill(
79
+      $bux, 
80
+      'dfd4z5d3s45sgf45645', 
81
+      'http://www.youtube.com/watch?feature=player_detailpage&v=Itfg7UpkcSs#t=3s', 
82
+      array($hardtek->getId(), $tribe->getId()), 
83
+      '<iframe width="'.$this->getParam('youtube_player_width').'" '
84
+        .'height="'.$this->getParam('youtube_player_height').'" '
85
+        .'src="http://www.youtube.com/embed/Itfg7UpkcSs" '
86
+        .'frameborder="0" allowfullscreen></iframe>'
87
+    );
88
+    $this->proceed_elementAndFill(
89
+      $bux, 
90
+      'dfd4z5d3s45sgf45645', 
91
+      'http://youtu.be/Itfg7UpkcSs', 
92
+      array($hardtek->getId(), $tribe->getId()), 
93
+      '<iframe width="'.$this->getParam('youtube_player_width').'" '
94
+        .'height="'.$this->getParam('youtube_player_height').'" '
95
+        .'src="http://www.youtube.com/embed/Itfg7UpkcSs" '
96
+        .'frameborder="0" allowfullscreen></iframe>'
97
+    );
98
+    $this->proceed_elementAndFill(
99
+      $bux, 
100
+      'dfd4z5d3s45sgf45645', 
101
+      'http://www.youtube.com/watch?v=Itfg7UpkcSs', 
102
+      array($hardtek->getId(), $tribe->getId()), 
103
+      '<iframe width="'.$this->getParam('youtube_player_width').'" '
104
+        .'height="'.$this->getParam('youtube_player_height').'" '
105
+        .'src="http://www.youtube.com/embed/Itfg7UpkcSs" '
106
+        .'frameborder="0" allowfullscreen></iframe>'
107
+    );
108
+    
109
+    /*
110
+     *   - dailymotion.com
111
+     */
112
+    $this->proceed_elementAndFill(
113
+      $bux, 
114
+      'fzgrj79ukl46ye4rgz6a', 
115
+      'http://www.dailymotion.com/video/xafj1q_black-bomb-a-tales-from-the-old-sch_music', 
116
+      array($hardtek->getId(), $tribe->getId()), 
117
+      '<iframe frameborder="0" width="'.$this->getParam('dailymotion_player_width').'" '
118
+        .'height="'.$this->getParam('dailymotion_player_height').'" '
119
+        .'src="http://www.dailymotion.com/embed/video/xafj1q"></iframe>'
120
+    );
121
+    
122
+    /*
123
+     * - soundcloud.com
124
+     */
125
+    $id = md5('http://soundcloud.com/matas/sets/library-project');
126
+    $this->proceed_elementAndFill(
127
+      $bux, 
128
+      'faez7tf8re9h4gf5j64dssz', 
129
+      'http://soundcloud.com/matas/sets/library-project', 
130
+      array($hardtek->getId(), $tribe->getId()), 
131
+      '<object height="'.$this->getParam('soundcloud_player_height').'" width="100%" id="embed_'.$id.'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
132
+          <param name="movie" value="http://player.soundcloud.com/player.swf?url=http://soundcloud.com/matas/sets/library-project&amp;enable_api=true&amp;object_id=embed_'.$id.'"></param>
133
+          <param name="allowscriptaccess" value="always"></param>
134
+          <embed allowscriptaccess="always" height="'.$this->getParam('soundcloud_player_height').'" src="http://player.soundcloud.com/player.swf?url=http://soundcloud.com/matas/sets/library-project&amp;enable_api=true&amp;object_id=embed_'.$id.'" type="application/x-shockwave-flash" width="100%" name="embed_'.$id.'"></embed>
135
+        </object>
136
+        '
137
+    );
138
+    
139
+    $id = md5('http://soundcloud.com/matas/above-hyperion-redux');
140
+    $this->proceed_elementAndFill(
141
+      $bux, 
142
+      'faez7tf8re9h4gf5j64dssz', 
143
+      'http://soundcloud.com/matas/above-hyperion-redux', 
144
+      array($hardtek->getId(), $tribe->getId()), 
145
+      '<object height="'.$this->getParam('soundcloud_player_height').'" width="100%" id="embed_'.$id.'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">
146
+          <param name="movie" value="http://player.soundcloud.com/player.swf?url=http://soundcloud.com/matas/above-hyperion-redux&amp;enable_api=true&amp;object_id=embed_'.$id.'"></param>
147
+          <param name="allowscriptaccess" value="always"></param>
148
+          <embed allowscriptaccess="always" height="'.$this->getParam('soundcloud_player_height').'" src="http://player.soundcloud.com/player.swf?url=http://soundcloud.com/matas/above-hyperion-redux&amp;enable_api=true&amp;object_id=embed_'.$id.'" type="application/x-shockwave-flash" width="100%" name="embed_'.$id.'"></embed>
149
+        </object>
150
+        '
151
+    );
152
+    
153
+    $this->proceed_elementAndFill(
154
+      $bux, 
155
+      'faez7tf8re9h4gf5j64dssz', 
156
+      'http://soundcloud.com/tracks/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D=', 
157
+      array($hardtek->getId(), $tribe->getId()), 
158
+      null
159
+    );
160
+    
161
+    $this->proceed_elementAndFill(
162
+      $bux, 
163
+      'faez7tf8re9h4gf5j64dssz', 
164
+      'http://soundcloud.com/people/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D=', 
165
+      array($hardtek->getId(), $tribe->getId()), 
166
+      null
167
+    );
168
+    
169
+    $this->proceed_elementAndFill(
170
+      $bux, 
171
+      'faez7tf8re9h4gf5j64dssz', 
172
+      'http://soundcloud.com/groups/search?q%5Bfulltext%5D=EEK+A+MOUSSE&q%5Btype%5D=&q%5Bduration%5D=', 
173
+      array($hardtek->getId(), $tribe->getId()), 
174
+      null
175
+    );
176
+     
177
+    /*
178
+     *   - jamendo.com
179
+     */
180
+    
181
+    $this->proceed_elementAndFill(
182
+      $bux, 
183
+      'gthyk456+liszz', 
184
+      'http://www.jamendo.com/fr/album/30661', 
185
+      array($hardtek->getId(), $tribe->getId()), 
186
+      '
187
+          <object width="'.$this->getParam('jamendo_player_width').'" height="'.$this->getParam('jamendo_player_height').'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" align="middle">
188
+            <param name="allowScriptAccess" value="always" />
189
+            <param name="wmode" value="transparent" />
190
+            <param name="movie" value="http://widgets.jamendo.com/fr/album/?album_id=30661&playertype=2008" />
191
+            <param name="quality" value="high" />
192
+            <param name="bgcolor" value="#FFFFFF" />
193
+            <embed src="http://widgets.jamendo.com/fr/album/?album_id=30661&playertype=2008" quality="high" wmode="transparent" bgcolor="#FFFFFF" width="'.$this->getParam('jamendo_player_width').'" height="'.$this->getParam('jamendo_player_height').'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
194
+              &nbsp;
195
+            </embed>
196
+            &nbsp;
197
+          </object>
198
+          <a href="http://pro.jamendo.com/" style="display:block;font-size:8px !important;">Catalogue professionnel de musique libre</a>
199
+        '
200
+    );
201
+    
202
+    $this->proceed_elementAndFill(
203
+      $bux, 
204
+      'gthyk456+liszz', 
205
+      'http://www.jamendo.com/fr/track/207079', 
206
+      array($hardtek->getId(), $tribe->getId()), 
207
+      '
208
+          <object width="'.$this->getParam('jamendo_player_width').'" height="'.$this->getParam('jamendo_player_height').'" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" align="middle">
209
+            <param name="allowScriptAccess" value="always" />
210
+            <param name="wmode" value="transparent" />
211
+            <param name="movie" value="http://widgets.jamendo.com/fr/track/?playertype=2008&track_id=207079" />
212
+            <param name="quality" value="high" />
213
+            <param name="bgcolor" value="#FFFFFF" />
214
+            <embed src="http://widgets.jamendo.com/fr/track/?playertype=2008&track_id=207079" quality="high" wmode="transparent" bgcolor="#FFFFFF" width="'.$this->getParam('jamendo_player_width').'" height="'.$this->getParam('jamendo_player_height').'" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
215
+              &nbsp;
216
+            </embed>
217
+            &nbsp;
218
+          </object>
219
+          <a href="http://pro.jamendo.com/" style="display:block;font-size:8px !important;">Catalogue professionnel de musique libre</a>
220
+        '
221
+    );
222
+    
223
+    $this->proceed_elementAndFill(
224
+      $bux, 
225
+      'gthyk456+liszz', 
226
+      'http://www.jamendo.com/fr/search/all/psytrance', 
227
+      array($hardtek->getId(), $tribe->getId()), 
228
+      null
229
+    );
230
+    
231
+    $this->proceed_elementAndFill(
232
+      $bux, 
233
+      'gthyk456+liszz', 
234
+      'http://www.jamendo.com/fr/artist/DJ_BETO', 
235
+      array($hardtek->getId(), $tribe->getId()), 
236
+      null
237
+    );
238
+    
239
+    /*/*
240
+     *   - deezer.com
241
+     */
242
+    
243
+    $this->proceed_elementAndFill(
244
+      $bux, 
245
+      'a9j4l56dsu8ra5gf647je', 
246
+      'http://www.deezer.com/fr/music/pantera/far-beyond-driven-80398', 
247
+      array($hardtek->getId(), $tribe->getId()), 
248
+      '<iframe scrolling="no" frameborder="0" allowTransparency="true" '
249
+        .'src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true'
250
+        .'&width='.$this->getParam('deezer_player_width').'&height='
251
+        .$this->getParam('deezer_player_height')
252
+        .'&cover=true&btn_popup=true&type=album&id=80398&title=" '
253
+        .'width="'.$this->getParam('deezer_player_width').'" height="'
254
+        .$this->getParam('deezer_player_height')
255
+        .'"></iframe>'
256
+    );
257
+    
258
+    $this->proceed_elementAndFill(
259
+      $bux, 
260
+      'g4th4545ku6kti456e456z', 
261
+      'http://www.deezer.com/fr/music/playlist/18701350', 
262
+      array($hardtek->getId(), $tribe->getId()), 
263
+      '<iframe scrolling="no" frameborder="0" allowTransparency="true" '
264
+        .'src="http://www.deezer.com/fr/plugins/player?autoplay=false&playlist=true'
265
+        .'&width='.$this->getParam('deezer_player_width').'&height='
266
+        .$this->getParam('deezer_player_height')
267
+        .'&cover=true&btn_popup=true&type=playlist&id=18701350&title=" '
268
+        .'width="'.$this->getParam('deezer_player_width').'" height="'
269
+        .$this->getParam('deezer_player_height')
270
+        .'"></iframe>'
271
+    );
272
+    
273
+  }
274
+  
53 275
 }

+ 39 - 0
src/Muzich/CoreBundle/lib/UnitTest.php View File

@@ -3,6 +3,8 @@
3 3
 namespace Muzich\CoreBundle\lib;
4 4
 
5 5
 require_once(__DIR__ . "/../../../../app/AppKernel.php");
6
+use Muzich\CoreBundle\Entity\Element;
7
+use Muzich\CoreBundle\ElementFactory\ElementManager;
6 8
 
7 9
 class UnitTest extends \PHPUnit_Framework_TestCase
8 10
 {
@@ -29,4 +31,41 @@ class UnitTest extends \PHPUnit_Framework_TestCase
29 31
   {
30 32
     return $this->get('doctrine');
31 33
   }
34
+  
35
+  protected function getParam($param)
36
+  {
37
+    return $this->_container->getParameter($param);
38
+  }
39
+  
40
+  protected function proceed_elementAndFill($user, $name, $url, $tag_ids, $final_embed)
41
+  {
42
+    $youtube_width = '590';
43
+    $youtube_height = '300';
44
+        
45
+    $element = new Element();
46
+    $element->setName($name);
47
+    $element->setTags(json_encode($tag_ids));
48
+    $element->setUrl($url);
49
+    
50
+    $factory = new ElementManager(
51
+      $element, 
52
+      $this->getDoctrine()->getEntityManager(), 
53
+      $this->_container
54
+    );
55
+    $factory->proceedFill($user);
56
+        
57
+    $this->assertEquals($element->getName(), $name);
58
+    $this->assertEquals($element->getUrl(), $url);
59
+    
60
+    // check tags
61
+    $element_tag_ids = array();
62
+    foreach ($element->getTags() as $tag)
63
+    {
64
+      $element_tag_ids[] = $tag->getId();
65
+    }
66
+    
67
+    $this->assertEquals($element_tag_ids, $tag_ids);
68
+    $this->assertEquals($element->getEmbed(), $final_embed);
69
+  }
70
+  
32 71
 }