/** * @covers WindowsAzure\Common\Internal\Http\batchRequest::appendContext * @covers WindowsAzure\Common\Internal\Http\batchRequest::encode * @covers WindowsAzure\Common\Internal\Http\batchRequest::getBody * @covers WindowsAzure\Common\Internal\Http\batchRequest::__construct */ public function testAppendContext() { // Setup $batchReq = new BatchRequest(); $context = new HttpCallContext(); $body = 'test body'; $uri = 'http://www.someurl.com'; $context->setBody($body); $context->setUri($uri); // Test $batchReq->appendContext($context); $batchReq->encode(); $resultBody = $batchReq->getBody(); $resultHeader = $batchReq->getHeaders(); // Assert $this->assertContains($body, $resultBody); }
/** * Create a job. * * @param WindowsAzure\MediaServices\Models\JobTemplate $jobTemplate Job * template data * * @param array $taskTemplates Performed * tasks template array * * @return Models\JobTemplate */ public function createJobTemplate($jobTemplate, $taskTemplates) { Validate::isA($jobTemplate, 'WindowsAzure\\MediaServices\\Models\\JobTemplate', 'jobTemplate'); Validate::isArray($taskTemplates, 'taskTemplates'); $batch = new BatchRequest(); $batch->appendContext($this->_getCreateEmptyJobTemplateContext($jobTemplate)); if ($taskTemplates != null) { foreach ($taskTemplates as $taskTemplate) { $batch->appendContext($this->_getCreateTaskTemplateContext($taskTemplate)); } } $batch->encode(); $method = Resources::HTTP_POST; $headers = $batch->getHeaders(); $postParams = array(); $queryParams = array(); $path = '$batch'; $statusCode = Resources::STATUS_ACCEPTED; $body = $batch->getBody(); $response = $this->send($method, $headers, $postParams, $queryParams, $path, $statusCode, $body); $batchResponse = new BatchResponse($response->getBody(), $batch); $responses = $batchResponse->getContexts(); $jobTemplateResponse = $responses[0]; $entry = new Entry(); $entry->parseXml($jobTemplateResponse->getBody()); $properties = $this->getPropertiesFromAtomEntry($entry); return JobTemplate::createFromOptions($properties); }