| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Overwatch\ResultBundle\Tests\E2E; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Facebook\WebDriver\WebDriverBy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Overwatch\ResultBundle\DataFixtures\ORM\TestResultFixtures; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Overwatch\TestBundle\DataFixtures\ORM\TestFixtures; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Overwatch\UserBundle\Tests\Base\WebDriverTestCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * ViewTestTest | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * Tests the View Test page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | class ViewTestTest extends WebDriverTestCase | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     public function testTest1Results() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $this->logInAsUser('user-1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |         $this->clickThroughToTest(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |         $this->assertEquals(TestFixtures::$tests['test-1']->getName(), $this->getHeaderText()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |         $this->assertCount(3, $this->getResultsOnPage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |         $this->assertEquals(TestResultFixtures::$results['result-3']->getInfo(), $this->getResultsOnPage()[0]->getText()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |         $this->assertTimestampEquals(TestResultFixtures::$results['result-3']->getCreatedAt(), $this->getResultsOnPage(' a')[0]->getAttribute('title')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         $this->assertContains(strtolower(TestResultFixtures::$results['result-3']->getStatus()), $this->getResultsOnPage('')[0]->getAttribute('class')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $this->assertEquals(TestResultFixtures::$results['result-2']->getInfo(), $this->getResultsOnPage()[1]->getText()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $this->assertTimestampEquals(TestResultFixtures::$results['result-2']->getCreatedAt(), $this->getResultsOnPage(' a')[1]->getAttribute('title')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $this->assertContains(strtolower(TestResultFixtures::$results['result-2']->getStatus()), $this->getResultsOnPage('')[1]->getAttribute('class')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         $this->assertEquals(TestResultFixtures::$results['result-1']->getInfo(), $this->getResultsOnPage()[2]->getText()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $this->assertTimestampEquals(TestResultFixtures::$results['result-1']->getCreatedAt(), $this->getResultsOnPage(' a')[2]->getAttribute('title')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->assertContains(strtolower(TestResultFixtures::$results['result-1']->getStatus()), $this->getResultsOnPage('')[2]->getAttribute('class')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     public function testTest2Results() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $this->logInAsUser('user-1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $this->clickThroughToTest(2); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         $this->assertEquals(TestFixtures::$tests['test-2']->getName(), $this->getHeaderText()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |         $this->assertCount(1, $this->getResultsOnPage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $this->assertEquals(TestResultFixtures::$results['result-4']->getInfo(), $this->getResultsOnPage()[0]->getText()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |         $this->assertTimestampEquals(TestResultFixtures::$results['result-4']->getCreatedAt(), $this->getResultsOnPage(' a')[0]->getAttribute('title')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         $this->assertContains(strtolower(TestResultFixtures::$results['result-4']->getStatus()), $this->getResultsOnPage('')[0]->getAttribute('class')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     public function testDeleteTest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |         $this->logInAsUser('user-1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |         $this->clickThroughToTest(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $this->getActionItem(2)->click(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $this->waitForAlert(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         $this->webDriver->switchTo()->alert()->accept(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->assertCount(1, $this->webDriver->findElements( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |             WebDriverBy::cssSelector('.groups li:first-child .tests li div.test') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         )); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function testRunTest() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $this->logInAsUser('user-1'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $this->clickThroughToTest(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         $this->getActionItem(3)->click(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $this->assertCount(4, $this->getResultsOnPage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |     public function testEditDeleteAndRunInsufficentPermissions() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->logInAsUser('user-2'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $this->clickThroughToTest(1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |          | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->assertFalse($this->getActionItem(1)->isDisplayed()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->assertFalse($this->getActionItem(2)->isDisplayed()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |         $this->assertFalse($this->getActionItem(3)->isDisplayed()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     private function clickThroughToTest($number) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $this->waitForLoadingAnimation(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |         $this->webDriver->findElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |             WebDriverBy::cssSelector('.tests li:nth-child(' . $number . ') .test a:nth-child(3)') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |         )->click(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     private function getResultsOnPage($selector = ' span') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $selector = '.result' . $selector; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $results = $this->webDriver->findElements( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |             WebDriverBy::cssSelector($selector) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         return $results; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |      | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |     private function getActionItem($number) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         return $this->webDriver->findElement( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             WebDriverBy::cssSelector('.results li:last-child a:nth-child(' . $number . ')') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 112 |  |  |     private function assertTimestampEquals($expected, $actual) | 
            
                                                        
            
                                    
            
            
                | 113 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 114 |  |  |         if (!$expected instanceof \DateTime) { | 
            
                                                        
            
                                    
            
            
                | 115 |  |  |             $expected = new \DateTime($expected); | 
            
                                                        
            
                                    
            
            
                | 116 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 117 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 118 |  |  |         if (!$actual instanceof \DateTime) { | 
            
                                                        
            
                                    
            
            
                | 119 |  |  |             $actual = new \DateTime($actual); | 
            
                                                        
            
                                    
            
            
                | 120 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 121 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 122 |  |  |         $this->assertEquals($expected, $actual); | 
            
                                                        
            
                                    
            
            
                | 123 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 124 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 125 |  |  |  |