Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
olleharstedt committed Feb 24, 2021
2 parents 725dd68 + 85cbc1b commit 0afd310
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 51 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Expand Up @@ -65,7 +65,8 @@ before_script:
- cp application/config/config-sample-mysql.php application/config/config.php
# Enable debug=2 in config file. OBS: This assumes debug is on line 61.
# TODO: Disable, a lines was added to config file and some tests started to fail.
# - sed -i '61s/.*/ "debug"=>2,/' application/config/config.php
- sed -i '61s/.*/ "debug"=>2,/' application/config/config.php
- cat application/config/config.php

# Install Apache.
# Code fetched from https://docs.travis-ci.com/user/languages/php/#Apache-%2B-PHP
Expand Down Expand Up @@ -112,5 +113,5 @@ before_script:

script:
# Run tests.
- DOMAIN=localhost ./third_party/bin/phpunit --stop-on-failure
- DOMAIN=localhost ./third_party/bin/phpunit --stop-on-failure --testdox
- yarn --cwd ./assets/packages/adminbasics run test
Expand Up @@ -59,8 +59,8 @@ public function move($destdir)
throw new Exception(gT('Temporary folder does not exist.'));
}

// TODO: Correct permission?
mkdir($destdir, 0760, true);
// NB: mkdir() always applies the set umask to 0777. See https://www.php.net/manual/en/function.mkdir
mkdir($destdir, 0777, true);

if (!is_writable(dirname($destdir))) {
throw new Exception(gT('Cannot move files due to permission problem. ' . $destdir));
Expand Down
Expand Up @@ -35,7 +35,7 @@
<div class="row ls-space margin top-10 bottom-10">
<div class='form-group'>
<label class='control-label col-sm-4'>
<?php eT('Display survey participants after adding?'); ?>
<?php eT('Display survey participant table after addition?'); ?>
</label>
<div class='col-sm-8'>
<!--<input type='checkbox' name='redirect' />-->
Expand Down
4 changes: 2 additions & 2 deletions application/views/assessment/assessments_view.php
Expand Up @@ -15,15 +15,15 @@
<div class="container-fluid">
<?php
$messageLink = gT("Assessment mode for this survey is not activated.").'<br/>'
. gt("If you want to activate it click here:").'<br/>'
. gt("If you want to activate it, click here:").'<br/>'
. '<a type="submit" class="btn btn-primary" href="'
. $this->createUrl('/assessment/activate', ['surveyid'=> $surveyid])
.'">'.gT('Activate assessements').'</a>';
if(!Assessment::isAssessmentActive($surveyid)) {
?>
<div class="row text-center">
<div class="jumbotron message-box warningheader col-sm-12 col-md-6 col-md-offset-3">
<h2><?= gT("Assessments mode not activated"); ?></h2>
<h2><?= gT("Assessment mode not activated"); ?></h2>
<?php echo $messageLink; ?>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -47,8 +47,9 @@
"scripts": {
"test": [
"! find application/ -type f -name '*.php' -print0 | xargs -I {} -0 -P 0 php -l {} | grep -v 'No syntax error'",
"! find tests/ -type f -name '*.php' -print0 | xargs -I {} -0 -P 0 php -l {} | grep -v 'No syntax error'",
"./third_party/bin/phpcs --standard=tests/rulesets/phpcs_ruleset.xml application/models/services",
"./third_party/bin/phpmd application/models/services/ text unusedcode",
"./third_party/bin/phpmd application/models/services/ text tests/rulesets/phpmd_ruleset.xml",
"./third_party/bin/psalm application/models/services/"
]
}
Expand Down
3 changes: 3 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -216,6 +216,9 @@
}
}

// NB: This line might be needed if you have PHP in a docker container.
//$config['components']['db']['connectionString'] = 'mysql:host=localhost;port=3306;dbname=ls4;';

// Check that tmp and upload are set to 777 permission (OK on test system).
if (substr(sprintf('%o', fileperms(BASEPATH . '../tmp/')), -4) != '0777') {
die('tmp folder not set to 777');
Expand Down
11 changes: 0 additions & 11 deletions tests/data/datasets/participantattributes.xml

This file was deleted.

40 changes: 10 additions & 30 deletions tests/unit/controllers/ParticipantActionTest.php
Expand Up @@ -3,39 +3,12 @@
namespace ls\tests\controllers;

use ls\tests\TestBaseClass;
use PHPUnit\DbUnit\TestCaseTrait;

/**
* Test the participantsaction controller class.
*/
class ParticipantActionTest extends TestBaseClass
{
use TestCaseTrait;

/**
* @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
*/
public function getConnection()
{
$config = include(APPPATH . '/config/config.php');
$dsn = 'mysql:dbname=limesurvey;host=localhost';
$user = $config['components']['db']['username'];
$password = $config['components']['db']['password'];
$pdo = new \PDO($dsn, $user, $password);
return $this->createDefaultDBConnection($pdo);
}

/**
* @return PHPUnit_Extensions_Database_DataSet_IDataSet
*/
public function getDataSet()
{
if (\PHP_VERSION_ID < 80000) {
libxml_disable_entity_loader(false);
}
return $this->createFlatXMLDataSet(ROOT . '/tests/data/datasets/participantattributes.xml');
}

/**
* @group pp
*/
Expand All @@ -49,7 +22,13 @@ public function testUpdateEncryption()
$participantController = new \participantsaction('dummy');

// TODO: Use PHPUnit dataset instead? https://phpunit.de/manual/6.5/en/database.html
$attribute_id = 10;
$attrName = new \ParticipantAttributeName();
$attrName->attribute_type = 'TB';
$attrName->defaultname = 'encrypted';
$attrName->visible = 'TRUE';
$attrName->encrypted = 'Y';
$attrName->core_attribute = 'N';
$this->assertTrue($attrName->save());

$attrName2 = new \ParticipantAttributeName();
$attrName2->attribute_type = 'TB';
Expand Down Expand Up @@ -79,7 +58,7 @@ public function testUpdateEncryption()

/** @var array<string, string> */
$extraAttributes = [
'ea_' . $attribute_id => 'Some encrypted value',
'ea_' . $attrName->attribute_id => 'Some encrypted value',
'ea_' . $attrName2->attribute_id => 'Some value'
];

Expand Down Expand Up @@ -112,7 +91,7 @@ public static function outputError($msg, $code = 0)
$attrValue = \ParticipantAttribute::model()->findByAttributes(
[
'participant_id' => $part->participant_id,
'attribute_id' => $attribute_id
'attribute_id' => $attrName->attribute_id
]
);

Expand All @@ -131,6 +110,7 @@ public static function outputError($msg, $code = 0)
// Equal, because it is NOT encrypted.
$this->assertEquals('Some value', $attrValue2->value);

$this->assertTrue($attrName->delete());
$this->assertTrue($attrName2->delete());
$this->assertTrue($attrValue->delete());
$this->assertTrue($attrValue2->delete());
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/helpers/RemoteControlTest.php
Expand Up @@ -333,7 +333,7 @@ public function testImportGroup()
$sessionKey,
self::$surveyId,
$groupData,
'lsg',
'lsg'
);

$this->assertIsNumeric($result, '$result = ' . json_encode($result));
Expand All @@ -346,5 +346,4 @@ public function testImportGroup()
self::$testSurvey->delete();
self::$testSurvey = null;
}

}

0 comments on commit 0afd310

Please sign in to comment.