FormParamLocationTest.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace GuzzleHttp\Tests\Command\Guzzle\RequestLocation;
  3. use GuzzleHttp\Command\Command;
  4. use GuzzleHttp\Command\Guzzle\Operation;
  5. use GuzzleHttp\Command\Guzzle\Parameter;
  6. use GuzzleHttp\Command\Guzzle\RequestLocation\FormParamLocation;
  7. use GuzzleHttp\Command\Guzzle\RequestLocation\PostFieldLocation;
  8. use GuzzleHttp\Psr7\Request;
  9. /**
  10. * @covers \GuzzleHttp\Command\Guzzle\RequestLocation\FormParamLocation
  11. * @covers \GuzzleHttp\Command\Guzzle\RequestLocation\AbstractLocation
  12. */
  13. class FormParamLocationTest extends \PHPUnit_Framework_TestCase
  14. {
  15. /**
  16. * @group RequestLocation
  17. */
  18. public function testVisitsLocation()
  19. {
  20. $location = new FormParamLocation();
  21. $command = new Command('foo', ['foo' => 'bar']);
  22. $request = new Request('POST', 'http://httbin.org');
  23. $param = new Parameter(['name' => 'foo']);
  24. $request = $location->visit($command, $request, $param);
  25. $operation = new Operation();
  26. $request = $location->after($command, $request, $operation);
  27. $this->assertEquals('foo=bar', $request->getBody()->getContents());
  28. $this->assertArraySubset([0 => 'application/x-www-form-urlencoded; charset=utf-8'], $request->getHeader('Content-Type'));
  29. }
  30. /**
  31. * @group RequestLocation
  32. */
  33. public function testAddsAdditionalProperties()
  34. {
  35. $location = new FormParamLocation();
  36. $command = new Command('foo', ['foo' => 'bar']);
  37. $command['add'] = 'props';
  38. $request = new Request('POST', 'http://httbin.org', []);
  39. $param = new Parameter(['name' => 'foo']);
  40. $request = $location->visit($command, $request, $param);
  41. $operation = new Operation([
  42. 'additionalParameters' => [
  43. 'location' => 'formParam'
  44. ]
  45. ]);
  46. $request = $location->after($command, $request, $operation);
  47. $this->assertEquals('foo=bar&add=props', $request->getBody()->getContents());
  48. }
  49. }