Open Journal Systems  3.3.0
CommandContentMd5PluginTest.php
1 <?php
2 
4 
9 
14 {
15  protected function getClient()
16  {
17  $description = new ServiceDescription(array(
18  'operations' => array(
19  'test' => array(
20  'httpMethod' => 'PUT',
21  'parameters' => array(
22  'ContentMD5' => array(),
23  'Body' => array(
24  'location' => 'body'
25  )
26  )
27  )
28  )
29  ));
30 
31  $client = new Client();
32  $client->setDescription($description);
33 
34  return $client;
35  }
36 
37  public function testHasEvents()
38  {
39  $this->assertNotEmpty(CommandContentMd5Plugin::getSubscribedEvents());
40  }
41 
43  {
44  $client = $this->getClient();
45  $command = $client->getCommand('test', array(
46  'Body' => 'Foo',
47  'ContentMD5' => true
48  ));
49  $event = new Event(array('command' => $command));
50  $request = $command->prepare();
51  $plugin = new CommandContentMd5Plugin();
52  $plugin->onCommandBeforeSend($event);
53  $this->assertEquals('E1bGfXrRY42Ba/uCLdLCXQ==', (string) $request->getHeader('Content-MD5'));
54  }
55 
57  {
58  $client = $this->getClient();
59  $client->getDescription()->getOperation('test')->setHttpMethod('GET');
60  $command = $client->getCommand('test');
61  $event = new Event(array('command' => $command));
62  $request = $command->prepare();
63  $plugin = new CommandContentMd5Plugin();
64  $plugin->onCommandBeforeSend($event);
65  $this->assertNull($request->getHeader('Content-MD5'));
66  }
67 
69  {
70  $client = $this->getClient();
71  $client->getDescription()->getOperation('test')->setHttpMethod('GET');
72  $command = $client->getCommand('test', array(
73  'ValidateMD5' => true
74  ));
75  $event = new Event(array('command' => $command));
76  $request = $command->prepare();
77  $plugin = new CommandContentMd5Plugin();
78  $plugin->onCommandBeforeSend($event);
79  $listeners = $request->getEventDispatcher()->getListeners('request.complete');
80  $this->assertNotEmpty($listeners);
81  }
82 
84  {
85  $client = $this->getClient();
86  $client->getDescription()->getOperation('test')->setHttpMethod('GET');
87  $command = $client->getCommand('test', array(
88  'ValidateMD5' => false
89  ));
90  $event = new Event(array('command' => $command));
91  $request = $command->prepare();
92  $plugin = new CommandContentMd5Plugin();
93  $plugin->onCommandBeforeSend($event);
94  $listeners = $request->getEventDispatcher()->getListeners('request.complete');
95  $this->assertEmpty($listeners);
96  }
97 }
Guzzle\Plugin\Md5\CommandContentMd5Plugin
Definition: CommandContentMd5Plugin.php:13
Guzzle\Tests\GuzzleTestCase
Definition: GuzzleTestCase.php:22
Guzzle\Service\Client
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Service/Client.php:25
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest\getClient
getClient()
Definition: CommandContentMd5PluginTest.php:15
Guzzle\Service\Description\ServiceDescription
Definition: ServiceDescription.php:11
Guzzle\Common\Event
Definition: lib/vendor/guzzle/guzzle/src/Guzzle/Common/Event.php:10
Guzzle\Plugin\Md5\CommandContentMd5Plugin\getSubscribedEvents
static getSubscribedEvents()
Definition: CommandContentMd5Plugin.php:37
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest\testIgnoresValidationWhenDisabled
testIgnoresValidationWhenDisabled()
Definition: CommandContentMd5PluginTest.php:83
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest
Definition: CommandContentMd5PluginTest.php:13
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest\testHasEvents
testHasEvents()
Definition: CommandContentMd5PluginTest.php:37
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest\testAddsValidationToResponsesOfContentMd5
testAddsValidationToResponsesOfContentMd5()
Definition: CommandContentMd5PluginTest.php:68
Guzzle\Tests\Plugin\Md5
Definition: CommandContentMd5PluginTest.php:3
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest\testValidatesMd5WhenParamExists
testValidatesMd5WhenParamExists()
Definition: CommandContentMd5PluginTest.php:42
Guzzle\Tests\Plugin\Md5\CommandContentMd5PluginTest\testDoesNothingWhenNoPayloadExists
testDoesNothingWhenNoPayloadExists()
Definition: CommandContentMd5PluginTest.php:56