public function testDownloadCallback() { // Upload a file. $upload_file_path = Helper\get_png(); $upload_test = new Test(); $upload_test->server('upload_response', 'POST', array('image' => '@' . $upload_file_path)); $uploaded_file_path = $upload_test->curl->response->file_path; // Download the file. $download_callback_called = false; $multi_curl = new MultiCurl(); $multi_curl->setHeader('X-DEBUG-TEST', 'download_response'); $multi_curl->addDownload(Test::TEST_URL . '?' . http_build_query(array('file_path' => $uploaded_file_path)), function ($instance, $fh) use(&$download_callback_called) { PHPUnit_Framework_Assert::assertFalse($download_callback_called); PHPUnit_Framework_Assert::assertInstanceOf('Curl\\Curl', $instance); PHPUnit_Framework_Assert::assertTrue(is_resource($fh)); PHPUnit_Framework_Assert::assertEquals('stream', get_resource_type($fh)); PHPUnit_Framework_Assert::assertGreaterThan(0, strlen(stream_get_contents($fh))); PHPUnit_Framework_Assert::assertEquals(0, strlen(stream_get_contents($fh))); PHPUnit_Framework_Assert::assertTrue(fclose($fh)); $download_callback_called = true; }); $multi_curl->start(); $this->assertTrue($download_callback_called); // Remove server file. $this->assertEquals('true', $upload_test->server('upload_cleanup', 'POST', array('file_path' => $uploaded_file_path))); unlink($upload_file_path); $this->assertFalse(file_exists($upload_file_path)); $this->assertFalse(file_exists($uploaded_file_path)); }
public function testArrayToStringConversion() { $test = new Test(); $test->server('post', 'POST', array('foo' => 'bar', 'baz' => array())); $this->assertEquals('foo=bar&baz=', $test->curl->response); $test = new Test(); $test->server('post', 'POST', array('foo' => 'bar', 'baz' => array('qux' => array()))); $this->assertEquals('foo=bar&baz[qux]=', urldecode($test->curl->response)); $test = new Test(); $test->server('post', 'POST', array('foo' => 'bar', 'baz' => array('qux' => array(), 'wibble' => 'wobble'))); $this->assertEquals('foo=bar&baz[qux]=&baz[wibble]=wobble', urldecode($test->curl->response)); }
public function testXMLDecoder() { $data = array('key' => 'Content-Type', 'value' => 'text/xml'); $test = new Test(); $test->server('xml_with_cdata_response', 'POST', $data); $this->assertFalse(strpos($test->curl->response->saveXML(), '<![CDATA[') === false); $test = new Test(); $test->curl->setXmlDecoder(function ($response) { return simplexml_load_string($response, 'SimpleXMLElement', LIBXML_NOCDATA); }); $test->server('xml_with_cdata_response', 'POST', $data); $this->assertTrue(strpos($test->curl->response->saveXML(), '<![CDATA[') === false); }
function remove_file_from_server($uploaded_file_path) { $download_test = new Test(); // Ensure file successfully removed. assert('true' === $download_test->server('upload_cleanup', 'POST', array('file_path' => $uploaded_file_path))); assert(file_exists($uploaded_file_path) === false); }
public function testGetInfo() { $test = new Test(); $test->server('server', 'GET'); $info = $test->curl->getInfo(); $expected_keys = array('url', 'content_type', 'http_code', 'header_size', 'request_size', 'filetime', 'ssl_verify_result', 'redirect_count', 'total_time', 'namelookup_time', 'connect_time', 'pretransfer_time', 'size_upload', 'size_download', 'speed_download', 'speed_upload', 'download_content_length', 'upload_content_length', 'starttransfer_time', 'redirect_time', 'certinfo', 'primary_ip', 'primary_port', 'local_ip', 'local_port', 'redirect_url', 'request_header'); // Not all keys are included on PHP 5.3 (tested 5.3.29). if (version_compare(PHP_VERSION, '5.4.0', '<')) { foreach (array('primary_ip', 'primary_port', 'local_ip', 'local_port') as $value) { $key = array_search($value, $expected_keys); unset($expected_keys[$key]); } } // Not all keys are included on HHVM (tested 3.6.6). if (defined('HHVM_VERSION')) { foreach (array('certinfo', 'primary_ip', 'primary_port', 'local_ip', 'redirect_url') as $value) { $key = array_search($value, $expected_keys); unset($expected_keys[$key]); } } foreach ($expected_keys as $key) { $this->assertArrayHasKey($key, $info); } }