UpdateListenerTest.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace App\Tests\Core\DB;
  19. use App\Core\DB\DB;
  20. use App\Core\DB\UpdateListener;
  21. use App\Util\GNUsocialTestCase;
  22. use DateTime;
  23. use Doctrine\ORM\EntityManagerInterface;
  24. use Doctrine\ORM\Event\PreUpdateEventArgs;
  25. class UpdateListenerTest extends GNUsocialTestCase
  26. {
  27. public function testPreUpdateExists()
  28. {
  29. static::bootKernel();
  30. $actor = DB::findOneBy('gsactor', ['nickname' => 'taken_user']);
  31. $date = new DateTime('1999-09-23');
  32. $actor->setModified($date);
  33. static::assertSame($actor->getModified(), $date);
  34. $em = static::$container->get(EntityManagerInterface::class);
  35. $change_set = [];
  36. $args = new PreUpdateEventArgs($actor, $em, $change_set);
  37. $ul = new UpdateListener();
  38. $ul->preUpdate($args);
  39. static::assertNotSame($actor->getModified(), $date);
  40. }
  41. public function testPreUpdateDoesNotExist()
  42. {
  43. static::bootKernel();
  44. $group_inbox = DB::dql('select gi from group_inbox gi join local_group lg with gi.group_id = lg.group_id where lg.nickname = :nickname', ['nickname' => 'taken_group'])[0];
  45. static::assertTrue(!method_exists($group_inbox, 'setModified'));
  46. $em = static::$container->get(EntityManagerInterface::class);
  47. $change_set = [];
  48. $args = new PreUpdateEventArgs($group_inbox, $em, $change_set);
  49. $ul = new UpdateListener();
  50. static::assertFalse($ul->preUpdate($args));
  51. }
  52. }