PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/addons/ResellersCenter/vendor/omnipay-2.3/vendor/omnipay/tests/src/Omnipay/Tests/GatewayTestCase.php

https://bitbucket.org/tecsecret/central-tecsecret
PHP | 354 lines | 277 code | 50 blank | 27 comment | 30 complexity | e44c34d2bc1cbfb17e27085e9006f96e MD5 | raw file
Possible License(s): Apache-2.0, BSD-3-Clause, MIT, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. namespace Omnipay\Tests;
  3. /**
  4. * Base Gateway Test class
  5. *
  6. * Ensures all gateways conform to consistent standards
  7. */
  8. abstract class GatewayTestCase extends TestCase
  9. {
  10. public function testGetNameNotEmpty()
  11. {
  12. $name = $this->gateway->getName();
  13. $this->assertNotEmpty($name);
  14. $this->assertInternalType('string', $name);
  15. }
  16. public function testGetShortNameNotEmpty()
  17. {
  18. $shortName = $this->gateway->getShortName();
  19. $this->assertNotEmpty($shortName);
  20. $this->assertInternalType('string', $shortName);
  21. }
  22. public function testGetDefaultParametersReturnsArray()
  23. {
  24. $settings = $this->gateway->getDefaultParameters();
  25. $this->assertInternalType('array', $settings);
  26. }
  27. public function testDefaultParametersHaveMatchingMethods()
  28. {
  29. $settings = $this->gateway->getDefaultParameters();
  30. foreach ($settings as $key => $default) {
  31. $getter = 'get'.ucfirst($this->camelCase($key));
  32. $setter = 'set'.ucfirst($this->camelCase($key));
  33. $value = uniqid();
  34. $this->assertTrue(method_exists($this->gateway, $getter), "Gateway must implement $getter()");
  35. $this->assertTrue(method_exists($this->gateway, $setter), "Gateway must implement $setter()");
  36. // setter must return instance
  37. $this->assertSame($this->gateway, $this->gateway->$setter($value));
  38. $this->assertSame($value, $this->gateway->$getter());
  39. }
  40. }
  41. public function testTestMode()
  42. {
  43. $this->assertSame($this->gateway, $this->gateway->setTestMode(false));
  44. $this->assertSame(false, $this->gateway->getTestMode());
  45. $this->assertSame($this->gateway, $this->gateway->setTestMode(true));
  46. $this->assertSame(true, $this->gateway->getTestMode());
  47. }
  48. public function testCurrency()
  49. {
  50. // currency is normalized to uppercase
  51. $this->assertSame($this->gateway, $this->gateway->setCurrency('eur'));
  52. $this->assertSame('EUR', $this->gateway->getCurrency());
  53. }
  54. public function testSupportsAuthorize()
  55. {
  56. $supportsAuthorize = $this->gateway->supportsAuthorize();
  57. $this->assertInternalType('boolean', $supportsAuthorize);
  58. if ($supportsAuthorize) {
  59. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->authorize());
  60. } else {
  61. $this->assertFalse(method_exists($this->gateway, 'authorize'));
  62. }
  63. }
  64. public function testSupportsCompleteAuthorize()
  65. {
  66. $supportsCompleteAuthorize = $this->gateway->supportsCompleteAuthorize();
  67. $this->assertInternalType('boolean', $supportsCompleteAuthorize);
  68. if ($supportsCompleteAuthorize) {
  69. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->completeAuthorize());
  70. } else {
  71. $this->assertFalse(method_exists($this->gateway, 'completeAuthorize'));
  72. }
  73. }
  74. public function testSupportsCapture()
  75. {
  76. $supportsCapture = $this->gateway->supportsCapture();
  77. $this->assertInternalType('boolean', $supportsCapture);
  78. if ($supportsCapture) {
  79. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->capture());
  80. } else {
  81. $this->assertFalse(method_exists($this->gateway, 'capture'));
  82. }
  83. }
  84. public function testSupportsPurchase()
  85. {
  86. $supportsPurchase = $this->gateway->supportsPurchase();
  87. $this->assertInternalType('boolean', $supportsPurchase);
  88. if ($supportsPurchase) {
  89. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->purchase());
  90. } else {
  91. $this->assertFalse(method_exists($this->gateway, 'purchase'));
  92. }
  93. }
  94. public function testSupportsCompletePurchase()
  95. {
  96. $supportsCompletePurchase = $this->gateway->supportsCompletePurchase();
  97. $this->assertInternalType('boolean', $supportsCompletePurchase);
  98. if ($supportsCompletePurchase) {
  99. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->completePurchase());
  100. } else {
  101. $this->assertFalse(method_exists($this->gateway, 'completePurchase'));
  102. }
  103. }
  104. public function testSupportsRefund()
  105. {
  106. $supportsRefund = $this->gateway->supportsRefund();
  107. $this->assertInternalType('boolean', $supportsRefund);
  108. if ($supportsRefund) {
  109. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->refund());
  110. } else {
  111. $this->assertFalse(method_exists($this->gateway, 'refund'));
  112. }
  113. }
  114. public function testSupportsVoid()
  115. {
  116. $supportsVoid = $this->gateway->supportsVoid();
  117. $this->assertInternalType('boolean', $supportsVoid);
  118. if ($supportsVoid) {
  119. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->void());
  120. } else {
  121. $this->assertFalse(method_exists($this->gateway, 'void'));
  122. }
  123. }
  124. public function testSupportsCreateCard()
  125. {
  126. $supportsCreate = $this->gateway->supportsCreateCard();
  127. $this->assertInternalType('boolean', $supportsCreate);
  128. if ($supportsCreate) {
  129. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->createCard());
  130. } else {
  131. $this->assertFalse(method_exists($this->gateway, 'createCard'));
  132. }
  133. }
  134. public function testSupportsDeleteCard()
  135. {
  136. $supportsDelete = $this->gateway->supportsDeleteCard();
  137. $this->assertInternalType('boolean', $supportsDelete);
  138. if ($supportsDelete) {
  139. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->deleteCard());
  140. } else {
  141. $this->assertFalse(method_exists($this->gateway, 'deleteCard'));
  142. }
  143. }
  144. public function testSupportsUpdateCard()
  145. {
  146. $supportsUpdate = $this->gateway->supportsUpdateCard();
  147. $this->assertInternalType('boolean', $supportsUpdate);
  148. if ($supportsUpdate) {
  149. $this->assertInstanceOf('Omnipay\Common\Message\RequestInterface', $this->gateway->updateCard());
  150. } else {
  151. $this->assertFalse(method_exists($this->gateway, 'updateCard'));
  152. }
  153. }
  154. public function testAuthorizeParameters()
  155. {
  156. if ($this->gateway->supportsAuthorize()) {
  157. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  158. // set property on gateway
  159. $getter = 'get'.ucfirst($this->camelCase($key));
  160. $setter = 'set'.ucfirst($this->camelCase($key));
  161. $value = uniqid();
  162. $this->gateway->$setter($value);
  163. // request should have matching property, with correct value
  164. $request = $this->gateway->authorize();
  165. $this->assertSame($value, $request->$getter());
  166. }
  167. }
  168. }
  169. public function testCompleteAuthorizeParameters()
  170. {
  171. if ($this->gateway->supportsCompleteAuthorize()) {
  172. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  173. // set property on gateway
  174. $getter = 'get'.ucfirst($this->camelCase($key));
  175. $setter = 'set'.ucfirst($this->camelCase($key));
  176. $value = uniqid();
  177. $this->gateway->$setter($value);
  178. // request should have matching property, with correct value
  179. $request = $this->gateway->completeAuthorize();
  180. $this->assertSame($value, $request->$getter());
  181. }
  182. }
  183. }
  184. public function testCaptureParameters()
  185. {
  186. if ($this->gateway->supportsCapture()) {
  187. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  188. // set property on gateway
  189. $getter = 'get'.ucfirst($this->camelCase($key));
  190. $setter = 'set'.ucfirst($this->camelCase($key));
  191. $value = uniqid();
  192. $this->gateway->$setter($value);
  193. // request should have matching property, with correct value
  194. $request = $this->gateway->capture();
  195. $this->assertSame($value, $request->$getter());
  196. }
  197. }
  198. }
  199. public function testPurchaseParameters()
  200. {
  201. if ($this->gateway->supportsPurchase()) {
  202. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  203. // set property on gateway
  204. $getter = 'get'.ucfirst($this->camelCase($key));
  205. $setter = 'set'.ucfirst($this->camelCase($key));
  206. $value = uniqid();
  207. $this->gateway->$setter($value);
  208. // request should have matching property, with correct value
  209. $request = $this->gateway->purchase();
  210. $this->assertSame($value, $request->$getter());
  211. }
  212. }
  213. }
  214. public function testCompletePurchaseParameters()
  215. {
  216. if ($this->gateway->supportsCompletePurchase()) {
  217. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  218. // set property on gateway
  219. $getter = 'get'.ucfirst($this->camelCase($key));
  220. $setter = 'set'.ucfirst($this->camelCase($key));
  221. $value = uniqid();
  222. $this->gateway->$setter($value);
  223. // request should have matching property, with correct value
  224. $request = $this->gateway->completePurchase();
  225. $this->assertSame($value, $request->$getter());
  226. }
  227. }
  228. }
  229. public function testRefundParameters()
  230. {
  231. if ($this->gateway->supportsRefund()) {
  232. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  233. // set property on gateway
  234. $getter = 'get'.ucfirst($this->camelCase($key));
  235. $setter = 'set'.ucfirst($this->camelCase($key));
  236. $value = uniqid();
  237. $this->gateway->$setter($value);
  238. // request should have matching property, with correct value
  239. $request = $this->gateway->refund();
  240. $this->assertSame($value, $request->$getter());
  241. }
  242. }
  243. }
  244. public function testVoidParameters()
  245. {
  246. if ($this->gateway->supportsVoid()) {
  247. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  248. // set property on gateway
  249. $getter = 'get'.ucfirst($this->camelCase($key));
  250. $setter = 'set'.ucfirst($this->camelCase($key));
  251. $value = uniqid();
  252. $this->gateway->$setter($value);
  253. // request should have matching property, with correct value
  254. $request = $this->gateway->void();
  255. $this->assertSame($value, $request->$getter());
  256. }
  257. }
  258. }
  259. public function testCreateCardParameters()
  260. {
  261. if ($this->gateway->supportsCreateCard()) {
  262. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  263. // set property on gateway
  264. $getter = 'get'.ucfirst($this->camelCase($key));
  265. $setter = 'set'.ucfirst($this->camelCase($key));
  266. $value = uniqid();
  267. $this->gateway->$setter($value);
  268. // request should have matching property, with correct value
  269. $request = $this->gateway->createCard();
  270. $this->assertSame($value, $request->$getter());
  271. }
  272. }
  273. }
  274. public function testDeleteCardParameters()
  275. {
  276. if ($this->gateway->supportsDeleteCard()) {
  277. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  278. // set property on gateway
  279. $getter = 'get'.ucfirst($this->camelCase($key));
  280. $setter = 'set'.ucfirst($this->camelCase($key));
  281. $value = uniqid();
  282. $this->gateway->$setter($value);
  283. // request should have matching property, with correct value
  284. $request = $this->gateway->deleteCard();
  285. $this->assertSame($value, $request->$getter());
  286. }
  287. }
  288. }
  289. public function testUpdateCardParameters()
  290. {
  291. if ($this->gateway->supportsUpdateCard()) {
  292. foreach ($this->gateway->getDefaultParameters() as $key => $default) {
  293. // set property on gateway
  294. $getter = 'get'.ucfirst($this->camelCase($key));
  295. $setter = 'set'.ucfirst($this->camelCase($key));
  296. $value = uniqid();
  297. $this->gateway->$setter($value);
  298. // request should have matching property, with correct value
  299. $request = $this->gateway->updateCard();
  300. $this->assertSame($value, $request->$getter());
  301. }
  302. }
  303. }
  304. }