|
@@ -4,6 +4,7 @@ namespace Muzich\CoreBundle\Tests\Controller;
|
4
|
4
|
|
5
|
5
|
use Muzich\CoreBundle\lib\FunctionalTest;
|
6
|
6
|
use Muzich\CoreBundle\Searcher\ElementSearcher;
|
|
7
|
+use Muzich\CoreBundle\Entity\Element;
|
7
|
8
|
|
8
|
9
|
class HomeControllerTest extends FunctionalTest
|
9
|
10
|
{
|
|
@@ -537,4 +538,201 @@ class HomeControllerTest extends FunctionalTest
|
537
|
538
|
|
538
|
539
|
}
|
539
|
540
|
|
|
541
|
+ /**
|
|
542
|
+ * Test de la récupération de nouveaux éléments
|
|
543
|
+ *
|
|
544
|
+ */
|
|
545
|
+ public function testSeeNew()
|
|
546
|
+ {
|
|
547
|
+ $this->client = self::createClient();
|
|
548
|
+ $this->connectUser('bux', 'toor');
|
|
549
|
+
|
|
550
|
+ $bux = $this->getUser();
|
|
551
|
+ $bob = $this->getDoctrine()->getRepository('MuzichCoreBundle:User')
|
|
552
|
+ ->findOneByUsername('bob')
|
|
553
|
+ ;
|
|
554
|
+ $hardtek_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Hardtek')->getId();
|
|
555
|
+ $tribe_id = $this->getDoctrine()->getRepository('MuzichCoreBundle:Tag')->findOneByName('Tribe')->getId();
|
|
556
|
+
|
|
557
|
+ // On récupère l'id du dernier element affiché
|
|
558
|
+ $extract = $this->crawler->filter('ul.elements li.element')
|
|
559
|
+ ->extract(array('id'));
|
|
560
|
+
|
|
561
|
+ $first_id = (int)str_replace('element_', '', $extract[0]);
|
|
562
|
+
|
|
563
|
+ $url = $this->generateUrl('element_new_count', array('refid' => $first_id));
|
|
564
|
+ // On effectue la kekete ajax
|
|
565
|
+ $crawler = $this->client->request(
|
|
566
|
+ 'GET',
|
|
567
|
+ $url,
|
|
568
|
+ array(),
|
|
569
|
+ array(),
|
|
570
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
571
|
+ );
|
|
572
|
+
|
|
573
|
+ $this->isResponseSuccess();
|
|
574
|
+
|
|
575
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
576
|
+ $this->assertEquals($response['status'], 'success');
|
|
577
|
+ $this->assertEquals($response['count'], '0');
|
|
578
|
+ $this->assertEquals($response['message'], '');
|
|
579
|
+
|
|
580
|
+ $this->addElementAjax('NewElement One', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
581
|
+ $this->addElementAjax('NewElement Two', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
582
|
+
|
|
583
|
+ // On refait la même demande, deux éléments sont nouveaux
|
|
584
|
+ $url = $this->generateUrl('element_new_count', array('refid' => $first_id));
|
|
585
|
+ // On effectue la kekete ajax
|
|
586
|
+ $crawler = $this->client->request(
|
|
587
|
+ 'GET',
|
|
588
|
+ $url,
|
|
589
|
+ array(),
|
|
590
|
+ array(),
|
|
591
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
592
|
+ );
|
|
593
|
+
|
|
594
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
595
|
+ $this->assertEquals($response['status'], 'success');
|
|
596
|
+ $this->assertEquals($response['count'], '2');
|
|
597
|
+
|
|
598
|
+ // Si on demande la récupération des nouveaux éléments on doit les obtenirs
|
|
599
|
+ $url = $this->generateUrl('element_new_get', array('refid' => $first_id));
|
|
600
|
+ // On effectue la kekete ajax
|
|
601
|
+ $crawler = $this->client->request(
|
|
602
|
+ 'GET',
|
|
603
|
+ $url,
|
|
604
|
+ array(),
|
|
605
|
+ array(),
|
|
606
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
607
|
+ );
|
|
608
|
+
|
|
609
|
+ $this->isResponseSuccess();
|
|
610
|
+
|
|
611
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
612
|
+ $this->assertEquals($response['status'], 'success');
|
|
613
|
+ $this->assertEquals($response['count'], '0');
|
|
614
|
+ $this->assertTrue(!is_null($response['html']));
|
|
615
|
+ $this->assertTrue(strpos($response['html'], 'NewElement One') !== false);
|
|
616
|
+ $this->assertTrue(strpos($response['html'], 'NewElement Two') !== false);
|
|
617
|
+
|
|
618
|
+ // On ajoute 10 autres éléments (NOTE: le 10 est hardcodé dans ce test
|
|
619
|
+ // , c'est la limite d'affichage d'éléments)
|
|
620
|
+ $this->addElementAjax('NewElement 3', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
621
|
+ $this->addElementAjax('NewElement 4', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
622
|
+ $this->addElementAjax('NewElement 5', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
623
|
+ $this->addElementAjax('NewElement 6', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
624
|
+ $this->addElementAjax('NewElement 7', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
625
|
+ $this->addElementAjax('NewElement 8', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
626
|
+ $this->addElementAjax('NewElement 9', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
627
|
+ $this->addElementAjax('NewElement 10', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
628
|
+ $this->addElementAjax('NewElement 11', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
629
|
+ $this->addElementAjax('NewElement 12', 'http://labas.com', json_encode(array($hardtek_id, $tribe_id)));
|
|
630
|
+
|
|
631
|
+ // On va refaire un count des nouveaux éléments
|
|
632
|
+ // Ca devrat nous répondree 12 puisque on utilise l'id de référence du début
|
|
633
|
+
|
|
634
|
+ // On refait la même demande, deux éléments sont nouveaux
|
|
635
|
+ $url = $this->generateUrl('element_new_count', array('refid' => $first_id));
|
|
636
|
+ // On effectue la kekete ajax
|
|
637
|
+ $crawler = $this->client->request(
|
|
638
|
+ 'GET',
|
|
639
|
+ $url,
|
|
640
|
+ array(),
|
|
641
|
+ array(),
|
|
642
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
643
|
+ );
|
|
644
|
+
|
|
645
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
646
|
+ $this->assertEquals($response['status'], 'success');
|
|
647
|
+ $this->assertEquals($response['count'], '12');
|
|
648
|
+
|
|
649
|
+ // Si on demande la récupération des nouveaux éléments on doit en obtenir 10
|
|
650
|
+ // et en rester 2
|
|
651
|
+ $url = $this->generateUrl('element_new_get', array('refid' => $first_id));
|
|
652
|
+ // On effectue la kekete ajax
|
|
653
|
+ $crawler = $this->client->request(
|
|
654
|
+ 'GET',
|
|
655
|
+ $url,
|
|
656
|
+ array(),
|
|
657
|
+ array(),
|
|
658
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
659
|
+ );
|
|
660
|
+
|
|
661
|
+ $this->isResponseSuccess();
|
|
662
|
+
|
|
663
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
664
|
+ $this->assertEquals($response['status'], 'success');
|
|
665
|
+ $this->assertEquals($response['count'], '2');
|
|
666
|
+ $this->assertTrue(!is_null($response['html']));
|
|
667
|
+ $this->assertTrue(strpos($response['html'], 'NewElement One') !== false);
|
|
668
|
+ $this->assertTrue(strpos($response['html'], 'NewElement Two') !== false);
|
|
669
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 3') !== false);
|
|
670
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 4') !== false);
|
|
671
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 5') !== false);
|
|
672
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 6') !== false);
|
|
673
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 7') !== false);
|
|
674
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 8') !== false);
|
|
675
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 9') !== false);
|
|
676
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 10') !== false);
|
|
677
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 11') === false);
|
|
678
|
+ $this->assertTrue(strpos($response['html'], 'NewElement 12') === false);
|
|
679
|
+
|
|
680
|
+ $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
|
|
681
|
+ ->findOneByName('NewElement 10')
|
|
682
|
+ ;
|
|
683
|
+ // notre nouvel id référent en celui de NewElement 10
|
|
684
|
+ // On renouvelle la demande, il ne doit y avoir que 2 élément nouveau a afficher
|
|
685
|
+ $url = $this->generateUrl('element_new_count', array('refid' => $element->getId()));
|
|
686
|
+ // On effectue la kekete ajax
|
|
687
|
+ $crawler = $this->client->request(
|
|
688
|
+ 'GET',
|
|
689
|
+ $url,
|
|
690
|
+ array(),
|
|
691
|
+ array(),
|
|
692
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
693
|
+ );
|
|
694
|
+
|
|
695
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
696
|
+ $this->assertEquals($response['status'], 'success');
|
|
697
|
+ $this->assertEquals($response['count'], '2');
|
|
698
|
+
|
|
699
|
+ }
|
|
700
|
+
|
|
701
|
+ public function testMoreElements()
|
|
702
|
+ {
|
|
703
|
+ $this->client = self::createClient();
|
|
704
|
+ $this->connectUser('bux', 'toor');
|
|
705
|
+
|
|
706
|
+ $bux = $this->getUser();
|
|
707
|
+
|
|
708
|
+ // On récupère l'id du dernier element affiché
|
|
709
|
+ $extract = $this->crawler->filter('ul.elements li.element')
|
|
710
|
+ ->extract(array('id'));
|
|
711
|
+
|
|
712
|
+ // !!!!!! NOTE !!!!! : 9 est hardcodé ici: la config est de 10 éléments en affichage
|
|
713
|
+ $id_limit = (int)str_replace('element_', '', $extract[9]);
|
|
714
|
+
|
|
715
|
+ $url = $this->generateUrl('search_elements_more', array(
|
|
716
|
+ 'id_limit' => $id_limit,
|
|
717
|
+ 'invertcolors' => 0
|
|
718
|
+ ));
|
|
719
|
+
|
|
720
|
+ // We want mooooore
|
|
721
|
+ // On effectue la kekete ajax
|
|
722
|
+ $crawler = $this->client->request(
|
|
723
|
+ 'GET',
|
|
724
|
+ $url,
|
|
725
|
+ array(),
|
|
726
|
+ array(),
|
|
727
|
+ array('HTTP_X-Requested-With' => 'XMLHttpRequest')
|
|
728
|
+ );
|
|
729
|
+
|
|
730
|
+ $response = json_decode($this->client->getResponse()->getContent(), true);
|
|
731
|
+ $this->assertEquals($response['status'], 'success');
|
|
732
|
+ $this->assertEquals($response['count'], '4'); // HARDCODE fixtures
|
|
733
|
+ $this->assertEquals($response['end'], true); // HARDCODE fixtures
|
|
734
|
+
|
|
735
|
+ }
|
|
736
|
+
|
|
737
|
+
|
540
|
738
|
}
|