From 2df50806fc2379888fef91ba832bc8d9b1bea9ec Mon Sep 17 00:00:00 2001 From: Olle Haerstedt Date: Wed, 17 Jan 2018 12:26:13 +0100 Subject: [PATCH] Revert "Merge branch 'TonisOrmisson-test-restructure10'" This reverts commit 88128858d0949129b8505dd3b3c0cc2e13506db5, reversing changes made to 6588f0e728f326754a03821c29501e58238c136e. --- .gitignore | 1 - .travis.yml | 2 +- phpunit.xml | 18 +- tests/DummyController.php | 5 +- tests/TestBaseClass.php | 52 +---- tests/TestBaseClassView.php | 4 +- tests/TestBaseClassWeb.php | 4 +- tests/TestHelper.php | 47 +++- tests/acceptance/README.md | 7 - .../admin/InstallationControllerTest.php | 209 ------------------ tests/acceptance/surveys/AjaxModeTest.php | 114 ---------- .../admin => controllers}/AdminViewsTest.php | 20 +- .../CreateSurveyTest.php | 68 ++++-- .../InstallationControllerTest.php | 7 +- .../SaveDualScaleAnswerOptionsTest.php | 52 +++-- .../TemplateControllerTest.php | 29 ++- .../sql/create-mysql.153.sql | 0 .../sql/create-mysql.258.sql | 0 .../sql/create-mysql.315.sql | 0 .../surveys/limesurvey_survey_186734.lss | 0 .../surveys/limesurvey_survey_352985.lss | 0 .../surveys/limesurvey_survey_366446.lss | 0 .../surveys/limesurvey_survey_454287.lss | 0 .../surveys/limesurvey_survey_563168.lss | 0 .../surveys/limesurvey_survey_583999.lss | 0 .../surveys/limesurvey_survey_677328.lss | 0 .../surveys/limesurvey_survey_834477.lss | 0 .../surveys/limesurvey_survey_88881.lss | 0 .../surveys/limesurvey_survey_917744.lss | 0 .../surveys/limesurvey_survey_975622.lss | 0 .../travis/travis-ci-apache | 0 .../travis/travis_setup.sh | 0 .../views/adminBaseViews.php | 0 .../views/adminGeneralSettingsViews.php | 0 .../views/adminParticipantsViews.php | 0 .../views/adminSettingsViews.php | 0 .../views/adminSurveyViews.php | 0 .../views/adminUsersViews.php | 0 tests/functional/README.md | 6 - .../helpers/CheckDatabaseJsonValuesTest.php | 26 ++- .../helpers/ExpressionCoreAux.php | 28 ++- .../helpers/ExpressionCoreHelperTest.php | 17 +- .../GroupRandomizationTest.php | 41 ++-- .../helpers/UpdateDbHelperTest.php | 32 ++- .../TemplateConfigurationTest.php | 6 +- .../DateTimeDefaultAnswerExpressionTest.php | 48 ++-- .../questions/DateTimeForwardBackTest.php | 31 ++- .../questions/DateTimeTest.php | 134 ++++++----- .../questions/DateTimeValidationTest.php | 41 ++-- .../MultipleChoiceNextPreviousTest.php | 32 +-- tests/resources/README.md | 1 - .../MultipleChoiceWithExpressionTest.php | 14 +- .../surveys/ScreenOutTest.php | 24 +- tests/travis/travis-ci-apache | 25 +++ tests/unit/README.md | 11 - 55 files changed, 498 insertions(+), 658 deletions(-) delete mode 100644 tests/acceptance/README.md delete mode 100644 tests/acceptance/admin/InstallationControllerTest.php delete mode 100644 tests/acceptance/surveys/AjaxModeTest.php rename tests/{acceptance/admin => controllers}/AdminViewsTest.php (84%) rename tests/{acceptance/admin => controllers}/CreateSurveyTest.php (95%) rename tests/{acceptance/admin/questions => controllers}/SaveDualScaleAnswerOptionsTest.php (88%) rename tests/{acceptance/admin => controllers}/TemplateControllerTest.php (73%) rename tests/{resources => data}/sql/create-mysql.153.sql (100%) rename tests/{resources => data}/sql/create-mysql.258.sql (100%) rename tests/{resources => data}/sql/create-mysql.315.sql (100%) rename tests/{resources => data}/surveys/limesurvey_survey_186734.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_352985.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_366446.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_454287.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_563168.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_583999.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_677328.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_834477.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_88881.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_917744.lss (100%) rename tests/{resources => data}/surveys/limesurvey_survey_975622.lss (100%) rename tests/{resources => data}/travis/travis-ci-apache (100%) rename tests/{resources => data}/travis/travis_setup.sh (100%) rename tests/{resources => data}/views/adminBaseViews.php (100%) rename tests/{resources => data}/views/adminGeneralSettingsViews.php (100%) rename tests/{resources => data}/views/adminParticipantsViews.php (100%) rename tests/{resources => data}/views/adminSettingsViews.php (100%) rename tests/{resources => data}/views/adminSurveyViews.php (100%) rename tests/{resources => data}/views/adminUsersViews.php (100%) delete mode 100644 tests/functional/README.md rename tests/{functional => }/helpers/CheckDatabaseJsonValuesTest.php (97%) rename tests/{functional => }/helpers/ExpressionCoreAux.php (97%) rename tests/{functional => }/helpers/ExpressionCoreHelperTest.php (97%) rename tests/{acceptance/surveys => helpers}/GroupRandomizationTest.php (83%) rename tests/{functional => }/helpers/UpdateDbHelperTest.php (99%) rename tests/{acceptance/admin => models}/TemplateConfigurationTest.php (86%) rename tests/{acceptance => }/questions/DateTimeDefaultAnswerExpressionTest.php (89%) rename tests/{acceptance => }/questions/DateTimeForwardBackTest.php (82%) rename tests/{acceptance => }/questions/DateTimeTest.php (68%) rename tests/{acceptance => }/questions/DateTimeValidationTest.php (77%) rename tests/{acceptance => }/questions/MultipleChoiceNextPreviousTest.php (82%) delete mode 100644 tests/resources/README.md rename tests/{acceptance => }/surveys/MultipleChoiceWithExpressionTest.php (96%) rename tests/{acceptance => }/surveys/ScreenOutTest.php (97%) create mode 100644 tests/travis/travis-ci-apache delete mode 100644 tests/unit/README.md diff --git a/.gitignore b/.gitignore index ab67056388b..8dd96ca468c 100644 --- a/.gitignore +++ b/.gitignore @@ -109,7 +109,6 @@ third_party/composer/installed\.json !.eslintignore !.eslint.json !.eslintrc.json -!.travis.yml ## ignore Vagrantfile Vagrantfile diff --git a/.travis.yml b/.travis.yml index 9beaadb02e2..fe919e118ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -43,7 +43,7 @@ before_script: - sudo sed -i -e "s,www-data,travis,g" /etc/apache2/envvars - sudo chown -R travis:travis /var/lib/apache2/fastcgi - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm - - sudo cp -f tests/resources/travis/travis-ci-apache /etc/apache2/sites-available/000-default.conf + - sudo cp -f tests/travis/travis-ci-apache /etc/apache2/sites-available/000-default.conf - sudo sed -e "s?%TRAVIS_BUILD_DIR%?$(pwd)?g" --in-place /etc/apache2/sites-available/000-default.conf - sudo service apache2 restart diff --git a/phpunit.xml b/phpunit.xml index 91c99e93aa8..94633b631b0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,13 +1,19 @@ - - tests/acceptance + + tests/questions - - tests/functional + + tests/helpers - - tests/unit + + tests/models + + + tests/controllers + + + tests/surveys diff --git a/tests/DummyController.php b/tests/DummyController.php index 551dda3b505..5e8081091e7 100644 --- a/tests/DummyController.php +++ b/tests/DummyController.php @@ -1,6 +1,6 @@ importAll(); parent::setUpBeforeClass(); - } - - // the folder getter can be used in @dataProvider methods since the setUpBeforeClass will run after them - - /** - * @return string - */ - public static function getDataFolder(){ - return __DIR__."/resources"; - } - - /** - * @return string - */ - public static function getViewsFolder(){ - return self::getDataFolder().DIRECTORY_SEPARATOR.'views'; - } - - /** - * @return string - */ - public static function getSurveysFolder(){ - return self::getDataFolder().DIRECTORY_SEPARATOR.'surveys'; - } - - /** - * @return string - */ - public static function getTempFolder(){ - return __DIR__."/tmp"; - } + self::$testHelper = new TestHelper(); - /** - * @return string - */ - public static function getScreenShotsFolder(){ - return self::getTempFolder().DIRECTORY_SEPARATOR.'screenshots'; + self::$dataFolder = __DIR__.'/data'; + self::$viewsFolder = self::$dataFolder."/views"; + self::$surveysFolder = self::$dataFolder.'/surveys'; + self::$tempFolder = __DIR__.'/tmp'; + self::$screenshotsFolder = self::$tempFolder.'/screenshots'; + self::$testHelper->importAll(); } /** diff --git a/tests/TestBaseClassView.php b/tests/TestBaseClassView.php index fab22f3409f..447cfa6b41d 100644 --- a/tests/TestBaseClassView.php +++ b/tests/TestBaseClassView.php @@ -11,13 +11,13 @@ * See COPYRIGHT.php for copyright notices and details. */ -namespace LimeSurvey\tests; +namespace ls\tests; use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\WebDriverExpectedCondition; /** - * @package LimeSurvey\tests + * @package ls\tests */ class TestBaseClassView extends TestBaseClassWeb { diff --git a/tests/TestBaseClassWeb.php b/tests/TestBaseClassWeb.php index 90e0d518e43..4b04f54dc7f 100644 --- a/tests/TestBaseClassWeb.php +++ b/tests/TestBaseClassWeb.php @@ -11,7 +11,7 @@ * See COPYRIGHT.php for copyright notices and details. */ -namespace LimeSurvey\tests; +namespace ls\tests; use Facebook\WebDriver\WebDriver; use Facebook\WebDriver\WebDriverBy; @@ -21,7 +21,7 @@ /** * Class TestBaseClassWeb * this is the base class for functional tests that need browser simulation - * @package LimeSurvey\tests + * @package ls\tests */ class TestBaseClassWeb extends TestBaseClass { diff --git a/tests/TestHelper.php b/tests/TestHelper.php index 19b27e9e908..7008d64d317 100644 --- a/tests/TestHelper.php +++ b/tests/TestHelper.php @@ -1,6 +1,6 @@ loadHelper('admin/activate'); } + /** * @param string $title * @param int $surveyId @@ -46,22 +49,28 @@ public function getSgqa($title, $surveyId) 'sid' => $surveyId ] ); + $this->assertNotEmpty($question); + $group = \QuestionGroup::model()->find( 'gid = :gid', [ 'gid' => $question->gid ] ); + $this->assertNotEmpty($group); + $sgqa = sprintf( '%sX%sX%s', $surveyId, $group->gid, $question->qid ); + return [$question, $group, $sgqa]; } + /** * Get survey options for imported survey. * @param int $surveyId @@ -95,6 +104,7 @@ public function getSurveyOptions($surveyId) ); return $surveyOptions; } + /** * @param int $surveyId * @return void @@ -109,9 +119,11 @@ public function activateSurvey($surveyId) $survey->savetimings = ''; $survey->save(); \Survey::model()->resetCache(); // Make sure the saved values will be picked up + $result = \activateSurvey($surveyId); $this->assertEquals(['status' => 'OK', 'pluginFeedback' => null], $result, 'Activate survey is OK'); } + /** * @param int $surveyId * @return void @@ -127,11 +139,12 @@ public function deactivateSurvey($surveyId) $result = $survey->save(); $this->assertTrue($result, 'Survey deactivated'); } + /** * Overwrite the db component with a new * configuration and database. * Before you run this, you might want to save - * the old db config in a variable, so you can + * the old db config in a variable, so you can * reconnect to it after you're done with the new * database. * $config = require(\Yii::app()->getBasePath() . '/config/config.php'); @@ -142,7 +155,9 @@ public function deactivateSurvey($surveyId) public function connectToNewDatabase($databaseName) { $db = \Yii::app()->getDb(); + $config = require(\Yii::app()->getBasePath() . '/config/config.php'); + // Check that we're using MySQL. $conStr = \Yii::app()->db->connectionString; $isMysql = substr($conStr, 0, 5) === 'mysql'; @@ -151,10 +166,12 @@ public function connectToNewDatabase($databaseName) return false; } $this->assertTrue($isMysql, 'This test only works on MySQL'); + // Get database name. preg_match("/dbname=([^;]*)/", $config['components']['db']['connectionString'], $matches); $this->assertEquals(2, count($matches)); $oldDatabase = $matches[1]; + try { $db->createCommand('DROP DATABASE ' . $databaseName)->execute(); } catch (\CDbException $ex) { @@ -162,6 +179,7 @@ public function connectToNewDatabase($databaseName) // Only this error is OK. self::assertTrue(strpos($msg, 'database doesn\'t exist') !== false, 'Could drop database'); } + try { $result = $db->createCommand( sprintf( @@ -175,6 +193,7 @@ public function connectToNewDatabase($databaseName) // This error is OK. $this->assertTrue(strpos($msg, 'database exists') !== false, 'Could create database'); } + // Connect to new database. $db->setActive(false); $newConfig = $config; @@ -189,6 +208,7 @@ public function connectToNewDatabase($databaseName) \Yii::app()->db->schema->refresh(); return \Yii::app()->getDb(); } + /** * @return void */ @@ -201,6 +221,7 @@ public function connectToOriginalDatabase() \Yii::app()->db->schema->getTables(); \Yii::app()->db->schema->refresh(); } + /** * @param int $version * @return \CDbConnection @@ -211,17 +232,22 @@ public function updateDbFromVersion($version, $connection = null) $connection = $this->connectToNewDatabase('__test_update_helper_' . $version); $this->assertNotEmpty($connection, 'Could connect to new database'); } + // Get InstallerController. $inst = new \InstallerController('foobar'); $inst->connection = $connection; + // Check SQL file. - $file = TestBaseClass::getDataFolder().'/sql/create-mysql.' . $version . '.sql'; + $file = __DIR__ . '/data/sql/create-mysql.' . $version . '.sql'; $this->assertFileExists($file, 'SQL file exists: ' . $file); + // Run SQL install file. $result = $inst->_executeSQLFile($file, 'lime_'); $this->assertEquals([], $result, 'No error messages from _executeSQLFile' . print_r($result, true)); + // Run upgrade. $result = \db_upgrade_all($version); + // Check error messages. $flashes = \Yii::app()->user->getFlashes(); if ($flashes) { @@ -229,8 +255,10 @@ public function updateDbFromVersion($version, $connection = null) } $this->assertEmpty($flashes, 'No flash error messages'); $this->assertTrue($result, 'Upgrade successful'); + return $inst->connection; } + /** * Make sure Selenium can preview surveys without * being logged in. @@ -240,6 +268,7 @@ public function enablePreview() { // Make sure we can preview without being logged in. $setting = \SettingGlobal::model()->findByPk('surveyPreview_require_Auth'); + // Possibly this setting does not exist yet. if (empty($setting)) { $setting = new \SettingGlobal(); @@ -251,6 +280,7 @@ public function enablePreview() $setting->save(); } } + /** * Drop database $databaseName. * Use in teardown methods. @@ -269,7 +299,7 @@ public function teardownDatabase($databaseName, $connection = null) $msg = $ex->getMessage(); // Only this error is OK. self::assertTrue( - // MySQL + // MySQL strpos($msg, 'database doesn\'t exist') !== false || // Postgres strpos($msg, "database \"$databaseName\" does not exist") !== false, @@ -277,6 +307,7 @@ public function teardownDatabase($databaseName, $connection = null) ); } } + /** * Use webdriver to put a screenshot in screenshot folder. * @param WebDriver $webDriver @@ -292,6 +323,7 @@ public function takeScreenshot($webDriver, $name) $result = file_put_contents($filename, $screenshot); $this->assertTrue($result > 0, 'Could not write screenshot to file ' . $filename); } + /** * javaTrace() - provide a Java style exception trace * @@ -343,8 +375,10 @@ public function javaTrace($ex, $seen = null) if ($prev) { $result .= "\n" . jTraceEx($prev, $seen); } + return $result; } + /** * @return WebDriver|null */ @@ -370,6 +404,7 @@ public function getWebDriver() sleep(1); } } while (!$success && $tries < 5); + return $webDriver; } -} \ No newline at end of file +} diff --git a/tests/acceptance/README.md b/tests/acceptance/README.md deleted file mode 100644 index 7ad775045b2..00000000000 --- a/tests/acceptance/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# Acceptance tests -from: -https://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test - -> Standard acceptance testing involves performing tests on the full system (e.g. using your web page via a web browser) to see whether the application's functionality satisfies the specification. E.g. "clicking a zoom icon should enlarge the document view by 25%." There is no real continuum of results, just a pass or fail outcome. - -Any test using the Facebook WebDriver should be somewhere here \ No newline at end of file diff --git a/tests/acceptance/admin/InstallationControllerTest.php b/tests/acceptance/admin/InstallationControllerTest.php deleted file mode 100644 index a814c263950..00000000000 --- a/tests/acceptance/admin/InstallationControllerTest.php +++ /dev/null @@ -1,209 +0,0 @@ -getWebDriver(); - self::$domain = getenv('DOMAIN'); - } - - /** - * - */ - public static function teardownAfterClass() - { - $configFile = \Yii::app()->getBasePath() . '/config/config.php'; - if (file_exists($configFile)) { - self::$testHelper->connectToOriginalDatabase(); - } - } - - /** - * - * @throws \CException - */ - public function testBasic() - { - //$this->checkFolders(); - - $configFile = \Yii::app()->getBasePath() . '/config/config.php'; - $databaseName = 'limesurvey'; - - $username = getenv('ADMINUSERNAME'); - if (!$username) { - $username = 'admin'; - } - $password = getenv('PASSWORD'); - if (!$password) { - $password = 'password'; - } - - $dbuser = getenv('DBUSER'); - if (!$dbuser) { - $dbuser = 'root'; - echo 'Default to database user "root". Use DBUSER=... from command-line to override this.' . PHP_EOL; - } - $dbpwd = getenv('DBPASSWORD'); - if (!$dbpwd) { - $dbpwd = ''; - echo 'Default to empty database password. Use DBPASSWORD=... from command-line to override this.' . PHP_EOL; - } - - if (file_exists($configFile)) { - // Delete possible previous database. - try { - $dbo = \Yii::app()->getDb(); - $dbo->createCommand('DROP DATABASE ' . $databaseName)->execute(); - } catch (\CDbException $ex) { - $msg = $ex->getMessage(); - // Only this error is OK. - self::assertTrue( - strpos($msg, "database doesn't exist") !== false, - 'Could drop database. Error message: ' . $msg - ); - } - - // Remove config.php if present. - $result = unlink($configFile); - $this->assertTrue($result, 'Could unlink config.php'); - } - - // Run installer. - $urlMan = \Yii::app()->urlManager; - $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); - $url = $urlMan->createUrl(''); - - try { - - // Installer start page. - self::$webDriver->get($url); - - // Click "Start installation". - $start = self::$webDriver->findElement(WebDriverBy::id('ls-start-installation')); - $start->click(); - - // Accept license. - $accept = self::$webDriver->findElement(WebDriverBy::id('ls-accept-license')); - $accept->click(); - - // Click next at pre-check. - $next = self::$webDriver->findElement(WebDriverBy::id('ls-next')); - $next->click(); - - // Fill in database form. - $dbuserDbType = self::$webDriver->findElement(WebDriverBy::cssSelector('select[name="InstallerConfigForm[dbtype]"] option[value="mysql"]')); - $dbuserInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbuser]"]')); - $dbpwdInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbpwd]"]')); - $dbnameInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbname]"]')); - - $dbuserDbType->click(); - $dbuserInput->clear()->sendKeys($dbuser); - $dbpwdInput->clear()->sendKeys($dbpwd); - $dbnameInput->sendKeys($databaseName); - - // Click next. - $next = self::$webDriver->findElement(WebDriverBy::id('ls-next')); - $next->click(); - - // Click "Create database". - $button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]')); - $button->click(); - - // Click "Populate". - $button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]')); - $button->click(); - - // Fill in admin username/password. - $adminLoginName = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[adminLoginName]"]')); - $adminLoginPwd = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[adminLoginPwd]"]')); - $confirmPwd = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[confirmPwd]"]')); - $adminLoginName->clear()->sendKeys($username); - $adminLoginPwd->clear()->sendKeys($password); - $confirmPwd->clear()->sendKeys($password); - - // Confirm optional settings (admin password etc). - $button = self::$webDriver->findElement(WebDriverBy::cssSelector('input[type="submit"]')); - $button->click(); - - // Go to administration. - $button = self::$webDriver->findElement(WebDriverBy::id('ls-administration')); - $button->click(); - - // Set debug=2 - /* TODO: Can't write to config.php after installation. - $configFile = \Yii::app()->getBasePath() . '/config/config.php'; - $data = file($configFile); - $data = array_map(function($data) { - return stristr($data, "'debug'=>0") ? "'debug'=>2," : $data; - }, $data); - $output = []; - exec('chmod 777 ' . $configFile, $output); - var_dump($output); - $result = file_put_contents($configFile, implode('', $data)); - $this->assertTrue($result > 0, 'Wrote config'); - */ - - // Reset urlManager to adapt to latest config. - $config = require($configFile); - $urlMan = \Yii::app()->urlManager; - $urlMan->setUrlFormat($config['components']['urlManager']['urlFormat']); - - // Login. - self::adminLogin($username, $password); - } catch (NoSuchElementException $ex) { - self::$testHelper->takeScreenshot(self::$webDriver, (new \ReflectionClass($this))->getShortName() . '_' . __FUNCTION__); - $this->assertFalse( - true, - self::$testHelper->javaTrace($ex) - ); - } - } - - /** - * Check that upload/tmp folders are writable. - * @todo Does not work. - */ - public function checkFolders() - { - $instContr = new \InstallerController('dummyvalue'); - $data = []; - $folder = \Yii::app()->getConfig('tempdir') . '/'; - $tempdirIsWritable = $instContr->checkDirectoryWriteable( - $folder, - $data, - 'tmpdir', - 'tperror', - true - ); - $this->assertTrue($tempdirIsWritable, 'Can write to tmp/'); - - $folder = \Yii::app()->getConfig('uploaddir') . '/'; - $uploadIsWritable = $instContr->checkDirectoryWriteable( - $folder, - $data, - 'uploaddir', - 'uerror', - true - ); - $this->assertTrue($uploadIsWritable, 'Can write to upload/'); - } -} diff --git a/tests/acceptance/surveys/AjaxModeTest.php b/tests/acceptance/surveys/AjaxModeTest.php deleted file mode 100644 index 2826b416a96..00000000000 --- a/tests/acceptance/surveys/AjaxModeTest.php +++ /dev/null @@ -1,114 +0,0 @@ -activateSurvey(self::$surveyId); - } - /** - * Test that Ajax mode records answer. - */ - public function testAjaxModeRecordsAnswer() - { - // TODO: This works when run individually, but not - // as part of the test suit. Screenshot shows it's - // stuck on welcome page. - $this->markTestSkipped(); - // Get questions. - $survey = \Survey::model()->findByPk(self::$surveyId); - $questionObjects = $survey->groups[0]->questions; - $questions = []; - foreach ($questionObjects as $q) { - $questions[$q->title] = $q; - } - // Make sure there are no responses in database. - $query = sprintf( - 'SELECT * FROM {{survey_%d}}', - self::$surveyId - ); - $db = \Yii::app()->getDb(); - $rows = $db->createCommand($query)->queryAll(); - $this->assertEmpty($rows, 'No answers'); - // Execute survey. - $urlMan = \Yii::app()->urlManager; - $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); - $url = $urlMan->createUrl( - 'survey/index', - [ - 'sid' => self::$surveyId, - 'newtest' => 'Y', - 'lang' => 'pt' - ] - ); - try { - // Click welcome page. - self::$webDriver->get($url); - $nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); - $nextButton->click(); - sleep(1); - // TODO: Temporary, test fails here (but only on fresh install). - $screenshot = self::$webDriver->takeScreenshot(); - $filename = self::$screenshotsFolder.'/AjaxModeTest.png'; - file_put_contents($filename, $screenshot); - // Find yes-no radio buttons, click "Yes". - $items = self::$webDriver->findElements(WebDriverBy::cssSelector('ul.yesno-button li')); - $this->assertCount(3, $items, 'Three radio buttons for yes-no question'); - $items[0]->click(); - // Check that EM is reacting. - $div = self::$webDriver->findElement(WebDriverBy::cssSelector('div#question' . $questions['q2']->qid)); - $this->assertEquals($div->getText(), 'The previous answer was FALSE'); - // Click "No". - $items[1]->click(); - // Check EM. - $div = self::$webDriver->findElement(WebDriverBy::cssSelector('div#question' . $questions['q2']->qid)); - $this->assertEquals($div->getText(), 'The previous answer was TRUE'); - // Click submit. - $submitButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); - $submitButton->click(); - // Check so that we see end page. - $completed = self::$webDriver->findElement(WebDriverBy::cssSelector('div.completed-text')); - $this->assertEquals( - $completed->getText(), - "Thank you!\nYour survey responses have been recorded.", - 'I can see completed text' - ); - } catch (NoSuchElementException $ex) { - $screenshot = self::$webDriver->takeScreenshot(); - $filename = self::$screenshotsFolder.'/AjaxModeTest.png'; - file_put_contents($filename, $screenshot); - $this->assertFalse( - true, - 'Url: ' . $url . PHP_EOL . - 'Screenshot in ' .$filename . PHP_EOL . $ex->getMessage() - ); - } - // Check answer in database. - $query = sprintf( - 'SELECT * FROM {{survey_%d}}', - self::$surveyId - ); - $rows = $db->createCommand($query)->queryAll(); - $this->assertCount(1, $rows); - $sgqa = self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['q1']->qid; - $answer = $rows[0][$sgqa]; - $this->assertEquals('N', $answer, 'Answer is "N"'); - } -} \ No newline at end of file diff --git a/tests/acceptance/admin/AdminViewsTest.php b/tests/controllers/AdminViewsTest.php similarity index 84% rename from tests/acceptance/admin/AdminViewsTest.php rename to tests/controllers/AdminViewsTest.php index 3de526d25dc..2e167cb3628 100644 --- a/tests/acceptance/admin/AdminViewsTest.php +++ b/tests/controllers/AdminViewsTest.php @@ -11,15 +11,15 @@ * See COPYRIGHT.php for copyright notices and details. */ -namespace LimeSurvey\tests\acceptance\admin; +namespace ls\tests\controllers; -use LimeSurvey\tests\TestBaseClassView; +use ls\tests\TestBaseClassView; /** * Class AdminViewsTest * This test loops through all basic admin view pages and cheks if they open withour errors * - * @package LimeSurvey\tests + * @package ls\tests * @group adminviews */ class AdminViewsTest extends TestBaseClassView @@ -27,31 +27,31 @@ class AdminViewsTest extends TestBaseClassView public function addBaseViews() { - return require self::getViewsFolder()."/adminBaseViews.php"; + return require __DIR__."/../data/views/adminBaseViews.php"; } public function addSurveyViews() { - return require self::getViewsFolder()."/adminSurveyViews.php"; + return require __DIR__."/../data/views/adminSurveyViews.php"; } public function addSettingsViews() { - return require self::getViewsFolder()."/adminSettingsViews.php"; + return require __DIR__."/../data/views/adminSettingsViews.php"; } public function addUsersViews() { - return require self::getViewsFolder()."/adminUsersViews.php"; + return require __DIR__."/../data/views/adminUsersViews.php"; } public function addParticipantsViews() { - return require self::getViewsFolder()."/adminParticipantsViews.php"; + return require __DIR__."/../data/views/adminParticipantsViews.php"; } public function addGeneralSettingsViews() { - return require self::getViewsFolder()."/adminGeneralSettingsViews.php"; + return require __DIR__."/../data/views/adminGeneralSettingsViews.php"; } /** @@ -89,7 +89,7 @@ public function testAdminSurveyViews($name, $view) } elseif (empty(self::$surveyId)) { // This situation can happen if we test only one data entry, // using --filter="testAdminSurveyViews#13" (for data entry 13). - $surveyFile = self::$surveysFolder . '/limesurvey_survey_454287.lss'; + $surveyFile = self::$surveysFolder . '/../data/surveys/limesurvey_survey_454287.lss'; self::importSurvey($surveyFile); } diff --git a/tests/acceptance/admin/CreateSurveyTest.php b/tests/controllers/CreateSurveyTest.php similarity index 95% rename from tests/acceptance/admin/CreateSurveyTest.php rename to tests/controllers/CreateSurveyTest.php index e48994c98d5..42122bfacce 100644 --- a/tests/acceptance/admin/CreateSurveyTest.php +++ b/tests/controllers/CreateSurveyTest.php @@ -1,17 +1,6 @@ session['loginID'] = 1; + // Browser login. self::adminLogin($username, $password); } /** - * + * */ public static function teardownAfterClass() { parent::tearDownAfterClass(); + // Delete survey. $criteria = new \CDbCriteria; $criteria->compare('correct_relation_defaultlanguage.surveyls_title', 'test survey 1', true, 'AND'); @@ -79,7 +71,9 @@ public function testCreateSurvey() $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); $url = $urlMan->createUrl('admin'); self::$webDriver->get($url); + sleep(1); + // Ignore welcome modal. try { $button = self::$webDriver->wait(1)->until( @@ -93,7 +87,9 @@ public function testCreateSurvey() } catch (TimeOutException $ex) { // Do nothing. } + sleep(1); + // Ignore password warning. try { $button = self::$webDriver->wait(1)->until( @@ -107,7 +103,10 @@ public function testCreateSurvey() } catch (NoSuchElementException $ex) { // Do nothing. } + + sleep(1); + // Click on big "Create survey" button. $link = self::$webDriver->wait(10)->until( WebDriverExpectedCondition::elementToBeClickable( @@ -115,20 +114,27 @@ public function testCreateSurvey() ) ); $link->click(); + // Fill in title. $title = self::$webDriver->findElement(WebDriverBy::id('surveyls_title')); $title->clear()->sendKeys('test survey 1'); + // Click save. $save = self::$webDriver->findElement(WebDriverBy::id('save-form-button')); $save->click(); + sleep(1); + // Remove notification. $save = self::$webDriver->findElement(WebDriverBy::cssSelector('button.close.limebutton')); $save->click(); + sleep(1); + // Go to structure sidebar $selectStructureSidebar = self::$webDriver->findElement(WebDriverBy::id('adminpanel__sidebar--selectorStructureButton')); $selectStructureSidebar->click(); + // Click "Add group". $addgroup = self::$webDriver->wait(10)->until( @@ -137,24 +143,31 @@ public function testCreateSurvey() ) ); $addgroup->click(); + // Fill in group title. $groupname = self::$webDriver->findElement(WebDriverBy::id('group_name_en')); $groupname->clear()->sendKeys('group1'); + sleep(1); + // Click save and add question. $save = self::$webDriver->findElement(WebDriverBy::id('save-and-new-question-button')); $save->click(); sleep(3); + // Add question title. $groupname = self::$webDriver->findElement(WebDriverBy::id('title')); $groupname->clear()->sendKeys('question1'); + // Click save. $save = self::$webDriver->findElement(WebDriverBy::id('save-button')); $save->click(); - sleep(1); + sleep(1); + $selectSettingsSidebar = self::$webDriver->findElement(WebDriverBy::id('adminpanel__sidebar--selectorSettingsButton')); $selectSettingsSidebar->click(); + // Click "Overview". $overview = self::$webDriver->wait(10)->until( WebDriverExpectedCondition::elementToBeClickable( @@ -162,17 +175,23 @@ public function testCreateSurvey() ) ); $overview->click(); + sleep(1); + // Click "Activate survey". $overview = self::$webDriver->findElement(WebDriverBy::id('ls-activate-survey')); $overview->click(); + // Confirm. $overview = self::$webDriver->findElement(WebDriverBy::id('activateSurvey__basicSettings--proceed')); $overview->click(); + // Click "Overview". $overview = self::$webDriver->findElement(WebDriverBy::id('sidemenu_1_1')); $overview->click(); + sleep(1); + // Click "Execute survey". $execute = self::$webDriver->wait(10)->until( WebDriverExpectedCondition::elementToBeClickable( @@ -180,16 +199,21 @@ public function testCreateSurvey() ) ); $execute->click(); + sleep(1); + // Switch to new tab. $windowHandles = self::$webDriver->getWindowHandles(); self::$webDriver->switchTo()->window( end($windowHandles) ); + sleep(1); + // New tab with active survey. $nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $nextButton->click(); + // Get questions. $dbo = \Yii::app()->getDb(); $query = 'SELECT sid FROM {{surveys}} ORDER BY datecreated DESC LIMIT 1'; @@ -206,14 +230,18 @@ public function testCreateSurvey() } $this->assertCount(1, $questions, 'We have exactly one question'); $this->assertTrue(isset($questions['question1']), json_encode(array_keys($questions))); + // Enter answer text. $sgqa = $sid . 'X' . $survey->groups[0]->gid . 'X' . $questions['question1']->qid; $question = self::$webDriver->findElement(WebDriverBy::id('answer' . $sgqa)); $question->sendKeys('foo bar'); + sleep(1); + // Click submit. $submitButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $submitButton->click(); + // Check so that we see end page. $completed = self::$webDriver->findElement(WebDriverBy::cssSelector('div.completed-text')); $this->assertEquals( @@ -221,6 +249,7 @@ public function testCreateSurvey() "Thank you!\nYour survey responses have been recorded.", 'I can see completed text' ); + // Check so that response is recorded in database. $query = sprintf( 'SELECT * FROM {{survey_%d}}', @@ -229,11 +258,13 @@ public function testCreateSurvey() $result = $dbo->createCommand($query)->queryAll(); $this->assertCount(1, $result, 'Exactly one response'); $this->assertEquals('foo bar', $result[0][$sgqa], '"foo bar" response'); + // Switch to first window. $windowHandles = self::$webDriver->getWindowHandles(); self::$webDriver->switchTo()->window( reset($windowHandles) ); + // Delete survey. $execute = self::$webDriver->wait(10)->until( WebDriverExpectedCondition::elementToBeClickable( @@ -253,11 +284,14 @@ public function testCreateSurvey() ) ); $execute->click(); + sleep(1); + // Make sure the survey can't be found. $query = 'SELECT sid FROM {{surveys}} WHERE sid = ' . $sid; $sids = $dbo->createCommand($query)->queryAll(); $this->assertCount(0, $sids); + } catch (NoSuchElementException $ex) { // TODO :Duplicated code. self::$testHelper->takeScreenshot(self::$webDriver, __CLASS__ . '_' . __FUNCTION__); @@ -291,4 +325,4 @@ public function testCreateSurvey() ); } } -} \ No newline at end of file +} diff --git a/tests/controllers/InstallationControllerTest.php b/tests/controllers/InstallationControllerTest.php index 452206d37ac..add9843f697 100644 --- a/tests/controllers/InstallationControllerTest.php +++ b/tests/controllers/InstallationControllerTest.php @@ -4,9 +4,6 @@ use Facebook\WebDriver\WebDriverBy; use Facebook\WebDriver\Exception\NoSuchElementException; -use LimeSurvey\tests\TestBaseClassWeb; -use LimeSurvey\tests\TestHelper; - /** * @since 2017-11-24 * @group inst @@ -14,7 +11,7 @@ class InstallationControllerTest extends TestBaseClassWeb { /** - * + * */ public static function setupBeforeClass() { @@ -114,7 +111,7 @@ public function testBasic() $dbuserInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbuser]"]')); $dbpwdInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbpwd]"]')); $dbnameInput = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="InstallerConfigForm[dbname]"]')); - + $dbuserDbType->click(); $dbuserInput->clear()->sendKeys($dbuser); $dbpwdInput->clear()->sendKeys($dbpwd); diff --git a/tests/acceptance/admin/questions/SaveDualScaleAnswerOptionsTest.php b/tests/controllers/SaveDualScaleAnswerOptionsTest.php similarity index 88% rename from tests/acceptance/admin/questions/SaveDualScaleAnswerOptionsTest.php rename to tests/controllers/SaveDualScaleAnswerOptionsTest.php index 654340d5138..6193b1cc952 100644 --- a/tests/acceptance/admin/questions/SaveDualScaleAnswerOptionsTest.php +++ b/tests/controllers/SaveDualScaleAnswerOptionsTest.php @@ -1,20 +1,8 @@ session['loginID'] = 1; + $username = getenv('ADMINUSERNAME'); if (!$username) { $username = 'admin'; } + $password = getenv('PASSWORD'); if (!$password) { $password = 'password'; } + // Permission to everything. \Yii::app()->session['loginID'] = 1; + // Browser login. self::adminLogin($username, $password); } + /** - * + * */ public function setup() { @@ -52,8 +46,9 @@ public function setup() $surveyFile = self::$surveysFolder . '/limesurvey_survey_677328.lss'; self::importSurvey($surveyFile); } + /** - * + * */ public function tearDown() { @@ -63,8 +58,9 @@ public function tearDown() self::$testSurvey = null; } } + /** - * + * */ public function testBasic() { @@ -73,6 +69,7 @@ public function testBasic() $this->assertNotEmpty($survey); $this->assertCount(1, $survey->groups, 'Wrong number of groups: ' . count($survey->groups)); $this->assertCount(1, $survey->groups[0]->questions, 'We have exactly one question'); + $urlMan = \Yii::app()->urlManager; $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); $url = $urlMan->createUrl( @@ -84,30 +81,39 @@ public function testBasic() 'qid' => $survey->groups[0]->questions[0]->qid ] ); + self::$webDriver->get($url); + $answer1 = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="answer_en_1_0"]')); $answer1->sendKeys('123'); + $answer2 = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="answer_en_1_1"]')); $answer2->sendKeys('abc'); + $savebutton = self::$webDriver->findElement(WebDriverBy::id('save-button')); $savebutton->click(); + $notif = self::$webDriver->findElement(WebDriverBy::id('notif-container')); $notifText = $notif->getText(); $this->assertContains('Answer options were successfully saved', $notifText); + $answers = \Answer::model()->findAllByAttributes(['qid' => $survey->groups[0]->questions[0]->qid]); $this->assertCount(2, $answers, 'Two answer options saved'); } + /** - * + * */ public function testUsingLinkToEditAnswers() { $surveyFile = self::$surveysFolder . '/limesurvey_survey_677328.lss'; self::importSurvey($surveyFile); + $survey = \Survey::model()->findByPk(self::$surveyId); $this->assertNotEmpty($survey); $this->assertCount(1, $survey->groups, 'Wrong number of groups: ' . count($survey->groups)); $this->assertCount(1, $survey->groups[0]->questions, 'We have exactly one question'); + $urlMan = \Yii::app()->urlManager; $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); $url = $urlMan->createUrl( @@ -119,20 +125,28 @@ public function testUsingLinkToEditAnswers() 'qid' => $survey->groups[0]->questions[0]->qid ] ); + self::$webDriver->get($url); + $button = self::$webDriver->findElement(WebDriverBy::linkText('Edit answer options')); $button->click(); + $answer1 = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="answer_en_1_0"]')); $answer1->sendKeys('123'); + $answer2 = self::$webDriver->findElement(WebDriverBy::cssSelector('input[name="answer_en_1_1"]')); $answer2->sendKeys('abc'); + sleep(1); + $savebutton = self::$webDriver->findElement(WebDriverBy::id('save-button')); $savebutton->click(); + $notif = self::$webDriver->findElement(WebDriverBy::id('notif-container')); $notifText = $notif->getText(); $this->assertContains('Answer options were successfully saved', $notifText); + $answers = \Answer::model()->findAllByAttributes(['qid' => $survey->groups[0]->questions[0]->qid]); $this->assertCount(2, $answers, 'Two answer options saved'); } -} \ No newline at end of file +} diff --git a/tests/acceptance/admin/TemplateControllerTest.php b/tests/controllers/TemplateControllerTest.php similarity index 73% rename from tests/acceptance/admin/TemplateControllerTest.php rename to tests/controllers/TemplateControllerTest.php index 55336203c4b..706e9ac3847 100644 --- a/tests/acceptance/admin/TemplateControllerTest.php +++ b/tests/controllers/TemplateControllerTest.php @@ -1,20 +1,8 @@ session['loginID'] = 1; \Yii::import('application.controllers.admin.themes', true); \Yii::import('application.helpers.globalsettings_helper', true); + // Clean up from last test. $templateName = 'foobartest'; \TemplateConfiguration::uninstall($templateName); \Template::model()->deleteAll('name = \'foobartest\''); \Permission::model()->deleteAllByAttributes(array('permission' => $templateName,'entity' => 'template')); + // Remove folder from last test. $newname = 'foobartest'; $newdirname = \Yii::app()->getConfig('userthemerootdir') . "/" . $newname; if (file_exists($newdirname)) { exec('rm -r ' . $newdirname); } + $config = require(\Yii::app()->getBasePath() . '/config/config-defaults.php'); // Simulate a POST. $_POST['newname'] = $newname; // NB: If default theme is not installed, this test will fail. $_POST['copydir'] = $config['defaulttheme']; $_SERVER['SERVER_NAME'] = 'localhost'; - $contr = new \themes(new DummyController('dummyid')); + + $contr = new \themes(new \ls\tests\DummyController('dummyid')); $contr->templatecopy(); + $flashes = \Yii::app()->user->getFlashes(); $this->assertEmpty($flashes, 'No flash messages'); + $template = \Template::model()->find( sprintf( 'name = \'%s\'', @@ -61,9 +56,11 @@ public function testCopyTemplate() ); $this->assertNotEmpty($template); $this->assertEquals($templateName, $template->name); + // Clean up. \Template::model()->deleteAll('name = \'foobartest\''); } + /** * @todo Copy template folder that does not exist. */ @@ -72,4 +69,4 @@ public function testCopyWrongFolder() { } */ -} \ No newline at end of file +} diff --git a/tests/resources/sql/create-mysql.153.sql b/tests/data/sql/create-mysql.153.sql similarity index 100% rename from tests/resources/sql/create-mysql.153.sql rename to tests/data/sql/create-mysql.153.sql diff --git a/tests/resources/sql/create-mysql.258.sql b/tests/data/sql/create-mysql.258.sql similarity index 100% rename from tests/resources/sql/create-mysql.258.sql rename to tests/data/sql/create-mysql.258.sql diff --git a/tests/resources/sql/create-mysql.315.sql b/tests/data/sql/create-mysql.315.sql similarity index 100% rename from tests/resources/sql/create-mysql.315.sql rename to tests/data/sql/create-mysql.315.sql diff --git a/tests/resources/surveys/limesurvey_survey_186734.lss b/tests/data/surveys/limesurvey_survey_186734.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_186734.lss rename to tests/data/surveys/limesurvey_survey_186734.lss diff --git a/tests/resources/surveys/limesurvey_survey_352985.lss b/tests/data/surveys/limesurvey_survey_352985.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_352985.lss rename to tests/data/surveys/limesurvey_survey_352985.lss diff --git a/tests/resources/surveys/limesurvey_survey_366446.lss b/tests/data/surveys/limesurvey_survey_366446.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_366446.lss rename to tests/data/surveys/limesurvey_survey_366446.lss diff --git a/tests/resources/surveys/limesurvey_survey_454287.lss b/tests/data/surveys/limesurvey_survey_454287.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_454287.lss rename to tests/data/surveys/limesurvey_survey_454287.lss diff --git a/tests/resources/surveys/limesurvey_survey_563168.lss b/tests/data/surveys/limesurvey_survey_563168.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_563168.lss rename to tests/data/surveys/limesurvey_survey_563168.lss diff --git a/tests/resources/surveys/limesurvey_survey_583999.lss b/tests/data/surveys/limesurvey_survey_583999.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_583999.lss rename to tests/data/surveys/limesurvey_survey_583999.lss diff --git a/tests/resources/surveys/limesurvey_survey_677328.lss b/tests/data/surveys/limesurvey_survey_677328.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_677328.lss rename to tests/data/surveys/limesurvey_survey_677328.lss diff --git a/tests/resources/surveys/limesurvey_survey_834477.lss b/tests/data/surveys/limesurvey_survey_834477.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_834477.lss rename to tests/data/surveys/limesurvey_survey_834477.lss diff --git a/tests/resources/surveys/limesurvey_survey_88881.lss b/tests/data/surveys/limesurvey_survey_88881.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_88881.lss rename to tests/data/surveys/limesurvey_survey_88881.lss diff --git a/tests/resources/surveys/limesurvey_survey_917744.lss b/tests/data/surveys/limesurvey_survey_917744.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_917744.lss rename to tests/data/surveys/limesurvey_survey_917744.lss diff --git a/tests/resources/surveys/limesurvey_survey_975622.lss b/tests/data/surveys/limesurvey_survey_975622.lss similarity index 100% rename from tests/resources/surveys/limesurvey_survey_975622.lss rename to tests/data/surveys/limesurvey_survey_975622.lss diff --git a/tests/resources/travis/travis-ci-apache b/tests/data/travis/travis-ci-apache similarity index 100% rename from tests/resources/travis/travis-ci-apache rename to tests/data/travis/travis-ci-apache diff --git a/tests/resources/travis/travis_setup.sh b/tests/data/travis/travis_setup.sh similarity index 100% rename from tests/resources/travis/travis_setup.sh rename to tests/data/travis/travis_setup.sh diff --git a/tests/resources/views/adminBaseViews.php b/tests/data/views/adminBaseViews.php similarity index 100% rename from tests/resources/views/adminBaseViews.php rename to tests/data/views/adminBaseViews.php diff --git a/tests/resources/views/adminGeneralSettingsViews.php b/tests/data/views/adminGeneralSettingsViews.php similarity index 100% rename from tests/resources/views/adminGeneralSettingsViews.php rename to tests/data/views/adminGeneralSettingsViews.php diff --git a/tests/resources/views/adminParticipantsViews.php b/tests/data/views/adminParticipantsViews.php similarity index 100% rename from tests/resources/views/adminParticipantsViews.php rename to tests/data/views/adminParticipantsViews.php diff --git a/tests/resources/views/adminSettingsViews.php b/tests/data/views/adminSettingsViews.php similarity index 100% rename from tests/resources/views/adminSettingsViews.php rename to tests/data/views/adminSettingsViews.php diff --git a/tests/resources/views/adminSurveyViews.php b/tests/data/views/adminSurveyViews.php similarity index 100% rename from tests/resources/views/adminSurveyViews.php rename to tests/data/views/adminSurveyViews.php diff --git a/tests/resources/views/adminUsersViews.php b/tests/data/views/adminUsersViews.php similarity index 100% rename from tests/resources/views/adminUsersViews.php rename to tests/data/views/adminUsersViews.php diff --git a/tests/functional/README.md b/tests/functional/README.md deleted file mode 100644 index 0b7c3d8a36a..00000000000 --- a/tests/functional/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Functional tests - -from: -https://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test - ->Functional tests check a particular feature for correctness by comparing the results for a given input against the specification. Functional tests don't concern themselves with intermediate results or side-effects, just the result (they don't care that after doing x, object y has state z). They are written to test part of the specification such as, "calling function Square(x) with the argument of 2 returns 4". diff --git a/tests/functional/helpers/CheckDatabaseJsonValuesTest.php b/tests/helpers/CheckDatabaseJsonValuesTest.php similarity index 97% rename from tests/functional/helpers/CheckDatabaseJsonValuesTest.php rename to tests/helpers/CheckDatabaseJsonValuesTest.php index 10161178361..56d1e7b94ec 100644 --- a/tests/functional/helpers/CheckDatabaseJsonValuesTest.php +++ b/tests/helpers/CheckDatabaseJsonValuesTest.php @@ -1,8 +1,6 @@ teardownDatabase('__test_update_helper_258'); self::$testHelper->teardownDatabase('__test_update_helper_315'); } + /** * * @throws \CException @@ -34,10 +34,12 @@ public static function teardownAfterClass() public function testCreate() { $db = \Yii::app()->getDb(); + $config = require(\Yii::app()->getBasePath() . '/config/config.php'); $version = require(\Yii::app()->getBasePath() . '/config/version.php'); $connection = self::$testHelper->connectToNewDatabase('__test_check_database_json'); $this->assertNotEmpty($connection, 'Could connect to new database'); + // Get InstallerController. $inst = new \InstallerController('foobar'); $inst->connection = \Yii::app()->db; @@ -46,45 +48,55 @@ public function testCreate() if ($result) { print_r($result); } + // Run upgrade. $result = \db_upgrade_all($version['dbversionnumber']); + // Check JSON. $this->checkMenuEntriesJson($inst->connection); $this->checkTemplateConfigurationJson($inst->connection); + // Connect to old database. $db->setActive(false); \Yii::app()->setComponent('db', $config['components']['db'], false); $db->setActive(true); } + /** - * + * */ public function testUpdateFrom258() { $connection = self::$testHelper->updateDbFromVersion(258); + // Check JSON. $this->checkMenuEntriesJson($connection); $this->checkTemplateConfigurationJson($connection); + $db = \Yii::app()->getDb(); $db->setActive(false); $config = require(\Yii::app()->getBasePath() . '/config/config.php'); \Yii::app()->setComponent('db', $config['components']['db'], false); $db->setActive(true); } + /** */ public function testUpdateFrom315() { $connection = self::$testHelper->updateDbFromVersion(315); + // Check JSON. $this->checkMenuEntriesJson($connection); $this->checkTemplateConfigurationJson($connection); + $db = \Yii::app()->getDb(); $db->setActive(false); $config = require(\Yii::app()->getBasePath() . '/config/config.php'); \Yii::app()->setComponent('db', $config['components']['db'], false); $db->setActive(true); } + /** * @param \CDbConnection $connection * @return void @@ -102,6 +114,7 @@ protected function checkMenuEntriesJson(\CDbConnection $connection) } } } + /** * @param \CDbConnection $connection * @return void @@ -131,7 +144,8 @@ protected function checkTemplateConfigurationJson(\CDbConnection $connection) } else { // Nothing to check. } + } } } -} \ No newline at end of file +} diff --git a/tests/functional/helpers/ExpressionCoreAux.php b/tests/helpers/ExpressionCoreAux.php similarity index 97% rename from tests/functional/helpers/ExpressionCoreAux.php rename to tests/helpers/ExpressionCoreAux.php index 5b6c1658f70..3c10954cea0 100644 --- a/tests/functional/helpers/ExpressionCoreAux.php +++ b/tests/helpers/ExpressionCoreAux.php @@ -1,5 +1,6 @@ . * @mixed */ public $value; + /** * Question alias. * @var string */ public $alias = 'test'; + /** * @param string $expression * @param string $sgqa @@ -55,6 +63,7 @@ public function __construct($expression, $sgqa, $questionType, $value) $this->questionType = $questionType; $this->value = $value; } + /** * @return void */ @@ -62,6 +71,7 @@ public function compareExpression() { // Input value 3. $_SESSION['survey_563168'][$this->sgqa] = $this->value; + $em = new \ExpressionManager(); $lem = \LimeExpressionManager::singleton(); $lem->setVariableAndTokenMappingsForExpressionManager('563168'); @@ -74,16 +84,23 @@ public function compareExpression() ] ] ); + $em->RDP_Evaluate($this->expression); + $emResult = $em->GetResult(); + if ($this->jsonEncodeEmResult) { $emResult = json_encode($emResult); } + $errors = $em->RDP_GetErrors(); $this->assertEmpty($errors, print_r($errors, true)); $jsOfExpression = $em->GetJavaScriptEquivalentOfExpression(); + $js = $this->getDummyNodeSetup() . $jsOfExpression; + $nodeOutput = $this->runNode($js); + $this->assertCount(1, $nodeOutput); $this->assertEquals( $emResult, @@ -98,8 +115,13 @@ public function compareExpression() ); } + /** * JS code to setup environment so LEMval() can run. + * @param string $sgqa + * @param mixed $value + * @param string $alias + * @param int $onlynum * @return string */ public function getDummyNodeSetup() @@ -109,6 +131,7 @@ public function getDummyNodeSetup() } else { $value = $this->value; } + list($surveyId, $groupId, /* questionId */) = explode('X', $this->sgqa, 3); return << 2, 2 => 'NUMBER' ]; + $dqString = [ 0 => ' ', 1 => 26, 2 => 'DQ_STRING' ]; + $em->RDP_StackPush($number); $em->RDP_StackPush($dqString); + $compare = [ 0 => '>=', 1 => 23, @@ -78,12 +84,15 @@ public function notes() ]; $noErrors = $em->RDP_EvaluateBinary($compare); $this->assertTrue($noErrors); + $result = $em->RDP_StackPop(); + $em->RDP_StackPush($number); $em->RDP_StackPush($dqString); $em->RDP_StackPush($compare); $em->SetJsVarsUsed([]); */ + /* $pageInfo = [ 'qid' => '5377', @@ -100,6 +109,7 @@ public function notes() ]; */ } + /** * @group me */ @@ -115,6 +125,7 @@ public function testNumericalQuestion() $test->compareExpression(); } } + /** * @group me2 */ @@ -129,4 +140,4 @@ public function testShortTextQuestion() $test->compareExpression(); } } -} \ No newline at end of file +} diff --git a/tests/acceptance/surveys/GroupRandomizationTest.php b/tests/helpers/GroupRandomizationTest.php similarity index 83% rename from tests/acceptance/surveys/GroupRandomizationTest.php rename to tests/helpers/GroupRandomizationTest.php index dc1b574afbe..fe9ba91d363 100644 --- a/tests/acceptance/surveys/GroupRandomizationTest.php +++ b/tests/helpers/GroupRandomizationTest.php @@ -1,21 +1,9 @@ connectToOriginalDatabase(); + \Yii::app()->session['loginID'] = 1; - $surveyFile = self::getSurveysFolder().'/limesurvey_survey_88881.lss'; + + $surveyFile = __DIR__ . '/../data/surveys/limesurvey_survey_88881.lss'; if (!file_exists($surveyFile)) { echo 'Fatal error: found no survey file'; exit(4); } + $translateLinksFields = false; $newSurveyName = null; try { @@ -54,6 +47,7 @@ public static function setupBeforeClass() 'Could not import survey limesurvey_survey_88881.lss: ' . $ex->getMessage() ); } + if ($result) { self::$surveyId = $result['newsid']; } else { @@ -61,6 +55,7 @@ public static function setupBeforeClass() exit(5); } } + /** * Selenium setup. */ @@ -71,11 +66,13 @@ public function setUp() echo 'Must specify DOMAIN environment variable to run this test, like "DOMAIN=localhost/limesurvey" or "DOMAIN=limesurvey.localhost".'; exit(6); } + //$capabilities = DesiredCapabilities::phantomjs(); //$this->webDriver = RemoteWebDriver::create('http://localhost:4444/', $capabilities); } + /** - * + * */ public static function teardownAfterClass() { @@ -85,6 +82,7 @@ public static function teardownAfterClass() exit(8); } } + /** * Tear down fixture. */ @@ -93,16 +91,20 @@ public function tearDown() // Close Firefox. self::$webDriver->quit(); } + + /** - * + * */ public function testRunSurvey() { self::$testHelper->activateSurvey(self::$surveyId); + $domain = getenv('DOMAIN'); if (empty($domain)) { $domain = ''; } + $urlMan = \Yii::app()->urlManager; $urlMan->setBaseUrl('http://' . $domain . '/index.php'); $url = $urlMan->createUrl( @@ -113,6 +115,7 @@ public function testRunSurvey() 'lang' => 'pt' ) ); + self::$webDriver->get($url); $submit = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $this->assertNotEmpty($submit); @@ -120,13 +123,17 @@ public function testRunSurvey() WebDriverExpectedCondition::visibilityOf($submit) ); $submit->click(); + $body = self::$webDriver->findElement(WebDriverBy::tagName('body')); $text = $body->getText(); + // There should be no PHP notice. $this->assertTrue(strpos($text, 'PHP notice') === false, $text); + // NB: This is how to take a screenshot, if necessary. //$screenshot = self::$webDriver->takeScreenshot(); //file_put_contents(__DIR__ . '/screenshot.png', $screenshot); + self::$testHelper->deactivateSurvey(self::$surveyId); } -} \ No newline at end of file +} diff --git a/tests/functional/helpers/UpdateDbHelperTest.php b/tests/helpers/UpdateDbHelperTest.php similarity index 99% rename from tests/functional/helpers/UpdateDbHelperTest.php rename to tests/helpers/UpdateDbHelperTest.php index 6cc8f0e2834..3f6b6962f82 100644 --- a/tests/functional/helpers/UpdateDbHelperTest.php +++ b/tests/helpers/UpdateDbHelperTest.php @@ -1,7 +1,6 @@ teardownDatabase('__test_install_script'); self::$testHelper->teardownDatabase('__test_install_script_compare'); } + /** * Run the database PHP install script. * @group install @@ -28,9 +28,11 @@ public static function teardownAfterClass() public function testInstallPhp() { $db = \Yii::app()->getDb(); + $config = require(\Yii::app()->getBasePath() . '/config/config.php'); $connection = self::$testHelper->connectToNewDatabase('__test_install_script'); $this->assertNotEmpty($connection, 'Could connect to new database'); + // Get InstallerController. $inst = new \InstallerController('foobar'); $inst->connection = \Yii::app()->db; @@ -39,6 +41,7 @@ public function testInstallPhp() if ($result) { print_r($result); } + // Dump database to file. /* $output = array(); @@ -53,11 +56,13 @@ public function testInstallPhp() $this->assertEmpty($output, 'No output from mysqldump'); $this->assertEmpty($result, 'No last line output from mysqldump'); */ + // Connect to old database. $db->setActive(false); \Yii::app()->setComponent('db', $config['components']['db'], false); $db->setActive(true); } + /** * Run db_upgrade_all() from dbversion 258, to make sure * there are no conflicts or syntax errors. @@ -67,8 +72,10 @@ public function testInstallPhp() public function testDbUpgradeFrom258() { self::$testHelper->updateDbFromVersion(258); + $db = \Yii::app()->getDb(); $config = require(\Yii::app()->getBasePath() . '/config/config.php'); + // Dump database to file. /* $output = array(); @@ -83,11 +90,14 @@ public function testDbUpgradeFrom258() $this->assertEmpty($output, 'No output from mysqldump'); $this->assertEmpty($result, 'No last line output from mysqldump'); */ + // Connect to old database. \Yii::app()->setComponent('db', $config['components']['db'], false); $db->setActive(true); + // Database is deleted in teardownAfterClass(). } + /** * @group from315 * @throws \CException @@ -95,12 +105,15 @@ public function testDbUpgradeFrom258() public function testDbUpgradeFrom315() { self::$testHelper->updateDbFromVersion(315); + $db = \Yii::app()->getDb(); $config = require(\Yii::app()->getBasePath() . '/config/config.php'); + // Connect to old database. \Yii::app()->setComponent('db', $config['components']['db'], false); $db->setActive(true); } + /** * Compare database between upgrade and fresh install. * @group dbcompare @@ -111,10 +124,12 @@ public function testCompareUpgradeAndFreshInstall() $connection = self::$testHelper->updateDbFromVersion(258); $upgradeTables = $connection->schema->getTables(); $this->compareAux($upgradeTables, 258); + $connection = self::$testHelper->updateDbFromVersion(315); $upgradeTables = $connection->schema->getTables(); $this->compareAux($upgradeTables, 315); } + /** * @param array $upgradeTables * @return void @@ -123,7 +138,9 @@ public function testCompareUpgradeAndFreshInstall() protected function compareAux(array $upgradeTables, $upgradedFrom) { $config = require(\Yii::app()->getBasePath() . '/config/config.php'); + $dbo = \Yii::app()->getDb(); + /* $config = require(\Yii::app()->getBasePath() . '/config/config.php'); // Get database name. @@ -143,12 +160,15 @@ protected function compareAux(array $upgradeTables, $upgradedFrom) ); $connection->active = true; */ + \Yii::app()->cache->flush(); + self::$testHelper->teardownDatabase('__test_install_script_compare'); $connection = self::$testHelper->connectToNewDatabase('__test_install_script_compare'); $this->assertNotEmpty($connection, 'Could not connect to new database: ' . json_encode($connection)); $connection->schemaCachingDuration = 0; // Deactivate schema caching $connection->schema->refresh(); + // Get InstallerController. $db = \Yii::app()->getDb(); $inst = new \InstallerController('foobar'); @@ -167,8 +187,10 @@ protected function compareAux(array $upgradeTables, $upgradedFrom) } $inst->connection->schema->refresh(); $freshInstallTables = $inst->connection->schema->getTables(); + $this->assertEquals(count($upgradeTables), count($freshInstallTables), 'Same number of tables'); $this->assertEquals(array_keys($upgradeTables), array_keys($freshInstallTables), 'Same number of tables'); + // Loop tables. $upgradeKeys = array_keys($upgradeTables); $freshInstallKeys = array_keys($freshInstallTables); @@ -176,8 +198,10 @@ protected function compareAux(array $upgradeTables, $upgradedFrom) $this->assertEquals($upgradeKeys[$i], $freshInstallKeys[$i]); $upgradeTable = $upgradeTables[$upgradeKeys[$i]]; $freshTable = $freshInstallTables[$freshInstallKeys[$i]]; + $upgradeColumns = $upgradeTable->columns; $freshColumns = $freshTable->columns; + // Loop columns. foreach ($upgradeColumns as $columnName => $upgradeColumn) { $upgradeColumn = (array) $upgradeColumn; @@ -201,6 +225,7 @@ protected function compareAux(array $upgradeTables, $upgradedFrom) } } } + /* Code to dump diff, but nearly useless due to collate difference. $output = array(); exec( @@ -214,9 +239,10 @@ protected function compareAux(array $upgradeTables, $upgradedFrom) $output ); */ + // Connect to old database. $dbo->setActive(false); \Yii::app()->setComponent('db', $config['components']['db'], false); $dbo->setActive(true); } -} \ No newline at end of file +} diff --git a/tests/acceptance/admin/TemplateConfigurationTest.php b/tests/models/TemplateConfigurationTest.php similarity index 86% rename from tests/acceptance/admin/TemplateConfigurationTest.php rename to tests/models/TemplateConfigurationTest.php index b2d33e0b094..f744b8f756f 100644 --- a/tests/acceptance/admin/TemplateConfigurationTest.php +++ b/tests/models/TemplateConfigurationTest.php @@ -1,7 +1,6 @@ prepareTemplateRendering('default'); + // No PHP notices. $this->assertTrue(true); } -} \ No newline at end of file +} diff --git a/tests/acceptance/questions/DateTimeDefaultAnswerExpressionTest.php b/tests/questions/DateTimeDefaultAnswerExpressionTest.php similarity index 89% rename from tests/acceptance/questions/DateTimeDefaultAnswerExpressionTest.php rename to tests/questions/DateTimeDefaultAnswerExpressionTest.php index 080a943ba08..ff55851fc17 100644 --- a/tests/acceptance/questions/DateTimeDefaultAnswerExpressionTest.php +++ b/tests/questions/DateTimeDefaultAnswerExpressionTest.php @@ -1,22 +1,6 @@ getSgqa('G1Q00005', self::$surveyId); + $surveyOptions = self::$testHelper->getSurveyOptions(self::$surveyId); + \Yii::app()->setConfig('surveyID', self::$surveyId); \Yii::app()->setController(new DummyController('dummyid')); buildsurveysession(self::$surveyId); @@ -61,15 +50,19 @@ public function testDefaultAnswerExpressionFill() ], $result ); + // Qanda needs this. $_SESSION['survey_' . self::$surveyId]['maxstep'] = 2; $_SESSION['survey_' . self::$surveyId]['step'] = 1; + // Move one step to run expressions. $moveResult = \LimeExpressionManager::NavigateForwards(); + // Check result from qanda. $qanda = \retrieveAnswers( $_SESSION['survey_' . self::$surveyId]['fieldarray'][0] ); + $correctDate = date('d/m/Y'); $this->assertNotEquals( false, @@ -82,7 +75,9 @@ public function testDefaultAnswerExpressionFill() ), 'Showing todays date' ); + } + /** * Test full default answer expression, * date('Y-m-d H:i'). @@ -93,8 +88,11 @@ public function testCorrectDefaultAnswerExpression() global $thissurvey; $thissurvey = self::$surveyId; $survey = \Survey::model()->findByPk(self::$surveyId); + list($question, $group, $sgqa) = self::$testHelper->getSgqa('q2', self::$surveyId); + $surveyOptions = self::$testHelper->getSurveyOptions(self::$surveyId); + \Yii::app()->setConfig('surveyID', self::$surveyId); \Yii::app()->setController(new DummyController('dummyid')); buildsurveysession(self::$surveyId); @@ -114,16 +112,21 @@ public function testCorrectDefaultAnswerExpression() ], $result ); + // Qanda needs this. $_SESSION['survey_' . self::$surveyId]['maxstep'] = 2; $_SESSION['survey_' . self::$surveyId]['step'] = 1; + // Move one step to run expressions. $moveResult = \LimeExpressionManager::NavigateForwards(); + // Check result from qanda. $qanda = \retrieveAnswers( $_SESSION['survey_' . self::$surveyId]['fieldarray'][1] // 1 = second question (q2) ); + $correctDate = date('d/m/Y'); + $this->assertNotEquals( false, strpos( @@ -136,6 +139,7 @@ public function testCorrectDefaultAnswerExpression() 'Showing todays date' ); } + /** * Test default answer, date format HH:MM, expression * date('HH:ii'). Return empty value. @@ -144,8 +148,11 @@ public function testWrongDefaultAnswerExpression() { global $thissurvey; $thissurvey = self::$surveyId; + list($question, $group, $sgqa) = self::$testHelper->getSgqa('q3', self::$surveyId); + $surveyOptions = self::$testHelper->getSurveyOptions(self::$surveyId); + \Yii::app()->setConfig('surveyID', self::$surveyId); \Yii::app()->setController(new DummyController('dummyid')); buildsurveysession(self::$surveyId); @@ -165,23 +172,28 @@ public function testWrongDefaultAnswerExpression() ], $result ); + // Qanda needs this. $_SESSION['survey_' . self::$surveyId]['maxstep'] = 2; $_SESSION['survey_' . self::$surveyId]['step'] = 1; + // Move one step to run expressions. $moveResult = \LimeExpressionManager::NavigateForwards(); + // Check result from qanda. $qanda = \retrieveAnswers( $_SESSION['survey_' . self::$surveyId]['fieldarray'][2] // 2 = third question (q3) ); + // NB: Empty value, since default answer expression is not parsed by qanda. $this->assertNotEquals( false, strpos($qanda[0][1], "value=\"\""), 'Showing empty date due to wrong expression' ); + // NB: Value below is todays time in format H:i, which can't be // parsed by qanda (expects Y-m-d H:i). //print_r($_SESSION['survey_' . self::$surveyId][$sgqa]); } -} \ No newline at end of file +} diff --git a/tests/acceptance/questions/DateTimeForwardBackTest.php b/tests/questions/DateTimeForwardBackTest.php similarity index 82% rename from tests/acceptance/questions/DateTimeForwardBackTest.php rename to tests/questions/DateTimeForwardBackTest.php index f33fe2b94b2..2dd2b1c5974 100644 --- a/tests/acceptance/questions/DateTimeForwardBackTest.php +++ b/tests/questions/DateTimeForwardBackTest.php @@ -1,21 +1,6 @@ getSgqa('G1Q00001', self::$surveyId); $surveyMode = 'group'; $LEMdebugLevel = 0; + self::$testHelper->activateSurvey(self::$surveyId); + // Must fetch this AFTER survey is activated. $surveyOptions = self::$testHelper->getSurveyOptions(self::$surveyId); + \Yii::app()->setConfig('surveyID', self::$surveyId); \Yii::app()->setController(new DummyController('dummyid')); \buildsurveysession(self::$surveyId); @@ -64,6 +55,7 @@ public function testQ1() ], $result ); + $qid = $question->qid; $gseq = 0; $_POST['relevance' . $qid] = 1; @@ -75,22 +67,27 @@ public function testQ1() $_POST[$sgqa] = '10:00'; $_SESSION['survey_' . self::$surveyId]['maxstep'] = 2; $_SESSION['survey_' . self::$surveyId]['step'] = 1; + $moveResult = \LimeExpressionManager::NavigateForwards(); $result = \LimeExpressionManager::ProcessCurrentResponses(); $this->assertEquals($result[$sgqa]['value'], '1970-01-01 10:00'); + $moveResult = \LimeExpressionManager::NavigateForwards(); // Result is empty dummy text question. \LimeExpressionManager::ProcessCurrentResponses(); + // Check answer in database. $query = 'SELECT * FROM {{survey_' . self::$surveyId . '}}'; $result = \Yii::app()->db->createCommand($query)->queryAll(); $this->assertEquals($result[0][$sgqa], '1970-01-01 10:00:00', 'Answer in database is 10:00'); + // Check result from qanda. $qanda = \retrieveAnswers( $_SESSION['survey_' . self::$surveyId]['fieldarray'][0] ); $this->assertEquals(false, strpos($qanda[0][1], "value=\"11:00\""), 'No 11:00 value from qanda'); $this->assertNotEquals(false, strpos($qanda[0][1], "value=\"10:00\""), 'One 10:00 value from qanda'); + self::$testHelper->deactivateSurvey(self::$surveyId); } -} \ No newline at end of file +} diff --git a/tests/acceptance/questions/DateTimeTest.php b/tests/questions/DateTimeTest.php similarity index 68% rename from tests/acceptance/questions/DateTimeTest.php rename to tests/questions/DateTimeTest.php index 5eb7e7cccf0..93d99553154 100644 --- a/tests/acceptance/questions/DateTimeTest.php +++ b/tests/questions/DateTimeTest.php @@ -1,20 +1,7 @@ qid => array - ( - 'info' => array ( - 'relevance' => '1', - 'grelevance' => '', - 'qid' => $question->qid, - 'qseq' => 1, - 'gseq' => 0, - 'jsResultVar_on' => 'answer' . $sgqa, - 'jsResultVar' => 'java' . $sgqa, - 'type' => 'D', + 'info' => array + ( + 'relevance' => '1', + 'grelevance' => '', + 'qid' => $question->qid, + 'qseq' => 1, + 'gseq' => 0, + 'jsResultVar_on' => 'answer' . $sgqa, + 'jsResultVar' => 'java' . $sgqa, + 'type' => 'D', + 'hidden' => false, + 'gid' => $group->gid, + 'mandatory' => 'N', + 'eqn' => '', + 'help' => '', + 'qtext' => '', + 'code' => 'q2', + 'other' => 'N', + 'default' => null, + 'rootVarName' => 'q2', + 'rowdivid' => '', + 'aid' => '', + 'sqid' => '', + ), + 'relevant' => true, 'hidden' => false, - 'gid' => $group->gid, - 'mandatory' => 'N', - 'eqn' => '', - 'help' => '', - 'qtext' => '', - 'code' => 'q2', - 'other' => 'N', - 'default' => null, - 'rootVarName' => 'q2', - 'rowdivid' => '', - 'aid' => '', - 'sqid' => '', - ), - 'relevant' => true, - 'hidden' => false, - 'relEqn' => '', - 'sgqa' => $sgqa, - 'unansweredSQs' => $sgqa, - 'valid' => true, - 'validEqn' => '', - 'prettyValidEqn' => '', - 'validTip' => '', - 'prettyValidTip' => '', - 'validJS' => '', - 'invalidSQs' => '', - 'relevantSQs' => $sgqa, - 'irrelevantSQs' => '', - 'subQrelEqn' => '', - 'mandViolation' => false, - 'anyUnanswered' => true, - 'mandTip' => '', - 'message' => '', - 'updatedValues' => array(), - 'sumEqn' => '', - 'sumRemainingEqn' => '' - ) + 'relEqn' => '', + 'sgqa' => $sgqa, + 'unansweredSQs' => $sgqa, + 'valid' => true, + 'validEqn' => '', + 'prettyValidEqn' => '', + 'validTip' => '', + 'prettyValidTip' => '', + 'validJS' => '', + 'invalidSQs' => '', + 'relevantSQs' => $sgqa, + 'irrelevantSQs' => '', + 'subQrelEqn' => '', + 'mandViolation' => false, + 'anyUnanswered' => true, + 'mandTip' => '', + 'message' => '', + 'updatedValues' => array(), + 'sumEqn' => '', + 'sumRemainingEqn' => '' + ) ); return $qset; } + /** * Test wrong date input and error message. * @group datewronginput @@ -98,10 +91,14 @@ public function testWrongInput() { $contr = new DummyController('dummyid'); \Yii::app()->setController($contr); + list($question, $group, $sgqa) = self::$testHelper->getSgqa('q2', self::$surveyId); + $qset = $this->getQuestionSetForQ2($question, $group, $sgqa); + $em = \LimeExpressionManager::singleton(); $em->setCurrentQset($qset); + $surveyMode = 'group'; $LEMdebugLevel = 0; $surveyOptions = self::$testHelper->getSurveyOptions(self::$surveyId); @@ -112,31 +109,40 @@ public function testWrongInput() false, $LEMdebugLevel ); + $qid = $question->qid; $gseq = 0; $_POST['relevance' . $qid] = 1; $_POST['relevanceG' . $gseq] = 1; $_POST[$sgqa] = 'asd'; + $result = \LimeExpressionManager::ProcessCurrentResponses(); $this->assertNotEmpty($result); $this->assertEquals(1, count($result), 'One question from ProcessCurrentResponses'); $this->assertEquals('INVALID', $result[$sgqa]['value']); + $originalPrefix = \Yii::app()->user->getStateKeyPrefix(); \Yii::app()->user->setStateKeyPrefix('frontend' . self::$surveyId); $flashes = \Yii::app()->user->getFlashes(); + $this->assertNotEmpty($flashes); $this->assertEquals(1, count($flashes), 'One error message'); + \Yii::app()->user->setStateKeyPrefix($originalPrefix); } + /** * Test correct date. */ public function testCorrectDateFormat() { list($question, $group, $sgqa) = self::$testHelper->getSgqa('q2', self::$surveyId); + $qset = $this->getQuestionSetForQ2($question, $group, $sgqa); + $em = \LimeExpressionManager::singleton(); $em->setCurrentQset($qset); + $surveyMode = 'group'; $LEMdebugLevel = 0; $surveyOptions = self::$testHelper->getSurveyOptions(self::$surveyId); @@ -147,21 +153,27 @@ public function testCorrectDateFormat() false, $LEMdebugLevel ); + $qid = $question->qid; $gseq = 0; $_POST['relevance' . $qid] = 1; $_POST['relevanceG' . $gseq] = 1; $_POST[$sgqa] = '23/12/2016'; + $result = \LimeExpressionManager::ProcessCurrentResponses(); $this->assertNotEmpty($result); $this->assertEquals(1, count($result), 'One question from ProcessCurrentResponses'); $this->assertEquals('2016-12-23 00:00', $result[$sgqa]['value']); + $originalPrefix = \Yii::app()->user->getStateKeyPrefix(); \Yii::app()->user->setStateKeyPrefix('frontend' . self::$surveyId); $flashes = \Yii::app()->user->getFlashes(); + $this->assertEmpty($flashes, 'No error message'); + \Yii::app()->user->setStateKeyPrefix($originalPrefix); } + /** * q1 is hidden question with default answer "now". */ @@ -186,4 +198,4 @@ public function testQ1() $result = \LimeExpressionManager::ProcessCurrentResponses(); $this->assertEquals(date('Y-m-d'), $_SESSION['survey_' . self::$surveyId][$sgqa]); } -} \ No newline at end of file +} diff --git a/tests/acceptance/questions/DateTimeValidationTest.php b/tests/questions/DateTimeValidationTest.php similarity index 77% rename from tests/acceptance/questions/DateTimeValidationTest.php rename to tests/questions/DateTimeValidationTest.php index 3606ddb2bda..3bcba3534f8 100644 --- a/tests/acceptance/questions/DateTimeValidationTest.php +++ b/tests/questions/DateTimeValidationTest.php @@ -1,24 +1,11 @@ enablePreview(); } + /** - * + * */ public function testBasic() { @@ -51,7 +40,9 @@ public function testBasic() 'lang' => 'pt' ] ); + self::$webDriver->get($url); + try { $submit = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); } catch (NoSuchElementException $ex) { @@ -64,13 +55,15 @@ public function testBasic() 'Screenshot in ' . $filename . PHP_EOL . $ex->getMessage() ); } + $this->assertNotEmpty($submit); self::$webDriver->wait(5)->until( WebDriverExpectedCondition::elementToBeClickable( - WebDriverBy::id('ls-button-submit') - ) + WebDriverBy::id('ls-button-submit') + ) ); $submit->click(); + // After submit we should see the complete page. try { // Wait max 10 second to find this div. @@ -92,14 +85,14 @@ public function testBasic() ); } catch (TimeOutException $ex) { $body = self::$webDriver->findElement(WebDriverBy::tagName('body')); - var_dump($body->getText()); - $reflect = new \ReflectionClass($this); - //if ($reflect->getShortName() === 'Name') { + var_dump($body->getText()); + $reflect = new \ReflectionClass($this); + //if ($reflect->getShortName() === 'Name') { self::$testHelper->takeScreenshot(self::$webDriver, $reflect->getShortName() . '_' . __FUNCTION__); $this->assertFalse( true, self::$testHelper->javaTrace($ex) ); - } + } } -} \ No newline at end of file +} diff --git a/tests/acceptance/questions/MultipleChoiceNextPreviousTest.php b/tests/questions/MultipleChoiceNextPreviousTest.php similarity index 82% rename from tests/acceptance/questions/MultipleChoiceNextPreviousTest.php rename to tests/questions/MultipleChoiceNextPreviousTest.php index b65e9a5ed1d..c140266c718 100644 --- a/tests/acceptance/questions/MultipleChoiceNextPreviousTest.php +++ b/tests/questions/MultipleChoiceNextPreviousTest.php @@ -1,21 +1,9 @@ urlManager; $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); @@ -49,6 +39,7 @@ public function testNextPrevious() 'lang' => 'pt' ] ); + // Get questions. $survey = \Survey::model()->findByPk(self::$surveyId); $questionObjects = $survey->groups[0]->questions; @@ -56,29 +47,38 @@ public function testNextPrevious() foreach ($questionObjects as $q) { $questions[$q->title] = $q; } + try { + self::$webDriver->get($url); + // Click first checkbox. $lis = self::$webDriver->findElements(WebDriverBy::cssSelector('li label')); $this->assertCount(3, $lis); $lis[0]->click(); + // Click next. $submit = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $submit->click(); + // Click previous.. $prev = self::$webDriver->findElement(WebDriverBy::id('ls-button-previous')); $prev->click(); sleep(1); // TODO: Does not work without this. + // Click next. $submit = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $submit->click(); + // Click previous.. $prev = self::$webDriver->findElement(WebDriverBy::id('ls-button-previous')); $prev->click(); + // Check value of checkbox. $sgqa = self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['q2']->qid; $checkbox = self::$webDriver->findElement(WebDriverBy::id('java' . $sgqa . 'SQ001')); $this->assertEquals('Y', $checkbox->getAttribute('value')); + } catch (NoSuchElementException $ex) { $screenshot = self::$webDriver->takeScreenshot(); $filename = self::$screenshotsFolder.'/MultipleChoiceNextPreviousTest.png'; @@ -90,4 +90,4 @@ public function testNextPrevious() ); } } -} \ No newline at end of file +} diff --git a/tests/resources/README.md b/tests/resources/README.md deleted file mode 100644 index 23d7ee42c17..00000000000 --- a/tests/resources/README.md +++ /dev/null @@ -1 +0,0 @@ -# Test resources diff --git a/tests/acceptance/surveys/MultipleChoiceWithExpressionTest.php b/tests/surveys/MultipleChoiceWithExpressionTest.php similarity index 96% rename from tests/acceptance/surveys/MultipleChoiceWithExpressionTest.php rename to tests/surveys/MultipleChoiceWithExpressionTest.php index c14cf355869..4d44989d5a9 100644 --- a/tests/acceptance/surveys/MultipleChoiceWithExpressionTest.php +++ b/tests/surveys/MultipleChoiceWithExpressionTest.php @@ -1,8 +1,8 @@ urlManager; $urlMan->setBaseUrl('http://' . self::$domain . '/index.php'); @@ -29,6 +30,7 @@ public function testBasic() 'lang' => 'pt' ] ); + // Get questions. $survey = \Survey::model()->findByPk(self::$surveyId); $questionObjects = $survey->groups[0]->questions; @@ -41,9 +43,11 @@ public function testBasic() $subquestions[$subq->title] = $subq; } $sgqa = self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['Q1']->qid . '123'; // 123 = first subquestion title. + try { // Get first page. self::$webDriver->get($url); + // Click on first multiple choice checkbox. $label = self::$webDriver->findElement( WebDriverBy::cssSelector( @@ -54,11 +58,13 @@ public function testBasic() ) ); $label->click(); + // Check that equation reacts. $equation = self::$webDriver->findElement(WebDriverBy::id('question' . $questions['equation1']->qid)); $equestionText = $equation->getText(); $trues = substr_count($equestionText, 'true'); $this->assertEquals(2, $trues, 'Found two "true"'); + $label->click(); $equestionText = $equation->getText(); $trues = substr_count($equestionText, 'true'); @@ -71,4 +77,4 @@ public function testBasic() ); } } -} \ No newline at end of file +} diff --git a/tests/acceptance/surveys/ScreenOutTest.php b/tests/surveys/ScreenOutTest.php similarity index 97% rename from tests/acceptance/surveys/ScreenOutTest.php rename to tests/surveys/ScreenOutTest.php index 6512b48e8a6..db01740812f 100644 --- a/tests/acceptance/surveys/ScreenOutTest.php +++ b/tests/surveys/ScreenOutTest.php @@ -1,13 +1,12 @@ 'pt' ] ); + try { self::$webDriver->get($url); + // Click next. $nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $nextButton->click(); + // Check that we see completed text. $completed = self::$webDriver->findElement(WebDriverBy::cssSelector('div.completed-text')); $this->assertNotEmpty($completed); + } catch (NoSuchElementException $ex) { $screenshot = self::$webDriver->takeScreenshot(); $filename = self::$screenshotsFolder.'/ScreenOutTest.png'; @@ -59,8 +64,9 @@ public function testNoAnswer() ); } } + /** - * + * */ public function testYes() { @@ -75,6 +81,7 @@ public function testYes() 'lang' => 'pt' ] ); + // Get questions. $survey = \Survey::model()->findByPk(self::$surveyId); $questionObjects = $survey->groups[0]->questions; @@ -82,25 +89,32 @@ public function testYes() foreach ($questionObjects as $q) { $questions[$q->title] = $q; } + try { self::$webDriver->get($url); + //javatbd186734X355X1911Y $answerId = 'javatbd' . self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['q1']->qid . 'Y'; $yesButton = self::$webDriver->findElement(WebDriverBy::id($answerId)); $yesButton->click(); + // Click next. $nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $nextButton->click(); + // answer186734X355X1912 $question2Id = 'answer' . self::$surveyId . 'X' . $survey->groups[0]->gid . 'X' . $questions['q2']->qid; $question2 = self::$webDriver->findElement(WebDriverBy::id($question2Id)); $this->assertNotEmpty($question2); + // Click next again. $nextButton = self::$webDriver->findElement(WebDriverBy::id('ls-button-submit')); $nextButton->click(); + // Check that we see completed text. $completed = self::$webDriver->findElement(WebDriverBy::cssSelector('div.completed-text')); $this->assertNotEmpty($completed); + } catch (NoSuchElementException $ex) { $screenshot = self::$webDriver->takeScreenshot(); $filename = self::$screenshotsFolder.'/ScreenOutTest.png'; @@ -112,4 +126,4 @@ public function testYes() ); } } -} \ No newline at end of file +} diff --git a/tests/travis/travis-ci-apache b/tests/travis/travis-ci-apache new file mode 100644 index 00000000000..fa2370a815c --- /dev/null +++ b/tests/travis/travis-ci-apache @@ -0,0 +1,25 @@ + + # [...] + + DocumentRoot %TRAVIS_BUILD_DIR% + + + Options FollowSymLinks MultiViews ExecCGI + AllowOverride All + Require all granted + + + # Wire up Apache to use Travis CI's php-fpm. + + AddHandler php7.1-fcgi .php + Action php7.1-fcgi /php7.1-fcgi + Alias /php7.1-fcgi /usr/lib/cgi-bin/php7.1-fcgi + FastCgiExternalServer /usr/lib/cgi-bin/php7.1-fcgi -host 127.0.0.1:9000 -pass-header Authorization + + + Require all granted + + + + # [...] + diff --git a/tests/unit/README.md b/tests/unit/README.md deleted file mode 100644 index ff60f5fa178..00000000000 --- a/tests/unit/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# Unit tests -from: -https://stackoverflow.com/questions/4904096/whats-the-difference-between-unit-functional-acceptance-and-integration-test - > Unit tests should be focussed on one particular feature (e.g., calling the pop method when the stack is empty should throw an InvalidOperationException). Everything it touches should be done in memory; this means that the test code and the code under test shouldn't: - >- Call out into (non-trivial) collaborators - >- Access the network - >- Hit a database - >- Use the file system - >- Spin up a thread - > - >Any kind of dependency that is slow / hard to understand / initialise / manipulate should be stubbed/mocked/whatevered using the appropriate techniques so you can focus on what the unit of code is doing, not what its dependencies do.