Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#980 [test -dbunit] remove dbunit dependency from MembershipRenewalTest #14315

Merged
merged 1 commit into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions tests/phpunit/CRM/Member/Form/MembershipRenewalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,8 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
protected $_individualId;
protected $_contribution;
protected $_financialTypeId = 1;
protected $_apiversion;
protected $_entity = 'Membership';
protected $_params;
protected $_ids = array();
protected $_paymentProcessorID;

/**
Expand All @@ -54,7 +52,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
*
* @var array
*/
protected $_processorParams = array();
protected $_processorParams = [];

/**
* ID of created membership.
Expand All @@ -68,7 +66,7 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
*
* @var array
*/
protected $paymentInstruments = array();
protected $paymentInstruments = [];


/**
Expand All @@ -83,18 +81,12 @@ class CRM_Member_Form_MembershipRenewalTest extends CiviUnitTestCase {
* and redirect stdin to a temporary file.
*/
public function setUp() {
$this->_apiversion = 3;
parent::setUp();

$this->_individualId = $this->individualCreate();
$this->_paymentProcessorID = $this->processorCreate();
// Insert test data.
$op = new PHPUnit_Extensions_Database_Operation_Insert();
$op->execute($this->_dbconn,
$this->createFlatXMLDataSet(
dirname(__FILE__) . '/dataset/data.xml'
)
);

$this->loadXMLDataSet(dirname(__FILE__) . '/dataset/data.xml');
$membershipTypeAnnualFixed = $this->callAPISuccess('membership_type', 'create', array(
'domain_id' => 1,
'name' => "AnnualFixed",
Expand All @@ -114,7 +106,7 @@ public function setUp() {
));
$this->_membershipID = $membership['id'];

$instruments = $this->callAPISuccess('contribution', 'getoptions', array('field' => 'payment_instrument_id'));
$instruments = $this->callAPISuccess('contribution', 'getoptions', ['field' => 'payment_instrument_id']);
$this->paymentInstruments = $instruments['values'];
}

Expand Down Expand Up @@ -144,7 +136,7 @@ public function tearDown() {
public function testSubmit() {
$form = $this->getForm();
$this->createLoggedInUser();
$params = array(
$params = [
'cid' => $this->_individualId,
'join_date' => date('m/d/Y', time()),
'start_date' => '',
Expand Down Expand Up @@ -178,7 +170,7 @@ public function testSubmit() {
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
);
];
$form->_contactID = $this->_individualId;

$form->testSubmit($params);
Expand Down
38 changes: 38 additions & 0 deletions tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,44 @@ public function loadAllFixtures() {
$this->getConnection()->getConnection()->query("SET FOREIGN_KEY_CHECKS = 1;");
}

/**
* Load the data that used to be handled by the discontinued dbunit class.
*
* This could do with further tidy up - the initial priority is simply to get rid of
* the dbunity package which is no longer supported.
*
* @param string $fileName
*/
protected function loadXMLDataSet($fileName) {
CRM_Core_DAO::executeQuery('SET FOREIGN_KEY_CHECKS = 0');
$xml = json_decode(json_encode(simplexml_load_file($fileName)), TRUE);
foreach ($xml as $tableName => $element) {
if (!empty($element)) {
foreach ($element as $row) {
$keys = $values = [];
if (isset($row['@attributes'])) {
foreach ($row['@attributes'] as $key => $value) {
$keys[] = $key;
$values[] = is_numeric($value) ? $value : "'{$value}'";
}
}
else {
// cos we copied it & it is inconsistent....
foreach ($row as $key => $value) {
$keys[] = $key;
$values[] = is_numeric($value) ? $value : "'{$value}'";
}
}

CRM_Core_DAO::executeQuery("
INSERT INTO $tableName (" . implode(',', $keys) . ') VALUES(' . implode(',', $values) . ')'
);
}
}
}
CRM_Core_DAO::executeQuery('SET FOREIGN_KEY_CHECKS = 1');
}

/**
* Create default domain contacts for the two domains added during test class.
* database population.
Expand Down