Skip to content

Commit

Permalink
tests restructure
Browse files Browse the repository at this point in the history
  • Loading branch information
TonisOrmisson committed Jan 10, 2018
1 parent 5c9b80a commit d57a6fa
Show file tree
Hide file tree
Showing 56 changed files with 1,475 additions and 263 deletions.
2 changes: 1 addition & 1 deletion tests/DummyController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ls\tests;
namespace LimeSurvey\tests;

class DummyController extends \CController
{
Expand Down
52 changes: 44 additions & 8 deletions tests/TestBaseClass.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ls\tests;
namespace LimeSurvey\tests;

use PHPUnit\Framework\TestCase;

Expand Down Expand Up @@ -34,15 +34,51 @@ class TestBaseClass extends TestCase

public static function setUpBeforeClass()
{
parent::setUpBeforeClass();
self::$testHelper = new TestHelper();

self::$dataFolder = __DIR__.'/data';
self::$viewsFolder = self::$dataFolder."/views";
self::$surveysFolder = self::$dataFolder.'/surveys';
self::$tempFolder = __DIR__.'/tmp';
self::$screenshotsFolder = self::$tempFolder.'/screenshots';
self::$dataFolder = self::getDataFolder();
self::$viewsFolder = self::getViewsFolder();
self::$surveysFolder = self::getSurveysFolder();
self::$tempFolder = self::getTempFolder();
self::$screenshotsFolder = self::getScreenShotsFolder();
self::$testHelper->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";
}

/**
* @return string
*/
public static function getScreenShotsFolder(){
return self::getTempFolder().DIRECTORY_SEPARATOR.'screenshots';
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/TestBaseClassView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
* See COPYRIGHT.php for copyright notices and details.
*/

namespace ls\tests;
namespace LimeSurvey\tests;

use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;

/**
* @package ls\tests
* @package LimeSurvey\tests
*/
class TestBaseClassView extends TestBaseClassWeb
{
Expand Down
4 changes: 2 additions & 2 deletions tests/TestBaseClassWeb.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* See COPYRIGHT.php for copyright notices and details.
*/

namespace ls\tests;
namespace LimeSurvey\tests;

use Facebook\WebDriver\WebDriver;
use Facebook\WebDriver\WebDriverBy;
Expand All @@ -21,7 +21,7 @@
/**
* Class TestBaseClassWeb
* this is the base class for functional tests that need browser simulation
* @package ls\tests
* @package LimeSurvey\tests
*/
class TestBaseClassWeb extends TestBaseClass
{
Expand Down
7 changes: 3 additions & 4 deletions tests/TestHelper.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ls\tests;
namespace LimeSurvey\tests;

use Facebook\WebDriver\Exception\WebDriverException;
use PHPUnit\Framework\TestCase;
Expand All @@ -10,8 +10,7 @@
use Facebook\WebDriver\Firefox\FirefoxDriver;
use Facebook\WebDriver\Firefox\FirefoxProfile;
use Facebook\WebDriver\Firefox\FirefoxPreferences;
use Facebook\WebDriver\Exception\WebDriverCurlException;
use Facebook\WebDriver\Exception\NoSuchDriverException;


class TestHelper extends TestCase
{
Expand Down Expand Up @@ -238,7 +237,7 @@ public function updateDbFromVersion($version, $connection = null)
$inst->connection = $connection;

// Check SQL file.
$file = __DIR__ . '/data/sql/create-mysql.' . $version . '.sql';
$file = TestBaseClass::getDataFolder() . '/sql/create-mysql.' . $version . '.sql';
$this->assertFileExists($file, 'SQL file exists: ' . $file);

// Run SQL install file.
Expand Down
25 changes: 25 additions & 0 deletions tests/WebTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* Change the following URL based on your server configuration
* Make sure the URL ends with a slash so that we can use relative URLs in test cases
*/
define('TEST_BASE_URL', 'http://localhost/testdrive/index-test.php/');

/**
* The base class for functional test cases.
* In this class, we set the base URL for the test application.
* We also provide some common methods to be used by concrete test classes.
*/
class WebTestCase extends CWebTestCase
{
/**
* Sets up before each test method runs.
* This mainly sets the base URL for the test application.
*/
protected function setUp()
{
parent::setUp();
$this->setBrowserUrl(TEST_BASE_URL);
}
}
7 changes: 7 additions & 0 deletions tests/acceptance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,47 @@
* See COPYRIGHT.php for copyright notices and details.
*/

namespace ls\tests\controllers;
namespace LimeSurvey\tests\acceptance\admin;

use ls\tests\TestBaseClassView;
use LimeSurvey\tests\TestBaseClassView;

/**
* Class AdminViewsTest
* This test loops through all basic admin view pages and cheks if they open withour errors
*
* @package ls\tests
* @package LimeSurvey\tests
* @group adminviews
*/
class AdminViewsTest extends TestBaseClassView
{

public function addBaseViews()
{
return require __DIR__."/../data/views/adminBaseViews.php";
return require self::getViewsFolder()."/adminBaseViews.php";
}

public function addSurveyViews()
{
return require __DIR__."/../data/views/adminSurveyViews.php";
return require self::getViewsFolder()."/adminSurveyViews.php";
}

public function addSettingsViews()
{
return require __DIR__."/../data/views/adminSettingsViews.php";
return require self::getViewsFolder()."/adminSettingsViews.php";
}

public function addUsersViews()
{
return require __DIR__."/../data/views/adminUsersViews.php";
return require self::getViewsFolder()."/adminUsersViews.php";
}
public function addParticipantsViews()
{
return require __DIR__."/../data/views/adminParticipantsViews.php";
return require self::getViewsFolder()."/adminParticipantsViews.php";
}

public function addGeneralSettingsViews()
{
return require __DIR__."/../data/views/adminGeneralSettingsViews.php";
return require self::getViewsFolder()."/adminGeneralSettingsViews.php";
}

/**
Expand Down Expand Up @@ -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 . '/../data/surveys/limesurvey_survey_454287.lss';
$surveyFile = self::$surveysFolder . '/limesurvey_survey_454287.lss';
self::importSurvey($surveyFile);

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
<?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.
*/

namespace ls\tests;
namespace LimeSurvey\tests\acceptance\admin;

use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
Expand All @@ -9,6 +20,7 @@
use Facebook\WebDriver\Exception\UnknownServerException;
use Facebook\WebDriver\Exception\TimeOutException;
use Facebook\WebDriver\Exception\ElementNotVisibleException;
use LimeSurvey\tests\TestBaseClassWeb;

/**
* Login and create a survey, add a group
Expand Down

0 comments on commit d57a6fa

Please sign in to comment.