Skip to content

Commit

Permalink
Revert "Dev: Use PHPUnit dataset instead of manually inserting data i…
Browse files Browse the repository at this point in the history
…n test"

This reverts commit c60ac14.
  • Loading branch information
olleharstedt committed Feb 24, 2021
1 parent 5d2c4de commit fee6204
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 41 deletions.
2 changes: 2 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -216,6 +216,8 @@
}
}

$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

0 comments on commit fee6204

Please sign in to comment.