ApiMediaFileUploadTest

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.

Defined (1)

The class is defined in the following location(s).

/lib/vendor/google/apiclient/tests/general/ApiMediaFileUploadTest.php  
  1. class ApiMediaFileUploadTest extends BaseTest 
  2. public function testMediaFile() 
  3. $client = $this->getClient(); 
  4. $request = new Google_Http_Request('http://www.example.com', 'POST'); 
  5. $media = new Google_Http_MediaFileUpload( 
  6. $client,  
  7. $request,  
  8. 'image/png',  
  9. base64_decode('data:image/png;base64, a') 
  10. ); 
  11.  
  12. $this->assertEquals(0, $media->getProgress()); 
  13. $this->assertGreaterThan(0, strlen($request->getPostBody())); 
  14.  
  15. public function testGetUploadType() 
  16. $client = $this->getClient(); 
  17. $request = new Google_Http_Request('http://www.example.com', 'POST'); 
  18.  
  19. // Test resumable upload 
  20. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true); 
  21. $params = array('mediaUpload' => array('value' => $media)); 
  22. $this->assertEquals('resumable', $media->getUploadType(null)); 
  23.  
  24. // Test data *only* uploads 
  25. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', false); 
  26. $this->assertEquals('media', $media->getUploadType(null)); 
  27.  
  28. // Test multipart uploads 
  29. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', false); 
  30. $this->assertEquals('multipart', $media->getUploadType(array('a' => 'b'))); 
  31.  
  32. public function testResultCode() 
  33. $client = $this->getClient(); 
  34. $request = new Google_Http_Request('http://www.example.com', 'POST'); 
  35.  
  36. // Test resumable upload 
  37. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', 'a', true); 
  38. $this->assertEquals(null, $media->getHttpResultCode()); 
  39.  
  40. public function testProcess() 
  41. $client = $this->getClient(); 
  42. $data = 'foo'; 
  43.  
  44. // Test data *only* uploads. 
  45. $request = new Google_Http_Request('http://www.example.com', 'POST'); 
  46. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false); 
  47. $this->assertEquals($data, $request->getPostBody()); 
  48.  
  49. // Test resumable (meta data) - we want to send the metadata, not the app data. 
  50. $request = new Google_Http_Request('http://www.example.com', 'POST'); 
  51. $reqData = json_encode("hello"); 
  52. $request->setPostBody($reqData); 
  53. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, true); 
  54. $this->assertEquals(json_decode($reqData), $request->getPostBody()); 
  55.  
  56. // Test multipart - we are sending encoded meta data and post data 
  57. $request = new Google_Http_Request('http://www.example.com', 'POST'); 
  58. $reqData = json_encode("hello"); 
  59. $request->setPostBody($reqData); 
  60. $media = new Google_Http_MediaFileUpload($client, $request, 'image/png', $data, false); 
  61. $this->assertContains($reqData, $request->getPostBody()); 
  62. $this->assertContains(base64_encode($data), $request->getPostBody());