ReputationTest.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace Muzich\CoreBundle\Tests\Controller;
  3. use Muzich\CoreBundle\lib\FunctionalTest;
  4. //use Symfony\Bundle\FrameworkBundle\Console\Application;
  5. //use Muzich\CoreBundle\Command\RecalculateReputationCommand;
  6. //use Symfony\Component\Console\Tester\CommandTester;
  7. ////use \AppKernel;
  8. //use Symfony\Component\HttpFoundation\Request;
  9. class ReputationTest extends FunctionalTest
  10. {
  11. // public function testCommandLineCalculateReputation()
  12. // {
  13. // require_once __DIR__.'/../../../../../app/bootstrap.php.cache';
  14. // require_once __DIR__.'/../../../../../app/AppKernel.php';
  15. //
  16. // $kernel = new \AppKernel('test', true);
  17. // $kernel->loadClassCache();
  18. // $kernel->handle(Request::createFromGlobals())->send();
  19. //
  20. // $application = new Application($kernel);
  21. // $application->add(new RecalculateReputationCommand());
  22. //
  23. // $command = $application->find('users:reputation:recalculate');
  24. // $commandTester = new CommandTester($command);
  25. //
  26. // $bux = $this->getUser('bux');
  27. // $bux->setReputation(0);
  28. // $this->getDoctrine()->getEntityManager()->persist($bux);
  29. // $this->getDoctrine()->getEntityManager()->flush();
  30. //
  31. // $bux = $this->getUser('bux');
  32. // $this->assertEquals($bux->getReputation(), 0);
  33. //
  34. // //$commandTester->execute(array('command' => $command->getName()));
  35. // }
  36. /**
  37. * Test de l'impact sur la reputation lorsque il y a vote sur element
  38. */
  39. public function testElementDelete()
  40. {
  41. $this->client = self::createClient();
  42. $this->connectUser('paul', 'toor');
  43. $paul = $this->getUser();
  44. // paul vote sur l'élément de bux
  45. // // Comme ça on a un point de vote (fixtures = 0 points)
  46. // // et une mise ne favoris
  47. $element = $this->getDoctrine()->getRepository('MuzichCoreBundle:Element')
  48. ->findOneByName('Heretik System Popof - Resistance')
  49. ;
  50. $crawler = $this->client->request(
  51. 'GET',
  52. $this->generateUrl('ajax_element_add_vote_good', array(
  53. 'element_id' => $element->getId(),
  54. 'token' => $paul->getPersonalHash()
  55. )),
  56. array(),
  57. array(),
  58. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  59. );
  60. $this->isResponseSuccess();
  61. $response = json_decode($this->client->getResponse()->getContent(), true);
  62. $this->assertEquals($response['status'], 'success');
  63. // bux va supprimer un de ses éléments
  64. $this->disconnectUser();
  65. $this->connectUser('bux', 'toor');
  66. $bux = $this->getUser();
  67. // D'aprés les fixtures plus le vote de paul: 23
  68. $this->assertEquals(23, $bux->getReputation());
  69. // On effectue la demande ajax d'edition
  70. $crawler = $this->client->request(
  71. 'GET',
  72. $this->generateUrl('element_remove', array(
  73. 'element_id' => $element->getId()
  74. )),
  75. array(),
  76. array(),
  77. array('HTTP_X-Requested-With' => 'XMLHttpRequest')
  78. );
  79. $this->isResponseSuccess();
  80. $response = json_decode($this->client->getResponse()->getContent(), true);
  81. $this->assertEquals($response['status'], 'success');
  82. $coef_element_fav = $this->getContainer()->getParameter('reputation_element_favorite_value');
  83. $coef_element_point = $this->getContainer()->getParameter('reputation_element_point_value');
  84. $bux = $this->getUser('bux');
  85. $this->assertEquals(23 - ($coef_element_fav * 1) - ($coef_element_point * 1), $bux->getReputation());
  86. }
  87. }