Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
MethodsTest.php
Go to the documentation of this file.
1 <?php
11 
14 
18 class MethodsTest extends \PHPUnit\Framework\TestCase
19 {
27  public function testPaymentMethod($code, $methodClass)
28  {
29  if ($code == 'vault') {
30  return;
31  }
32  Bootstrap::getObjectManager()->configure($this->getTestConfiguration());
34  $blockFactory = Bootstrap::getObjectManager()->get(
35  \Magento\Framework\View\Element\BlockFactory::class
36  );
38  \Magento\Store\Model\StoreManagerInterface::class
39  )->getStore()->getId();
41  if (empty($methodClass)) {
45  $this->fail("Model of '{$code}' payment method is not found.");
46  }
47  $model = Bootstrap::getObjectManager()->create($methodClass);
48  if ($code == \Magento\Payment\Model\Method\Substitution::CODE) {
49  $paymentInfo = $this->getMockBuilder(
50  \Magento\Payment\Model\Info::class
51  )->disableOriginalConstructor()->setMethods(
52  []
53  )->getMock();
54  $paymentInfo->expects(
55  $this->any()
56  )->method(
57  'getAdditionalInformation'
58  )->will(
59  $this->returnValue('Additional data mock')
60  );
61  $model->setInfoInstance($paymentInfo);
62  }
63  Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
64  ->setMode(State::MODE_DEVELOPER);
65  $this->assertNotEmpty($model->getTitle());
66  foreach ([$model->getFormBlockType(), $model->getInfoBlockType()] as $blockClass) {
67  $message = "Block class: {$blockClass}";
69  $block = $blockFactory->createBlock($blockClass);
70  $block->setArea('frontend');
71  $this->assertFileExists((string)$block->getTemplateFile(), $message);
72  if ($model->canUseInternal()) {
73  try {
75  \Magento\Store\Model\StoreManagerInterface::class
76  )->getStore()->setId(
77  \Magento\Store\Model\Store::DEFAULT_STORE_ID
78  );
79  $block->setArea('adminhtml');
80  $this->assertFileExists((string)$block->getTemplateFile(), $message);
82  \Magento\Store\Model\StoreManagerInterface::class
83  )->getStore()->setId(
84  $storeId
85  );
86  } catch (\Exception $e) {
88  \Magento\Store\Model\StoreManagerInterface::class
89  )->getStore()->setId(
90  $storeId
91  );
92  throw $e;
93  }
94  }
95  }
96  Bootstrap::getObjectManager()->get(\Magento\Framework\App\State::class)
97  ->setMode(State::MODE_DEFAULT);
98  }
99 
103  public function paymentMethodDataProvider()
104  {
106  $helper = Bootstrap::getObjectManager()->get(\Magento\Payment\Helper\Data::class);
107  $result = [];
108  foreach ($helper->getPaymentMethods() as $code => $method) {
109  $result[] = [$code, $method['model']];
110  }
111  return $result;
112  }
113 
118  private function collectFiles($path)
119  {
120  $ds = preg_quote(DIRECTORY_SEPARATOR);
121  $flags = \FilesystemIterator::CURRENT_AS_FILEINFO
122  | \FilesystemIterator::SKIP_DOTS;
123  $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, $flags));
124 
125  return new \RegexIterator(
126  $iterator,
127  '#' . $ds . 'etc' . $ds . 'di\.php$#',
128  \RegexIterator::MATCH,
129  \RegexIterator::USE_KEY
130  );
131  }
132 
136  private function getTestConfiguration()
137  {
138  $result = [];
139  $ds = DIRECTORY_SEPARATOR;
140  $path = __DIR__ . $ds . str_repeat('..' . $ds, 5) . 'Magento';
141 
142  foreach ($this->collectFiles($path) as $file) {
143  $config = include $file->getPathname();
144  $result = array_replace_recursive($result, $config);
145  }
146 
147  return $result;
148  }
149 }
$helper
Definition: iframe.phtml:13
$config
Definition: fraud_order.php:17
defined('TESTS_BP')||define('TESTS_BP' __DIR__
Definition: _bootstrap.php:60
$paymentInfo
$message
$block
Definition: block.php:8
$method
Definition: info.phtml:13
$code
Definition: info.phtml:12