Open Monograph Press  3.3.0
AbstractResponseTest.php
1 <?php
2 
3 namespace Omnipay\Common\Message;
4 
5 use Mockery as m;
6 use Omnipay\Tests\TestCase;
7 
8 class AbstractResponseTest extends TestCase
9 {
10  public function setUp()
11  {
12  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponse')->makePartial();
13  }
14 
15  public function testConstruct()
16  {
17  $data = array('foo' => 'bar');
18  $request = $this->getMockRequest();
19  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponse', array($request, $data))->makePartial();
20 
21  $this->assertSame($request, $this->response->getRequest());
22  $this->assertSame($data, $this->response->getData());
23  }
24 
25  public function testDefaultMethods()
26  {
27  $this->assertFalse($this->response->isPending());
28  $this->assertFalse($this->response->isRedirect());
29  $this->assertFalse($this->response->isTransparentRedirect());
30  $this->assertFalse($this->response->isCancelled());
31  $this->assertNull($this->response->getData());
32  $this->assertNull($this->response->getTransactionReference());
33  $this->assertNull($this->response->getMessage());
34  $this->assertNull($this->response->getCode());
35  }
36 
42  {
43  $this->response->getRedirectResponse();
44  }
45 
51  {
52  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial();
53  $this->response->shouldReceive('isRedirect')->once()->andReturn(false);
54 
55  $this->response->getRedirectResponse();
56  }
57 
58  public function testGetRedirectResponseGet()
59  {
60  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial();
61  $this->response->shouldReceive('getRedirectMethod')->andReturn('GET');
62 
63  $httpResponse = $this->response->getRedirectResponse();
64  $this->assertSame(302, $httpResponse->getStatusCode());
65  $this->assertSame('https://example.com/redirect?a=1&b=2', $httpResponse->getTargetUrl());
66  }
67 
68  public function testGetRedirectResponsePost()
69  {
70  $data = array('foo' => 'bar', 'key&"' => '<value>');
71  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial();
72  $this->response->shouldReceive('getRedirectMethod')->andReturn('POST');
73  $this->response->shouldReceive('getRedirectData')->andReturn($data);
74 
75  $httpResponse = $this->response->getRedirectResponse();
76  $this->assertSame(200, $httpResponse->getStatusCode());
77  $this->assertContains('<form action="https://example.com/redirect?a=1&amp;b=2" method="post">', $httpResponse->getContent());
78  $this->assertContains('<input type="hidden" name="foo" value="bar" />', $httpResponse->getContent());
79  $this->assertContains('<input type="hidden" name="key&amp;&quot;" value="&lt;value&gt;" />', $httpResponse->getContent());
80  }
81 
87  {
88  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial();
89  $this->response->shouldReceive('getRedirectMethod')->andReturn('DELETE');
90 
91  $this->response->getRedirectResponse();
92  }
93 
94  public function testGetTransactionIdNull()
95  {
96  $this->response = m::mock('\Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse')->makePartial();
97  $this->assertNull($this->response->getTransactionId());
98  }
99 }
100 
102 {
103  public function isPending()
104  {
105  return false;
106  }
107 
108  public function isSuccessful()
109  {
110  return false;
111  }
112 
113  public function isRedirect()
114  {
115  return true;
116  }
117 
118  public function getRedirectUrl()
119  {
120  return 'https://example.com/redirect?a=1&b=2';
121  }
122 
123  public function getRedirectMethod() {}
124  public function getRedirectData() {}
125 }
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse\isSuccessful
isSuccessful()
Definition: AbstractResponseTest.php:108
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse\getRedirectUrl
getRedirectUrl()
Definition: AbstractResponseTest.php:118
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse\getRedirectData
getRedirectData()
Definition: AbstractResponseTest.php:124
Omnipay\Common\Message\AbstractResponseTest
Definition: AbstractResponseTest.php:8
Omnipay\Common\Message\AbstractResponseTest\testDefaultMethods
testDefaultMethods()
Definition: AbstractResponseTest.php:25
Omnipay\Common\Message\RedirectResponseInterface
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/RedirectResponseInterface.php:18
Omnipay\Common\Message\AbstractResponseTest\testGetRedirectResponsePost
testGetRedirectResponsePost()
Definition: AbstractResponseTest.php:68
Omnipay\Common\Message\AbstractResponseTest\setUp
setUp()
Definition: AbstractResponseTest.php:10
Omnipay\Common\Message\AbstractResponseTest\testGetRedirectResponseNotSupported
testGetRedirectResponseNotSupported()
Definition: AbstractResponseTest.php:50
Omnipay\Common\Message\AbstractResponseTest\testGetTransactionIdNull
testGetTransactionIdNull()
Definition: AbstractResponseTest.php:94
Omnipay\Common\Message\AbstractResponseTest\testGetRedirectResponseNotImplemented
testGetRedirectResponseNotImplemented()
Definition: AbstractResponseTest.php:41
Omnipay\Common\Message\AbstractResponseTest\testGetRedirectResponseInvalidMethod
testGetRedirectResponseInvalidMethod()
Definition: AbstractResponseTest.php:86
Omnipay\Common\Message\AbstractResponse
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractResponse.php:31
Omnipay\Common\Message
Definition: lib/vendor/omnipay/common/src/Omnipay/Common/Message/AbstractRequest.php:6
Omnipay\Common\Message\AbstractResponseTest\testGetRedirectResponseGet
testGetRedirectResponseGet()
Definition: AbstractResponseTest.php:58
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse\getRedirectMethod
getRedirectMethod()
Definition: AbstractResponseTest.php:123
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse\isPending
isPending()
Definition: AbstractResponseTest.php:103
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse\isRedirect
isRedirect()
Definition: AbstractResponseTest.php:113
Omnipay\Common\Message\AbstractResponseTest\testConstruct
testConstruct()
Definition: AbstractResponseTest.php:15
Omnipay\Common\Message\AbstractResponseTest_MockRedirectResponse
Definition: AbstractResponseTest.php:101