Elgg\EntityIconServiceTest::testCanListenToIconsSavedHook PHP Метод

testCanListenToIconsSavedHook() публичный Метод

    public function testCanListenToIconsSavedHook()
    {
        $file = new \ElggFile();
        $file->owner_guid = 1;
        $file->setFilename('600x300.jpg');
        $this->hooks->registerHandler('entity:icon:saved', 'object', function ($hook, $type, $return, $params) {
            // make sure we passed in documented params
            if (!$params['entity'] instanceof \ElggEntity) {
                return;
            }
            if (!isset($params['x1']) || !isset($params['y1']) || !isset($params['x2']) || !isset($params['y2'])) {
                return;
            }
            _elgg_services()->iconService->deleteIcon($params['entity']);
        });
        $this->assertTrue($this->hooks->hasHandler('entity:icon:saved', 'object'));
        $service = $this->createService();
        _elgg_services()->setValue('iconService', $service);
        $service->saveIconFromElggFile($this->entity, $file);
        // icons were deleted by the hook
        $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'));
    }