Permalink
Browse files

ESDEV-4156 Write functional tests to cover setup

These tests would act as characterization tests to ensure that no
functionality would be broken when trying to include changes of
showing errors from executing external commands.
  • Loading branch information...
1 parent 11b4d51 commit dcd8268542eea53f8b723ab5fdce7f15ca2060f2 @rezonanc-oxid rezonanc-oxid committed Dec 21, 2016
Showing with 724 additions and 46 deletions.
  1. +23 −1 source/Setup/Controller.php
  2. +23 −2 source/Setup/Utilities.php
  3. +678 −43 tests/Acceptance/Frontend/ShopSetUpTest.php
@@ -119,6 +119,9 @@ public function license()
/**
* DB info entry page
+ *
+ * Functionality is tested via:
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToWelcomeScreenInCaseLicenseIsNotCheckedAsAgreed`
*/
public function dbInfo()
{
@@ -182,6 +185,12 @@ public function dirsInfo()
/**
* Testing database connection
+ *
+ * Functionality is tested via:
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenNotAllFieldsAreFilled`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenDatabaseUserDoesNotHaveAccess`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenDatabaseUserIsValidButCantCreateDatabase`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testUserIsNotifiedIfAValidDatabaseAlreadyExistsBeforeTryingToOverwriteIt`
*/
public function dbConnect()
{
@@ -195,7 +204,7 @@ public function dbConnect()
$databaseConfigValues = $this->getUtilitiesInstance()->getRequestVar("aDB", "post");
$session->setSessionParam('aDB', $databaseConfigValues);
- // check if iportant parameters are set
+ // check if important parameters are set
if (!$databaseConfigValues['dbHost'] || !$databaseConfigValues['dbName']) {
$setup->setNextStep($setup->getStep('STEP_DB_INFO'));
$view->setMessage($language->getText('ERROR_FILL_ALL_FIELDS'));
@@ -259,6 +268,12 @@ public function dbConnect()
/**
* Creating database
+ *
+ * Functionality is tested via:
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenDatabaseUserIsValidButCantCreateDatabase`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testUserIsNotifiedIfAValidDatabaseAlreadyExistsBeforeTryingToOverwriteIt`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenSetupSqlFileIsMissing`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDatabaseEntryPageWhenSetupSqlFileHasSyntaxError`
*/
public function dbCreate()
{
@@ -352,6 +367,13 @@ public function dbCreate()
/**
* Writing config info
+ *
+ * Functionality is tested via:
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDirInfoEntryPageWhenNotAllFieldsAreFilled`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDirInfoEntryPageWhenPasswordIsTooShort`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDirInfoEntryPageWhenPasswordDoesNotMatch`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDirInfoEntryPageWhenInvalidEmailUsed`
+ * `Acceptance/Frontend/ShopSetUpTest.php::testSetupRedirectsToDirInfoEntryPageWhenSetupCantFindConfigFile`
*/
public function dirsWrite()
{
@@ -182,18 +182,20 @@ public function getDefaultPathParams()
}
/**
- * Updates config.inc.php file contents
+ * Updates config.inc.php file contents.
*
* @param array $aParams paths parameters
*
- * @throws Exception exception is thrown is file cant be open for reading or can not be written
+ * @throws Exception File can't be found, opened for reading or written.
*/
public function updateConfigFile($aParams)
{
$sConfPath = $aParams['sShopDir'] . "/config.inc.php";
$oLang = $this->getInstance("Language");
+ $this->handleMissingConfigFileException($sConfPath);
+
clearstatcache();
@chmod($sConfPath, getDefaultFileMode());
if (($fp = fopen($sConfPath, "r"))) {
@@ -222,6 +224,25 @@ public function updateConfigFile($aParams)
}
/**
+ * Throws an exception in case config file is missing.
+ *
+ * This is necessary to suppress PHP warnings during Setup. With the help of exception this problem is
+ * caught and displayed properly.
+ *
+ * @param string $pathToConfigFile File path to eShop configuration file.
+ *
+ * @throws Exception Config file is missing.
+ */
+ private function handleMissingConfigFileException($pathToConfigFile)
+ {
+ if (!file_exists($pathToConfigFile)) {
+ $language = $this->getLanguageInstance();
+
+ throw new Exception(sprintf($language->getText('ERROR_COULD_NOT_OPEN_CONFIG_FILE'), $pathToConfigFile));
+ }
+ }
+
+ /**
* Updates default htaccess file with user defined params
*
* @param array $aParams various setup parameters
Oops, something went wrong.

0 comments on commit dcd8268

Please sign in to comment.