| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Test\Buy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Facebook\WebDriver\WebDriverBy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Facebook\WebDriver\WebDriverExpectedCondition; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Test\PagantisOscommerceTest; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * Class AbstractBuy | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @package Test\Buy | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 12 |  |  |  */ | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | abstract class AbstractBuy extends PagantisOscommerceTest | 
            
                                                                        
                            
            
                                    
            
            
                | 14 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 15 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 16 |  |  |      * Product name | 
            
                                                                        
                            
            
                                    
            
            
                | 17 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 18 |  |  |     const PRODUCT_NAME = 'Matrox G200 MMS'; | 
            
                                                                        
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  |      * Correct purchase message | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |     const CORRECT_PURCHASE_MESSAGE = 'Your Order Has Been Processed!'; | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 26 |  |  |      * Canceled purchase message | 
            
                                                                        
                            
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     const CANCELED_PURCHASE_MESSAGE = 'YOUR ORDER HAS BEEN CANCELED.'; | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |      * Shopping cart message | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |     const SHOPPING_CART_MESSAGE = 'SHOPPING CART'; | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 36 |  |  |      * Empty shopping cart message | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     const EMPTY_SHOPPING_CART = 'SHOPPING CART IS EMPTY'; | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |      * Pagantis Order Title | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |     const PAGANTIS_TITLE = 'Paga+Tarde'; | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |      * Notification route | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |     const NOTIFICATION_FOLDER = '/pagantis/notify'; | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |      * Buy unregistered | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |     public function prepareProductAndCheckout() | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |         $this->goToProductPage(); | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  |         $this->addToCart(); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 60 |  |  |      * testAddToCart | 
            
                                                                        
                            
            
                                    
            
            
                | 61 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |     public function addToCart() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |         $addToCartButtonSearch = WebDriverBy::id('tdb4'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($addToCartButtonSearch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $this->waitUntil($condition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $addToCartButtonElement = $this->webDriver->findElement($addToCartButtonSearch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($addToCartButtonElement)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $addToCartButtonElement->click(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $buyButtonSearch = WebDriverBy::id('tdb5'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($buyButtonSearch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->waitUntil($condition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $buyButtonElement = $this->webDriver->findElement($buyButtonSearch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($buyButtonElement)); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 77 |  |  |         $buyButtonElement->click(); | 
            
                                                                        
                            
            
                                    
            
            
                | 78 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 79 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 80 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 81 |  |  |      * Go to the product page | 
            
                                                                        
                            
            
                                    
            
            
                | 82 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |     public function goToProductPage() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |         $this->webDriver->get(self::OSCURL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |         $productGridSearch = WebDriverBy::className('contentText'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |         $productLinkSearch = $productGridSearch->linkText(self::PRODUCT_NAME); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->webDriver->wait()->until( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             WebDriverExpectedCondition::elementToBeClickable( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |                 $productLinkSearch | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |         $productLinkElement = $this->webDriver->findElement($productLinkSearch); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($productLinkElement)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         sleep(3); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |         $productLinkElement->click(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $this->assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             self::PRODUCT_NAME . ', ' . self::TITLE, | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 100 |  |  |             $this->webDriver->getTitle() | 
            
                                                                        
                                                                
            
                                    
            
            
                | 101 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 102 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 103 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 104 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 105 |  |  |      * Fill the shipping method information | 
            
                                                                        
                            
            
                                    
            
            
                | 106 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 107 |  |  |     public function fillPaymentMethod() | 
            
                                                                        
                            
            
                                    
            
            
                | 108 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 109 |  |  |         $button = WebDriverBy::xpath("//tr[@class='moduleRow']/td[2]/input[@value='pagantis']"); | 
            
                                                                        
                            
            
                                    
            
            
                | 110 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($button); | 
            
                                                                        
                            
            
                                    
            
            
                | 111 |  |  |         $this->waitUntil($condition); | 
            
                                                                        
                            
            
                                    
            
            
                | 112 |  |  |         $this->findByXpath("//tr[@class='moduleRow']/td[2]/input[@value='pagantis']")->click(); | 
            
                                                                        
                            
            
                                    
            
            
                | 113 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 114 |  |  |         $buttonSearch = WebDriverBy::id('tdb6'); | 
            
                                                                        
                            
            
                                    
            
            
                | 115 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($buttonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 116 |  |  |         $this->waitUntil($condition); | 
            
                                                                        
                            
            
                                    
            
            
                | 117 |  |  |         $buttonElement = $this->webDriver->findElement($buttonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 118 |  |  |         $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($buttonElement)); | 
            
                                                                        
                            
            
                                    
            
            
                | 119 |  |  |         $buttonElement->click(); | 
            
                                                                        
                            
            
                                    
            
            
                | 120 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 122 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 123 |  |  |      * Fill the shipping method information | 
            
                                                                        
                            
            
                                    
            
            
                | 124 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 125 |  |  |     public function fillShippingMethod() | 
            
                                                                        
                            
            
                                    
            
            
                | 126 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 127 |  |  |         $buttonSearch = WebDriverBy::id('tdb6'); | 
            
                                                                        
                            
            
                                    
            
            
                | 128 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($buttonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |         $this->waitUntil($condition); | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |         $buttonElement = $this->webDriver->findElement($buttonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |         $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($buttonElement)); | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         $buttonElement->click(); | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |      * Complete order and open Pagantis (redirect or iframe methods) | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |      * @throws \Facebook\WebDriver\Exception\NoSuchElementException | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |      * @throws \Facebook\WebDriver\Exception\TimeOutException | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |     public function goToPagantis() | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |         $buttonSearch = WebDriverBy::id('tdb5'); | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($buttonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         $this->waitUntil($condition); | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |         $buttonElement = $this->webDriver->findElement($buttonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |         $this->webDriver->executeScript("arguments[0].scrollIntoView(true);", array($buttonElement)); | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |         $buttonElement->click(); | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |      * Close previous pagantis session if an user is logged in | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |      * @throws \Facebook\WebDriver\Exception\NoSuchElementException | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |      * @throws \Facebook\WebDriver\Exception\TimeOutException | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |     public function logoutFromPagantis() | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |         // Wait the page to render (check the simulator is rendered) | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |         $this->webDriver->wait()->until( | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |             WebDriverExpectedCondition::elementToBeClickable( | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |                 WebDriverBy::name('minusButton') | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |             ) | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |         ); | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |         // Check if user is logged in in Pagantis | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |         $closeSession = $this->webDriver->findElements(WebDriverBy::name('one_click_return_to_normal')); | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |         if (count($closeSession) !== 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |             //Logged out | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |             $continueButtonSearch = WebDriverBy::name('one_click_return_to_normal'); | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |             $continueButtonElement = $this->webDriver->findElement($continueButtonSearch); | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |             $continueButtonElement->click(); | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 176 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 177 |  |  |      * Verify That UTF Encoding is working | 
            
                                                                        
                            
            
                                    
            
            
                | 178 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     public function verifyUTF8() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $paymentFormElement = WebDriverBy::className('FieldsPreview-desc'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |         $condition = WebDriverExpectedCondition::visibilityOfElementLocated($paymentFormElement); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         $this->webDriver->wait()->until($condition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $this->assertTrue((bool) $condition); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $this->assertSame( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |             $this->configuration['firstname'] . ' ' . $this->configuration['lastname'], | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 187 |  |  |             $this->findByClass('FieldsPreview-desc')->getText() | 
            
                                                                        
                                                                
            
                                    
            
            
                | 188 |  |  |         ); | 
            
                                                                        
                                                                
            
                                    
            
            
                | 189 |  |  |     } | 
            
                                                                        
                                                                
            
                                    
            
            
                | 190 |  |  |  | 
            
                                                                        
                                                                
            
                                    
            
            
                | 191 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 192 |  |  |      * Check purchase return message | 
            
                                                                        
                            
            
                                    
            
            
                | 193 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 194 |  |  |      * @param string $message | 
            
                                                                        
                            
            
                                    
            
            
                | 195 |  |  |      * | 
            
                                                                        
                            
            
                                    
            
            
                | 196 |  |  |      * @throws \Facebook\WebDriver\Exception\NoSuchElementException | 
            
                                                                        
                            
            
                                    
            
            
                | 197 |  |  |      * @throws \Facebook\WebDriver\Exception\TimeOutException | 
            
                                                                        
                            
            
                                    
            
            
                | 198 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     public function checkPurchaseReturn($message = '') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |         // Check if all goes good | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         $this->webDriver->wait()->until( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |             WebDriverExpectedCondition::visibilityOfElementLocated( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |                 WebDriverBy::cssSelector('#bodyContent>h1') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             ) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |         $successMessage = $this->findByCss('#bodyContent>h1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |         $this->assertContains( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |             $message, | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 210 |  |  |             $successMessage->getText() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         ); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 213 |  |  | } |