Elgg\UploadServiceTest::testCanAcceptUploadedFile PHP Method

testCanAcceptUploadedFile() public method

    public function testCanAcceptUploadedFile()
    {
        $tmp = new ElggFile();
        $tmp->owner_guid = $this->owner_guid;
        $tmp->setFilename('tmp.gif');
        $tmp->open('write');
        $tmp->write(file_get_contents(elgg_get_config('dataroot') . '1/1/400x300.gif'));
        $tmp->close();
        $tmp_file = $tmp->getFilenameOnFilestore();
        $filesize = $tmp->getSize();
        $upload = ['gif' => new UploadedFile($tmp_file, 'tmp.gif', 'image/gif', filesize($tmp_file), UPLOAD_ERR_OK, true)];
        _elgg_services()->request->files->set('upload', $upload);
        $file = new ElggFile();
        $file->owner_guid = $this->owner_guid;
        $uploaded_files = _elgg_services()->uploads->getUploadedFiles('upload');
        $uploaded_file = array_shift($uploaded_files);
        $this->assertTrue($file->acceptUploadedFile($uploaded_file));
        $this->assertTrue($file->exists());
        $this->assertNotEmpty($file->title);
        $this->assertEquals('image/gif', $file->getMimeType());
        $this->assertEquals('image', $file->getSimpleType());
        $this->assertEquals($filesize, $file->getSize());
        $this->assertEquals('tmp.gif', $file->originalfilename);
    }