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

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

    public function testCanSaveIconFromUploadedFile()
    {
        // Make a copy of the file so we can move it
        $tmp = new \ElggFile();
        $tmp->owner_guid = $this->user->guid;
        $tmp->setFilename('tmp.gif');
        $tmp->open('write');
        $tmp->write(file_get_contents($this->config()->get('dataroot') . '1/1/400x300.gif'));
        $tmp->close();
        $uploaded_file = $tmp->getFilenameOnFilestore();
        $upload = new \Symfony\Component\HttpFoundation\File\UploadedFile($uploaded_file, 'tmp.gif', 'image/gif', filesize($uploaded_file), UPLOAD_ERR_OK, true);
        $this->request->files->set('icon', $upload);
        $service = $this->createService();
        $service->saveIconFromUploadedFile($this->entity, 'icon');
        $this->assertTrue($service->hasIcon($this->entity, 'master'));
        $this->assertTrue($service->hasIcon($this->entity, 'large'));
        $this->assertTrue($service->hasIcon($this->entity, 'medium'));
        $this->assertTrue($service->hasIcon($this->entity, 'small'));
        $this->assertTrue($service->hasIcon($this->entity, 'tiny'));
        $this->assertTrue($service->hasIcon($this->entity, 'topbar'));
        // make sure uploaded file is deleted
        $this->assertFalse(file_exists($upload->getPathname()));
        // make sure we removed temporary files
        $dir_items = scandir($this->entity_dir_path . 'tmp');
        $this->assertTrue(count($dir_items) <= 2);
    }