Skip to content

Commit

Permalink
add clickable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Dec 30, 2017
1 parent c305604 commit 064eb1d
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 9 deletions.
18 changes: 15 additions & 3 deletions tests/TestBaseClassView.php
Expand Up @@ -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(
Expand All @@ -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());
Expand All @@ -72,7 +84,7 @@ protected function findViewTag($name, $view)
'FAILED viewing %s on route %s, full url %s',
$name,
$view['route'],
$url
$this->url
)
);
}
Expand Down
13 changes: 13 additions & 0 deletions tests/TestBaseClassWeb.php
Expand Up @@ -17,6 +17,7 @@
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\Exception\TimeOutException;
use User;

/**
* Class TestBaseClassWeb
Expand All @@ -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
*/
Expand Down
55 changes: 49 additions & 6 deletions tests/controllers/AdminViewsTest.php
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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
Expand All @@ -66,7 +75,7 @@ public function testAdminViews($name, $view)
$this->assertTrue(true);
return;
}
$this->findViewTag($name, $view);
$this->openAndFindViewTag($name, $view);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand All @@ -104,7 +113,7 @@ public function testAdminSurveyViews($name, $view)
*/
public function testSettingsViews($name, $view)
{
$this->findViewTag($name, $view);
$this->openAndFindViewTag($name, $view);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -132,7 +141,7 @@ public function testUserViews($name,$view){
*/
public function testGeneralSettingsViews($name, $view)
{
$this->findViewTag($name, $view);
$this->openAndFindViewTag($name, $view);
}

/**
Expand All @@ -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);
}
}

}
20 changes: 20 additions & 0 deletions tests/data/views/adminClickViews.php
@@ -0,0 +1,20 @@
<?php
/**
* LimeSurvey
* Copyright (C) 2007-2011 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 or later, see LICENSE.php
* LimeSurvey is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
*/
/**
* This contains a list of survey-related admin views that we can loop for testing
*/
return [
// Central participants DB ---------------------------------------
// --------------------------------------------------
['setUserPermissions', ['route'=>'user/sa/setuserpermissions/uid/{UID}','clickId'=>'set-user-permissions-{UID}']],
];

0 comments on commit 064eb1d

Please sign in to comment.