8 use Magento\Mtf\Block\Block;
9 use Magento\Mtf\Client\ElementInterface;
10 use Magento\Mtf\Client\Locator;
22 private $webhookEventOptionsMap = [
23 'CASE_CREATION' =>
'Case Creation',
24 'CASE_REVIEW' =>
'Case Review',
25 'GUARANTEE_COMPLETION' =>
'Guarantee Completion' 33 private $webhookAddedElement =
'//table[@id="webhooks"]//tr[./td/span/text()="%s" and ./td/span/text()="%s"]';
40 private $webhookUrl =
'[id="webhookUrl"]';
47 private $webhookTeamOption =
'.//select[@id="webhookTeams"]//option[text()="%s"]';
54 private $webhookEventOption =
'select[id="webhookEvent"] option[value="%s"]';
61 private $webhookAddButton =
'[id="addWebhook"] [type=submit]';
68 private $webhookDeleteButton =
'[class*="webhook-delete"]';
75 private $webhookDeleteConfirmButton =
'[class="appriseOuter"] button[value="ok"]';
85 $handlerUrl = $this->getHandlerUrl();
87 foreach ($this->webhookEventOptionsMap as $webhookEventCode => $webhookEventName) {
88 if ($this->getWebhook($team, $webhookEventName)) {
92 $this->addWebhook($handlerUrl, $webhookEventCode, $team);
104 foreach ($this->webhookEventOptionsMap as $webhookEventName) {
105 if ($webhook = $this->getWebhook($team, $webhookEventName)) {
106 $this->deleteWebhook($webhook);
118 private function getWebhook($team, $webhookEventName)
120 $webhook = $this->_rootElement->find(
121 sprintf($this->webhookAddedElement, $team, $webhookEventName),
122 Locator::SELECTOR_XPATH
125 return $webhook->isPresent() ? $webhook :
null;
134 private function deleteWebhook(ElementInterface $webhook)
136 $webhook->find($this->webhookDeleteButton)->click();
137 $this->_rootElement->find($this->webhookDeleteConfirmButton)->click();
148 private function addWebhook(
153 $this->setEvent($webhookEventCode);
154 $this->setTeam($team);
155 $this->setUrl($handlerUrl);
165 private function setEvent($webhookEventCode)
167 $this->_rootElement->find(
168 sprintf($this->webhookEventOption, $webhookEventCode)
178 private function setTeam($team)
180 $this->_rootElement->find(
181 sprintf($this->webhookTeamOption, $team),
182 Locator::SELECTOR_XPATH
192 private function setUrl($handlerUrl)
194 $this->_rootElement->find($this->webhookUrl)->setValue($handlerUrl);
202 private function submit()
204 $this->_rootElement->find($this->webhookAddButton)->click();
212 private function getHandlerUrl()
214 return $_ENV[
'app_frontend_url'] .
'signifyd/webhooks/handler';