| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | /* | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  * This file is part of the Sylius package. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  * (c) Paweł Jędrzejewski | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * For the full copyright and license information, please view the LICENSE | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * file that was distributed with this source code. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | namespace Sylius\Behat\Page\Admin\Promotion; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | use Behat\Mink\Element\NodeElement; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | use Sylius\Behat\Behaviour\ChecksCodeImmutability; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Sylius\Behat\Behaviour\NamesIt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Sylius\Behat\Page\Admin\Crud\UpdatePage as BaseUpdatePage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class UpdatePage extends BaseUpdatePage implements UpdatePageInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     use NamesIt; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     use ChecksCodeImmutability; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     public function setPriority(?int $priority): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->getDocument()->fillField('Priority', $priority); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     public function getPriority(): int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         return (int) $this->getElement('priority')->getValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     public function checkChannelsState(string $channelName): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $field = $this->getDocument()->findField($channelName); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return (bool) $field->getValue(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |     public function fillUsageLimit(string $limit): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->getDocument()->fillField('Usage limit', $limit); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function makeExclusive(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->getDocument()->checkField('Exclusive'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |     public function checkCouponBased(): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |         $this->getDocument()->checkField('Coupon based'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |     public function checkChannel(string $name): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->getDocument()->checkField($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     public function setStartsAt(\DateTimeInterface $dateTime): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $timestamp = $dateTime->getTimestamp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->getDocument()->fillField('sylius_promotion_startsAt_date', date('Y-m-d', $timestamp)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->getDocument()->fillField('sylius_promotion_startsAt_time', date('H:i', $timestamp)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |     public function setEndsAt(\DateTimeInterface $dateTime): void | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $timestamp = $dateTime->getTimestamp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->getDocument()->fillField('sylius_promotion_endsAt_date', date('Y-m-d', $timestamp)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->getDocument()->fillField('sylius_promotion_endsAt_time', date('H:i', $timestamp)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     public function hasStartsAt(\DateTimeInterface $dateTime): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $timestamp = $dateTime->getTimestamp(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         return $this->getElement('starts_at_date')->getValue() === date('Y-m-d', $timestamp) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |             && $this->getElement('starts_at_time')->getValue() === date('H:i', $timestamp); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 87 |  |  |     public function hasEndsAt(\DateTimeInterface $dateTime): bool | 
            
                                                                        
                            
            
                                    
            
            
                | 88 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 89 |  |  |         $timestamp = $dateTime->getTimestamp(); | 
            
                                                                        
                            
            
                                    
            
            
                | 90 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 91 |  |  |         return $this->getElement('ends_at_date')->getValue() === date('Y-m-d', $timestamp) | 
            
                                                                        
                            
            
                                    
            
            
                | 92 |  |  |             && $this->getElement('ends_at_time')->getValue() === date('H:i', $timestamp); | 
            
                                                                        
                            
            
                                    
            
            
                | 93 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     public function hasAnyRule(): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $items = $this->getElement('rules')->findAll('css', 'div[data-form-collection="item"]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         return 0 < count($items); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     public function hasRule(string $name): bool | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |         $items = $this->getElement('rules')->findAll('css', 'div[data-form-collection="item"]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |         foreach ($items as $item) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             $selectedOption = $item->find('css', 'option[selected="selected"]'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             /** @var NodeElement $selectedOption */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |             if ($selectedOption->getText() === $name) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |                 return true; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         return false; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     protected function getCodeElement(): NodeElement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         return $this->getElement('code'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     protected function getDefinedElements(): array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |         return [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |             'code' => '#sylius_promotion_code', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |             'priority' => '#sylius_promotion_priority', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |             'coupon_based' => '#sylius_promotion_couponBased', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |             'ends_at' => '#sylius_promotion_endsAt', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |             'ends_at_date' => '#sylius_promotion_endsAt_date', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |             'ends_at_time' => '#sylius_promotion_endsAt_time', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |             'exclusive' => '#sylius_promotion_exclusive', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |             'name' => '#sylius_promotion_name', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |             'rules' => '#rules', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |             'starts_at' => '#sylius_promotion_startsAt', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |             'starts_at_date' => '#sylius_promotion_startsAt_date', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |             'starts_at_time' => '#sylius_promotion_startsAt_time', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |             'usage_limit' => '#sylius_promotion_usageLimit', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 141 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 142 |  |  |  |