public function __construct($url, $requestID = null) { RequestError::checkCURL(); self::_checkDefaultDwnDir(); $this->_dwnFolder = static::DOWNLOAD_FOLDER; $this->_dwnDir = OBX_DOC_ROOT . $this->_dwnFolder; $this->_url = $url; $this->_bEncapsulatedID = false; if (null !== $requestID) { $requestID = trim($requestID); if (empty($requestID)) { $this->_bEncapsulatedID = true; } static::fixFileName($requestID); $this->_ID = $requestID; } else { $this->_bEncapsulatedID = true; } if ($this->_bEncapsulatedID === true) { $this->_ID = static::generateID(); } $this->_initCURL(); $this->setTimeout(static::DEFAULT_TIMEOUT); $this->setWaiting(static::DEFAULT_WAITING); }
public function testDownload404() { try { $Request = new Request(static::$_url404); $Request->downloadToFile('/upload/obx.core/test/Request/404/404.json'); } catch (RequestError $e) { $this->assertEquals(RequestError::E_FILE_SAVE_NO_RESPONSE, $e->getCode()); $this->assertEquals(RequestError::getLangMessage(RequestError::E_FILE_SAVE_NO_RESPONSE), $e->getMessage()); } $this->assertEquals('404', $Request->getStatus()); $this->assertFileNotExists(self::$_docRoot . '/upload/obx.core/test/Request/404/404.json'); $RequestAllowSave404 = new Request(static::$_url404); $RequestAllowSave404->setAllowSave404ToFile(); $RequestAllowSave404->downloadToDir('/upload/obx.core/test/Request/404/', Request::SAVE_TO_DIR_COUNT); $this->assertEquals('404', $RequestAllowSave404->getStatus()); $this->assertFileExists(self::$_docRoot . '/upload/obx.core/test/Request/404/test.response.json'); }