Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisGac committed Jun 28, 2017
2 parents 0b44197 + 571a9f9 commit 20036bc
Show file tree
Hide file tree
Showing 15 changed files with 759 additions and 65 deletions.
1 change: 0 additions & 1 deletion application/helpers/update/updatedb_helper.php
Expand Up @@ -860,7 +860,6 @@ function db_upgrade_all($iOldDBVersion, $bSilent=false) {

addPrimaryKey('sessions', array('id'));
addColumn('{{surveys_languagesettings}}','surveyls_attributecaptions',"TEXT");
addColumn('{{surveys}}','sendconfirmation',"string(1) default 'Y'");

upgradeSurveys156();

Expand Down
6 changes: 2 additions & 4 deletions application/models/Survey.php
Expand Up @@ -104,12 +104,10 @@ class Survey extends LSActiveRecord
*/
protected $findByPkCache = array();

/**
* @var string $format : A : All in one, G : Group by group, Q : question by question
*/
/** @var string A : All in one, G : Group by group, Q : question by question */
public $format = 'G';
/**
* @var string $htmlemail : Y : all email related to this survey use HTML format
* @property string $htmlemail Y mean all email related to this survey use HTML format
*/
public $htmlemail='Y';

Expand Down
4 changes: 2 additions & 2 deletions docs/demosurveys/ls205_randomization_group_test.lss
Expand Up @@ -2723,7 +2723,7 @@
<row>
<sid><![CDATA[88881]]></sid>
<admin><![CDATA[Your Name]]></admin>
<adminemail><![CDATA[your@email.org]]></adminemail>
<adminemail><![CDATA[example@example.net]]></adminemail>
<anonymized><![CDATA[Y]]></anonymized>
<faxto/>
<format><![CDATA[G]]></format>
Expand All @@ -2750,7 +2750,7 @@
<assessments><![CDATA[Y]]></assessments>
<usecaptcha><![CDATA[D]]></usecaptcha>
<usetokens><![CDATA[N]]></usetokens>
<bounce_email><![CDATA[your@email.org]]></bounce_email>
<bounce_email><![CDATA[example@example.net]]></bounce_email>
<attributedescriptions/>
<emailresponseto/>
<emailnotificationto/>
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml
Expand Up @@ -3,5 +3,8 @@
<testsuite name="Questions">
<directory>tests/questions</directory>
</testsuite>
<testsuite name="Helpers">
<directory>tests/helpers</directory>
</testsuite>
</testsuites>
</phpunit>
22 changes: 22 additions & 0 deletions tests/TestBaseClass.php
@@ -0,0 +1,22 @@
<?php

namespace ls\tests;

use PHPUnit\Framework\TestCase;

class TestBaseClass extends \PHPUnit_Framework_TestCase
{
/**
* @var TestHelper
*/
protected static $testHelper = null;

public function __construct()
{
self::$testHelper = new TestHelper();

self::$testHelper->importAll();

parent::__construct();
}
}
79 changes: 78 additions & 1 deletion tests/TestHelper.php
Expand Up @@ -2,7 +2,26 @@

namespace ls\tests;

class TestHelper extends \PHPUnit_Framework_TestCase {
class TestHelper extends \PHPUnit_Framework_TestCase
{

/**
* Import all helpers etc.
* @return void
*/
public function importAll()
{
\Yii::import('application.helpers.common_helper', true);
\Yii::import('application.helpers.replacements_helper', true);
\Yii::import('application.helpers.surveytranslator_helper', true);
\Yii::import('application.helpers.admin.import_helper', true);
\Yii::import('application.helpers.expressions.em_manager_helper', true);
\Yii::import('application.helpers.expressions.em_manager_helper', true);
\Yii::import('application.helpers.qanda_helper', true);
\Yii::import('application.helpers.update.updatedb_helper', true);
\Yii::import('application.helpers.update.update_helper', true);
\Yii::app()->loadHelper('admin/activate');
}

/**
* @param string $title
Expand Down Expand Up @@ -107,4 +126,62 @@ public function deactivateSurvey($surveyId)
$result = $survey->save();
$this->assertTrue($result);
}

/**
* 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
* reconnect to it after you're done with the new
* database.
* $config = require(\Yii::app()->getBasePath() . '/config/config.php');
*
* @param string $databaseName
* @return boolean True at success.
*/
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';
if (!$isMysql) {
$this->markTestSkipped('Only works on MySQL');
return false;
}
$this->assertTrue($isMysql, 'This test only works on MySQL');

// Get database name.
preg_match("/dbname=([^;]*)/", \Yii::app()->db->connectionString, $matches);
$this->assertEquals(2, count($matches));
$oldDatabase = $matches[1];

try {
$result = $db->createCommand(
sprintf(
'CREATE DATABASE %s DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci',
$databaseName
)
)->execute();
$this->assertEquals(1, $result, 'Could create database');
} catch (\CDbException $ex) {
$msg = $ex->getMessage();
// This error is OK.
$this->assertTrue(strpos($msg, 'database exists') !== false);
}

// Connect to new database.
$db->setActive(false);
$newConfig = $config;
$newConfig['components']['db']['connectionString'] = str_replace(
'dbname=' . $oldDatabase,
'dbname=' . $databaseName,
$config['components']['db']['connectionString']
);
\Yii::app()->setComponent('db', $newConfig['components']['db'], false);
return true;
}
}
1 change: 1 addition & 0 deletions tests/bootstrap.php
Expand Up @@ -229,3 +229,4 @@
}, E_ERROR & E_WARNING & E_PARSE);

require_once(__DIR__ . '/TestHelper.php');
require_once(__DIR__ . '/TestBaseClass.php');

1 comment on commit 20036bc

@Shnoulle
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks you :)

Please sign in to comment.