public function testCanSaveIconsWithAHookHandler()
{
$file = new \ElggFile();
$file->owner_guid = 1;
$file->setFilename('600x300.jpg');
$this->hooks->registerHandler('entity:icon:save', 'object', function ($hook, $type, $return, $params) {
if ($return) {
return;
}
// make sure we passed in documented params
if (!$params['entity'] instanceof \ElggEntity || !$params['file'] instanceof \ElggFile) {
return;
}
if (!isset($params['x1']) || !isset($params['y1']) || !isset($params['x2']) || !isset($params['y2'])) {
return;
}
return true;
});
$this->assertTrue($this->hooks->hasHandler('entity:icon:save', 'object'));
$service = $this->createService();
$service->saveIconFromElggFile($this->entity, $file);
// original file should stay where it is
$this->assertTrue($file->exists());
// hook returned true without generating icons
$this->assertFalse($service->hasIcon($this->entity, 'master'));
$this->assertFalse($service->hasIcon($this->entity, 'large'));
$this->assertFalse($service->hasIcon($this->entity, 'medium'));
$this->assertFalse($service->hasIcon($this->entity, 'small'));
$this->assertFalse($service->hasIcon($this->entity, 'tiny'));
$this->assertFalse($service->hasIcon($this->entity, 'topbar'));
}