protected $_individualId;
protected $_contribution;
protected $_financialTypeId = 1;
- protected $_apiversion;
protected $_entity = 'Membership';
protected $_params;
- protected $_ids = array();
protected $_paymentProcessorID;
/**
*
* @var array
*/
- protected $_processorParams = array();
+ protected $_processorParams = [];
/**
* ID of created membership.
*
* @var array
*/
- protected $paymentInstruments = array();
+ protected $paymentInstruments = [];
/**
* 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",
));
$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'];
}
public function testSubmit() {
$form = $this->getForm();
$this->createLoggedInUser();
- $params = array(
+ $params = [
'cid' => $this->_individualId,
'join_date' => date('m/d/Y', time()),
'start_date' => '',
'billing_state_province_id-5' => '1003',
'billing_postal_code-5' => '90210',
'billing_country_id-5' => '1228',
- );
+ ];
$form->_contactID = $this->_individualId;
$form->testSubmit($params);
$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.