public function testCanOverrideContainerPermissionsWithAHook()
{
$owner = $this->mocks()->getUser();
$entity = $this->mocks()->getObject(['owner_guid' => $owner->guid, 'subtype' => 'bar']);
$this->assertTrue($entity->canWriteToContainer($owner->guid, 'object', 'bar'));
$this->hooks->registerHandler('container_permissions_check', 'object', function ($hook, $type, $return, $params) use($entity, $owner) {
$this->assertInstanceOf(ElggEntity::class, $params['container']);
$this->assertInstanceOf(ElggUser::class, $params['user']);
$this->assertEquals($entity, $params['container']);
$this->assertEquals($owner, $params['user']);
$this->assertEquals('bar', $params['subtype']);
$this->assertTrue($return);
return false;
});
$this->assertFalse($entity->canWriteToContainer($owner->guid, 'object', 'bar'));
// Should still be able to write to container without particular entity type specified
$this->assertTrue($entity->canWriteToContainer($owner->guid));
}