2020-10-13 23:45:48 +01:00
< ? php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
2021-04-01 23:24:39 +01:00
namespace App\Tests\Core\DB ;
2020-10-13 23:45:48 +01:00
2021-05-06 22:57:06 +01:00
use App\Core\DB\DB ;
2020-11-09 19:43:39 +00:00
use App\Core\DB\UpdateListener ;
2021-05-06 22:57:06 +01:00
use App\Util\GNUsocialTestCase ;
2020-10-13 23:45:48 +01:00
use DateTime ;
2021-05-06 22:57:06 +01:00
use Doctrine\ORM\EntityManagerInterface ;
2020-10-13 23:45:48 +01:00
use Doctrine\ORM\Event\PreUpdateEventArgs ;
2021-05-06 22:57:06 +01:00
class UpdateListenerTest extends GNUsocialTestCase
2020-10-13 23:45:48 +01:00
{
2021-05-06 22:57:06 +01:00
public function testPreUpdateExists ()
2020-10-13 23:45:48 +01:00
{
2021-03-31 10:54:50 +01:00
static :: bootKernel ();
2021-05-06 22:57:06 +01:00
$actor = DB :: findOneBy ( 'gsactor' , [ 'nickname' => 'taken_user' ]);
2021-04-10 22:57:00 +01:00
$date = new DateTime ( '1999-09-23' );
$actor -> setModified ( $date );
static :: assertSame ( $actor -> getModified (), $date );
2020-10-13 23:45:48 +01:00
2021-05-06 22:57:06 +01:00
$em = static :: $container -> get ( EntityManagerInterface :: class );
2020-10-13 23:45:48 +01:00
$change_set = [];
$args = new PreUpdateEventArgs ( $actor , $em , $change_set );
$ul = new UpdateListener ();
$ul -> preUpdate ( $args );
2021-04-10 22:57:00 +01:00
static :: assertNotSame ( $actor -> getModified (), $date );
2020-10-13 23:45:48 +01:00
}
2021-05-06 22:57:06 +01:00
public function testPreUpdateDoesNotExist ()
{
static :: bootKernel ();
$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 ];
static :: assertTrue ( ! method_exists ( $group_inbox , 'setModified' ));
$em = static :: $container -> get ( EntityManagerInterface :: class );
$change_set = [];
$args = new PreUpdateEventArgs ( $group_inbox , $em , $change_set );
$ul = new UpdateListener ();
static :: assertFalse ( $ul -> preUpdate ( $args ));
}
2020-10-13 23:45:48 +01:00
}