summaryrefslogtreecommitdiff
path: root/vendor/guzzle/guzzle/tests/Guzzle/Tests/Plugin/Md5/CommandContentMd5PluginTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/guzzle/guzzle/tests/Guzzle/Tests/Plugin/Md5/CommandContentMd5PluginTest.php')
-rw-r--r--vendor/guzzle/guzzle/tests/Guzzle/Tests/Plugin/Md5/CommandContentMd5PluginTest.php97
1 files changed, 97 insertions, 0 deletions
diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Plugin/Md5/CommandContentMd5PluginTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Plugin/Md5/CommandContentMd5PluginTest.php
new file mode 100644
index 0000000..4bd4111
--- /dev/null
+++ b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Plugin/Md5/CommandContentMd5PluginTest.php
@@ -0,0 +1,97 @@
+<?php
+
+namespace Guzzle\Tests\Plugin\Md5;
+
+use Guzzle\Common\Event;
+use Guzzle\Plugin\Md5\CommandContentMd5Plugin;
+use Guzzle\Service\Description\ServiceDescription;
+use Guzzle\Service\Client;
+
+/**
+ * @covers Guzzle\Plugin\Md5\CommandContentMd5Plugin
+ */
+class CommandContentMd5PluginTest extends \Guzzle\Tests\GuzzleTestCase
+{
+ protected function getClient()
+ {
+ $description = new ServiceDescription(array(
+ 'operations' => array(
+ 'test' => array(
+ 'httpMethod' => 'PUT',
+ 'parameters' => array(
+ 'ContentMD5' => array(),
+ 'Body' => array(
+ 'location' => 'body'
+ )
+ )
+ )
+ )
+ ));
+
+ $client = new Client();
+ $client->setDescription($description);
+
+ return $client;
+ }
+
+ public function testHasEvents()
+ {
+ $this->assertNotEmpty(CommandContentMd5Plugin::getSubscribedEvents());
+ }
+
+ public function testValidatesMd5WhenParamExists()
+ {
+ $client = $this->getClient();
+ $command = $client->getCommand('test', array(
+ 'Body' => 'Foo',
+ 'ContentMD5' => true
+ ));
+ $event = new Event(array('command' => $command));
+ $request = $command->prepare();
+ $plugin = new CommandContentMd5Plugin();
+ $plugin->onCommandBeforeSend($event);
+ $this->assertEquals('E1bGfXrRY42Ba/uCLdLCXQ==', (string) $request->getHeader('Content-MD5'));
+ }
+
+ public function testDoesNothingWhenNoPayloadExists()
+ {
+ $client = $this->getClient();
+ $client->getDescription()->getOperation('test')->setHttpMethod('GET');
+ $command = $client->getCommand('test');
+ $event = new Event(array('command' => $command));
+ $request = $command->prepare();
+ $plugin = new CommandContentMd5Plugin();
+ $plugin->onCommandBeforeSend($event);
+ $this->assertNull($request->getHeader('Content-MD5'));
+ }
+
+ public function testAddsValidationToResponsesOfContentMd5()
+ {
+ $client = $this->getClient();
+ $client->getDescription()->getOperation('test')->setHttpMethod('GET');
+ $command = $client->getCommand('test', array(
+ 'ValidateMD5' => true
+ ));
+ $event = new Event(array('command' => $command));
+ $request = $command->prepare();
+ $plugin = new CommandContentMd5Plugin();
+ $plugin->onCommandBeforeSend($event);
+ $listeners = $request->getEventDispatcher()->getListeners('request.complete');
+ $this->assertNotEmpty($listeners);
+ }
+
+ public function testIgnoresValidationWhenDisabled()
+ {
+ $client = $this->getClient();
+ $client->getDescription()->getOperation('test')->setHttpMethod('GET');
+ $command = $client->getCommand('test', array(
+ 'ValidateMD5' => false
+ ));
+ $event = new Event(array('command' => $command));
+ $request = $command->prepare();
+ $plugin = new CommandContentMd5Plugin();
+ $plugin->onCommandBeforeSend($event);
+ $listeners = $request->getEventDispatcher()->getListeners('request.complete');
+ $this->assertEmpty($listeners);
+ }
+}