public function testUpload() { $this->instance->init(); $result = $this->instance->__async_maxfilesize(); $this->assertEquals(true, in_array($result['sizeString'], array(ini_get('post_max_size'), ini_get('upload_max_filesize')))); $upload = new Upload(array(), null, $this->instance, $this->getMockBuilder('\\samsonphp\\upload\\AsyncHandler')->disableOriginalConstructor()->getMock()); $this->setHandlerParams($upload->handler); $upload->upload($filePath, $uploadName, $fileName); $this->assertTrue($upload->extension('png')); $this->assertEquals($upload->extension(), 'png'); $this->assertEquals($upload->mimeType(), 'png'); $this->assertEquals($upload->size(), 1003); $this->assertEquals($fileName, 'tests/samsonos.png'); $this->assertEquals($upload->realName(), 'tests/samsonos.png'); $this->assertNotNull($filePath); $this->assertNotNull($uploadName); $this->assertNotNull($upload->path()); $this->assertNotNull($upload->name()); $this->assertNotNull($upload->fullPath()); }
/** Upload file controller */ public function __async_upload() { /** @var \samsonphp\fs\FileService $fsModule */ $fsModule = $this->system->module('fs'); // Create object for uploading file to server $upload = new Upload(array(), $_GET['i']); // Uploading file to server; $upload->upload($file_path); // Call scale if it is loaded if (class_exists('\\samson\\scale\\ScaleController', false) && $this->isImage($fsModule->extension($file_path))) { /** @var \samson\scale\ScaleController $scale */ $scale = $this->system->module('scale'); $scale->resize($upload->fullPath(), $upload->name(), $upload->uploadDir); } // TODO: Work with upload real and URL paths $urlPath = $upload->path() . $upload->name(); /** @var \samsoncms\input\Field $field Save path to file in DB */ $this->createField(new dbQuery(), $_GET['e'], $_GET['f'], $_GET['i']); $this->field->save($urlPath); // Return upload object for further usage return array('status' => 1, 'path' => $urlPath); }