public function testPhoto() { $dir = __DIR__; chdir($dir); $imageFile = 'validImage.jpg'; $path = 'data' . DS . $imageFile; $image = file_get_contents($path); $imageData = base64_encode($image); chdir(Mage::getBaseDir()); $endpoint = 'api/rest/customconfigurable/photo'; $url = $this->_callbackUrl . $endpoint; $params = array('filename' => $imageFile, 'code' => $this->_photoCode, 'data' => $imageData); $data = json_encode($params); $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data))); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $headerStr = substr($response, 0, $headerSize); $headersAr = Mage::helper('aydus_customconfigurable')->getHeadersArray($headerStr); curl_close($ch); $gotLocation = false; if (is_array($headersAr) && count($headersAr) > 0) { $location = ''; foreach ($headersAr as $headerAr) { foreach ($headerAr as $headerKey => $headerValue) { if ($headerKey == 'Location') { $location = $headerValue; $parsedUrlAr = parse_url($location); if (is_array($parsedUrlAr) && count($parsedUrlAr) > 0) { //location looks like http://www.example.com/media/aydus/customconfigurable/v/a/1422388585-validImage.jpg if (is_numeric(strpos($location, $imageFile))) { $gotLocation = true; self::$_photoUrl = $location; } } } } } } $this->assertTrue($gotLocation); }