Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
RemoveTaxRule.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Fixture\FixtureInterface;
10 use Magento\Mtf\Handler\Curl;
11 use Magento\Mtf\Util\Protocol\CurlInterface;
14 
19 class RemoveTaxRule extends Curl
20 {
24  const TAX_RULE_REMOVE_MESSAGE = 'The tax rule has been deleted';
25 
29  protected $taxRuleGridUrl;
30 
39  public function persist(FixtureInterface $fixture = null)
40  {
41  $this->taxRuleGridUrl = $_ENV['app_backend_url'] . 'tax/rule/index/';
42  $curl = $this->getCurl($this->taxRuleGridUrl);
43  $response = $curl->read();
44  $this->removeTaxRules($response);
45  $curl->close();
46  return $response;
47  }
48 
55  protected function getCurl($url)
56  {
57  $curl = new BackendDecorator(new CurlTransport(), $this->_configuration);
58  $curl->write($url, [], CurlInterface::GET);
59  return $curl;
60  }
61 
68  protected function removeTaxRules($data)
69  {
70  preg_match_all("!tax\/rule\/edit\/rule\/([\d]+)!", $data, $result);
71  if (!isset($result[1]) || empty($result[1])) {
72  return null;
73  }
74  foreach ($result[1] as $taxRuleId) {
75  $this->_deleteTaxRuleRequest((int)$taxRuleId);
76  break;
77  }
78 
79  $curl = $this->getCurl($this->taxRuleGridUrl);
80  $response = $curl->read();
81  $curl->close();
82  return $this->removeTaxRules($response);
83  }
84 
90  protected function deleteTaxRuleRequest($taxRuleId)
91  {
92  $url = $_ENV['app_backend_url'] . 'tax/rule/delete/rule/' . (int) $taxRuleId;
93  $curl = $this->getCurl($url);
94  $response = $curl->read();
95  $this->checkMessage($response, $taxRuleId);
96  $curl->close();
97  }
98 
106  protected function checkMessage($data, $taxRuleId)
107  {
108  preg_match_all('!(' . static::TAX_RULE_REMOVE_MESSAGE . ')!', $data, $result);
109  if (!isset($result[1]) || empty($result[1])) {
110  throw new \RuntimeException('Tax rule ID ' . $taxRuleId . 'not removed!');
111  }
112  }
113 }
$response
Definition: 404.php:11
persist(FixtureInterface $fixture=null)