diff --git a/tests/TestBaseClassView.php b/tests/TestBaseClassView.php index 447cfa6b41d..d0df4f65a9a 100644 --- a/tests/TestBaseClassView.php +++ b/tests/TestBaseClassView.php @@ -41,16 +41,28 @@ public static function setupBeforeClass() self::adminLogin($username, $password); } + /** + * @param $name + * @param $view + * @throws \Exception + */ + protected function openAndFindViewTag($name, $view){ + $this->url = $this->getUrl($view); + $this->openView($this->url); + return $this->findViewTag($name,$view); + } + /** * @param string $name * @param array $view + * @throws \Exception */ protected function findViewTag($name, $view) { $url = $this->getUrl($view); $this->openView($url); $element = null; - $filename = null; + $filename = self::$screenshotsFolder. '/'.$name.'.png'; try { $element = self::$webDriver->wait(2)->until( @@ -61,7 +73,7 @@ protected function findViewTag($name, $view) } catch (\Exception $e) { //throw new Exception($e->getMessage()); $screenshot = self::$webDriver->takeScreenshot(); - file_put_contents(self::$screenshotsFolder. '/'.$name.'.png', $screenshot); + file_put_contents($filename, $screenshot); } //$body = $this->webDriver->findElement(WebDriverBy::tagName('body')); //var_dump($body->getText()); @@ -72,7 +84,7 @@ protected function findViewTag($name, $view) 'FAILED viewing %s on route %s, full url %s', $name, $view['route'], - $url + $this->url ) ); } diff --git a/tests/TestBaseClassWeb.php b/tests/TestBaseClassWeb.php index 4b04f54dc7f..b4861a5323d 100644 --- a/tests/TestBaseClassWeb.php +++ b/tests/TestBaseClassWeb.php @@ -17,6 +17,7 @@ use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverExpectedCondition; use Facebook\WebDriver\Exception\TimeOutException; +use User; /** * Class TestBaseClassWeb @@ -31,6 +32,18 @@ class TestBaseClassWeb extends TestBaseClass */ public static $webPort = 4444; + /** @var int $superUserId */ + protected static $superUserId = 1; + + /** @var string $noPermissionsUserPassword */ + protected static $noPermissionsUserPassword = 'myHardPassword'; + + /** @var string $noPermissionsUserUsername */ + protected static $noPermissionsUserUsername = 'noPermissionsUser'; + + /** @var User $noPermissionsUser */ + protected static $noPermissionsUser; + /** * @var WebDriver $webDriver */ diff --git a/tests/controllers/AdminViewsTest.php b/tests/controllers/AdminViewsTest.php index 2e167cb3628..dc7ec314d82 100644 --- a/tests/controllers/AdminViewsTest.php +++ b/tests/controllers/AdminViewsTest.php @@ -13,6 +13,10 @@ namespace ls\tests\controllers; +use Facebook\WebDriver\Interactions\WebDriverActions; +use Facebook\WebDriver\WebDriverBy; +use Facebook\WebDriver\WebDriverExpectedCondition; +use Facebook\WebDriver\WebDriverKeys; use ls\tests\TestBaseClassView; /** @@ -54,6 +58,11 @@ public function addGeneralSettingsViews() return require __DIR__."/../data/views/adminGeneralSettingsViews.php"; } + public function addAdminClickViews() + { + return require __DIR__."/../data/views/adminClickViews.php"; + } + /** * @param string $name * @param array$view @@ -66,7 +75,7 @@ public function testAdminViews($name, $view) $this->assertTrue(true); return; } - $this->findViewTag($name, $view); + $this->openAndFindViewTag($name, $view); } /** @@ -94,7 +103,7 @@ public function testAdminSurveyViews($name, $view) } $view['route'] = ReplaceFields($view['route'], ['{SID}'=> self::$testSurvey->primaryKey]); - $this->findViewTag($name, $view); + $this->openAndFindViewTag($name, $view); } /** @@ -104,7 +113,7 @@ public function testAdminSurveyViews($name, $view) */ public function testSettingsViews($name, $view) { - $this->findViewTag($name, $view); + $this->openAndFindViewTag($name, $view); } /** @@ -122,7 +131,7 @@ public function testUserViews($name,$view){ $uid = 2; } $view['route'] = ReplaceFields($view['route'],['{UID}'=>$uid]); - $this->findViewTag($name, $view); + $this->openAndFindViewTag($name, $view); } /** @@ -132,7 +141,7 @@ public function testUserViews($name,$view){ */ public function testGeneralSettingsViews($name, $view) { - $this->findViewTag($name, $view); + $this->openAndFindViewTag($name, $view); } /** @@ -141,6 +150,40 @@ public function testGeneralSettingsViews($name, $view) * @dataProvider addParticipantsViews */ public function testParticipantsViews($name,$view){ - $this->findViewTag($name, $view); + $this->openAndFindViewTag($name, $view); + } + + + + /** + * @param string $name + * @param array $view + * @throws \Exception + * @throws \Facebook\WebDriver\Exception\NoSuchElementException + * @throws \Facebook\WebDriver\Exception\TimeOutException + * @dataProvider addAdminClickViews + */ + public function testAdminClickViews($name,$view){ + // FIXME need to crate another user + //$this->markTestSkipped(); + $view['clickId'] = ReplaceFields($view['route'],['{UID}'=>self::$noPermissionsUser->primaryKey]); + $url = $this->getUrl($view); + $this->openView($url); + try{ + self::$webDriver->wait(2)->until( + WebDriverExpectedCondition::presenceOfAllElementsLocatedBy( + WebDriverBy::id('set-user-permissions-'.self::$noPermissionsUser->primaryKey) + ) + ); + $clickable = self::$webDriver->findElement(WebDriverBy::id('set-user-permissions-'.self::$noPermissionsUser->primaryKey)); + $clickable->click(); + + }catch (\Exception $e){ + throw $e; + $screenshot = self::$webDriver->takeScreenshot(); + $filename = self::$screenshotsFolder .'/'.$name.'.png'; + file_put_contents($filename, $screenshot); + } } + } diff --git a/tests/data/views/adminClickViews.php b/tests/data/views/adminClickViews.php new file mode 100644 index 00000000000..6b629619880 --- /dev/null +++ b/tests/data/views/adminClickViews.php @@ -0,0 +1,20 @@ +'user/sa/setuserpermissions/uid/{UID}','clickId'=>'set-user-permissions-{UID}']], +]; \ No newline at end of file