*
* @param mixed $prop Valid property name
* @param string $label e.g. 'default'
+ *
+ * @return mixed
*/
protected function get($prop, $label) {
- if (isset($this->props['default'][$prop])) {
+ if (array_key_exists($prop, $this->props['default'])) {
return $this->props[$label][$prop];
}
throw new \BadMethodCallException("Property '$prop' has not been set.");
/**
* @param int $contributionRecurID
* @param string $label e.g. 'default'
+ *
+ * @return \Civi\Payment\PropertyBag
*/
public function setContributionRecurID($contributionRecurID, $label = 'default') {
// We don't use this because it counts zero as positive: CRM_Utils_Type::validate($contactID, 'Positive');
if (!($contributionRecurID > 0)) {
- throw new InvalidArgumentException("ContributionRecurID must be a positive integer");
+ throw new InvalidArgumentException('ContributionRecurID must be a positive integer');
}
return $this->set('contributionRecurID', $label, (int) $contributionRecurID);
* Nb. this is stored in civicrm_contribution_recur.processor_id and is NOT
* in any way related to the payment processor ID.
*
- * @return string
+ * @param string $label
+ *
+ * @return string|null
*/
public function getRecurProcessorID($label = 'default') {
return $this->get('recurProcessorID', $label);
* Set the unique payment processor service provided ID for a particular
* subscription.
*
- * @param string $input
+ * See https://github.com/civicrm/civicrm-core/pull/17292 for discussion
+ * of how this function accepting NULL fits with standard / planned behaviour.
+ *
+ * @param string|null $input
* @param string $label e.g. 'default'
+ *
+ * @return \Civi\Payment\PropertyBag
*/
public function setRecurProcessorID($input, $label = 'default') {
- if (empty($input) || strlen($input) > 255) {
- throw new \InvalidArgumentException("processorID field has max length of 255");
+ if ($input === '') {
+ $input = NULL;
+ }
+ if (strlen($input) > 255 || in_array($input, [FALSE, 0], TRUE)) {
+ throw new \InvalidArgumentException('processorID field has max length of 255');
}
return $this->set('recurProcessorID', $label, $input);
}
*/
class PropertyBagTest extends \PHPUnit\Framework\TestCase implements HeadlessInterface, TransactionalInterface {
+ /**
+ * @return \Civi\Test\CiviEnvBuilder
+ */
public function setUpHeadless() {
return \Civi\Test::headless()->apply();
}
- protected function setUp() {
- parent::setUp();
- // $this->useTransaction(TRUE);
- }
-
- public function tearDown() {
- parent::tearDown();
- }
-
/**
* Test we can set a contact ID.
*/
$this->assertEquals(123, $propertyBag['contact_id']);
}
+ /**
+ * Test that null is valid for recurring contribution ID.
+ *
+ * See https://github.com/civicrm/civicrm-core/pull/17292
+ */
+ public function testRecurProcessorIDNull() {
+ $bag = new PropertyBag();
+ $bag->setRecurProcessorID(NULL);
+ $value = $bag->getRecurProcessorID();
+ $this->assertNull($value);
+ }
+
/**
*/
public function testMergeInputs() {
['paymentToken', [], $valid_strings, []],
['recurFrequencyInterval', ['frequency_interval'], $valid_ints, $invalid_ints],
['recurFrequencyUnit', [], [['month', 'month'], ['day', 'day'], ['year', 'year']], ['', NULL, 0]],
- ['recurProcessorID', [], [['foo', 'foo']], [str_repeat('x', 256), NULL, '', 0]],
+ ['recurProcessorID', [], [['foo', 'foo']], [str_repeat('x', 256)]],
['transactionID', ['transaction_id'], $valid_strings, []],
['trxnResultCode', [], $valid_strings, []],
];