Skip to content

Commit

Permalink
Add UTF-8 encoding to the DomDocument
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasmiller committed Sep 10, 2022
1 parent 17173a1 commit f498af1
Show file tree
Hide file tree
Showing 15 changed files with 45 additions and 35 deletions.
8 changes: 4 additions & 4 deletions Tests/Recurly/Account_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function testXml() {
$account->custom_fields[] = new Recurly_CustomField("serial_number", "4567-8900-1234");

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><account_code>act123</account_code><first_name>Verena</first_name><address><address1>123 Main St.</address1></address><tax_exempt>false</tax_exempt><entity_use_code>I</entity_use_code><shipping_addresses><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Home</nickname><first_name>Verena</first_name><last_name>Example</last_name></shipping_address></shipping_addresses><preferred_locale>en-US</preferred_locale><custom_fields><custom_field><name>serial_number</name><value>4567-8900-1234</value></custom_field></custom_fields><account_acquisition><cost_in_cents>599</cost_in_cents><currency>USD</currency><channel>marketing_content</channel><subchannel>pickle sticks blog post</subchannel><campaign>mailchimp67a904de95.0914d8f4b4</campaign></account_acquisition><exemption_certificate>Some Certificate</exemption_certificate><dunning_campaign_id>1234abcd</dunning_campaign_id></account>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<account><account_code>act123</account_code><first_name>Verena</first_name><address><address1>123 Main St.</address1></address><tax_exempt>false</tax_exempt><entity_use_code>I</entity_use_code><shipping_addresses><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address><address1>123 Dolores St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Home</nickname><first_name>Verena</first_name><last_name>Example</last_name></shipping_address></shipping_addresses><preferred_locale>en-US</preferred_locale><custom_fields><custom_field><name>serial_number</name><value>4567-8900-1234</value></custom_field></custom_fields><account_acquisition><cost_in_cents>599</cost_in_cents><currency>USD</currency><channel>marketing_content</channel><subchannel>pickle sticks blog post</subchannel><campaign>mailchimp67a904de95.0914d8f4b4</campaign></account_acquisition><exemption_certificate>Some Certificate</exemption_certificate><dunning_campaign_id>1234abcd</dunning_campaign_id></account>\n",
$account->xml()
);
}
Expand All @@ -159,7 +159,7 @@ public function testTransactionType() {
$account = Recurly_Account::get('abcdef1234567890', $this->client);
$account->transaction_type = 'moto';
$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><transaction_type>moto</transaction_type></account>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<account><transaction_type>moto</transaction_type></account>\n",
$account->xml()
);
}
Expand All @@ -172,7 +172,7 @@ public function testNestedAddress() {
$account = Recurly_Account::get('abcdef1234567890', $this->client);
$account->address->address1 = '987 Alternate St.';
$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><address><address1>987 Alternate St.</address1></address></account>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<account><address><address1>987 Alternate St.</address1></address></account>\n",
$account->xml()
);
}
Expand All @@ -187,7 +187,7 @@ public function testNestedCustomFields() {
$account->custom_fields[] = new Recurly_CustomField('shasta', '');

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<account><custom_fields><custom_field><name>shasta</name><value></value></custom_field><custom_field><name>new_field</name><value>something</value></custom_field></custom_fields></account>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<account><custom_fields><custom_field><name>shasta</name><value></value></custom_field><custom_field><name>new_field</name><value>something</value></custom_field></custom_fields></account>\n",
$account->xml()
);
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Adjustment_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testXml() {
// This deprecated parameter should be ignored:
$charge->taxable = 0;

$expected = "<?xml version=\"1.0\"?>\n<adjustment><currency>USD</currency><unit_amount_in_cents>5000</unit_amount_in_cents><quantity>1</quantity><description>Charge for extra bandwidth</description><accounting_code>bandwidth</accounting_code><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><origin>external_gift_card</origin><product_code>abc123</product_code><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address_id>123456789</shipping_address_id></adjustment>\n";
$expected = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<adjustment><currency>USD</currency><unit_amount_in_cents>5000</unit_amount_in_cents><quantity>1</quantity><description>Charge for extra bandwidth</description><accounting_code>bandwidth</accounting_code><tax_exempt>false</tax_exempt><tax_code>fake-tax-code</tax_code><origin>external_gift_card</origin><product_code>abc123</product_code><shipping_address><address1>123 Main St.</address1><city>San Francisco</city><state>CA</state><zip>94110</zip><country>US</country><phone>555-555-5555</phone><email>verena@example.com</email><nickname>Work</nickname><first_name>Verena</first_name><last_name>Example</last_name><company>Recurly Inc.</company></shipping_address><shipping_address_id>123456789</shipping_address_id></adjustment>\n";
$this->assertEquals($expected, $charge->xml());
}
}
10 changes: 5 additions & 5 deletions Tests/Recurly/Billing_Info_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public function testCreateForAccountWithToken() {
$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals(
$billing_info->xml(),
"<?xml version=\"1.0\"?>\n<billing_info><token_id>abc123</token_id></billing_info>\n"
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<billing_info><token_id>abc123</token_id></billing_info>\n"
);
$billing_info->create();
}
Expand All @@ -184,7 +184,7 @@ public function testTransactionType() {
$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals(
$billing_info->xml(),
"<?xml version=\"1.0\"?>\n<billing_info><transaction_type>moto</transaction_type></billing_info>\n"
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<billing_info><transaction_type>moto</transaction_type></billing_info>\n"
);
}

Expand All @@ -196,7 +196,7 @@ public function testForExternalHppType() {
$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals(
$billing_info->xml(),
"<?xml version=\"1.0\"?>\n<billing_info><token_id>abc123</token_id><external_hpp_type>adyen</external_hpp_type></billing_info>\n"
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<billing_info><token_id>abc123</token_id><external_hpp_type>adyen</external_hpp_type></billing_info>\n"
);
}

Expand All @@ -208,7 +208,7 @@ public function testForOnlineBankingPaymentType() {
$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals(
$billing_info->xml(),
"<?xml version=\"1.0\"?>\n<billing_info><token_id>abc123</token_id><online_banking_payment_type>ideal</online_banking_payment_type></billing_info>\n"
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<billing_info><token_id>abc123</token_id><online_banking_payment_type>ideal</online_banking_payment_type></billing_info>\n"
);
}

Expand All @@ -222,7 +222,7 @@ public function testForGatewayToken() {
$this->assertInstanceOf('Recurly_BillingInfo', $billing_info);
$this->assertEquals(
$billing_info->xml(),
"<?xml version=\"1.0\"?>\n<billing_info><month>11</month><year>2025</year><gateway_token>x1x2x3</gateway_token><gateway_code>abc123</gateway_code></billing_info>\n"
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<billing_info><month>11</month><year>2025</year><gateway_token>x1x2x3</gateway_token><gateway_code>abc123</gateway_code></billing_info>\n"
);
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/Recurly/Coupon_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testXml() {
$coupon->invoice_description = 'Invoice description';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<coupon><coupon_code>fifteen-off</coupon_code><name>$15 Off</name><discount_type>dollar</discount_type><discount_in_cents><USD>1500</USD></discount_in_cents><invoice_description>Invoice description</invoice_description></coupon>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coupon><coupon_code>fifteen-off</coupon_code><name>$15 Off</name><discount_type>dollar</discount_type><discount_in_cents><USD>1500</USD></discount_in_cents><invoice_description>Invoice description</invoice_description></coupon>\n",
$coupon->xml()
);
}
Expand All @@ -128,7 +128,7 @@ public function testXmlWithPlans() {
$coupon->invoice_description = 'Invoice description';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<coupon><coupon_code>fifteen-off</coupon_code><name>$15 Off</name><discount_type>dollar</discount_type><discount_in_cents><USD>1500</USD></discount_in_cents><plan_codes><plan_code>gold</plan_code><plan_code>monthly</plan_code></plan_codes><invoice_description>Invoice description</invoice_description></coupon>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coupon><coupon_code>fifteen-off</coupon_code><name>$15 Off</name><discount_type>dollar</discount_type><discount_in_cents><USD>1500</USD></discount_in_cents><plan_codes><plan_code>gold</plan_code><plan_code>monthly</plan_code></plan_codes><invoice_description>Invoice description</invoice_description></coupon>\n",
$coupon->xml()
);
}
Expand All @@ -143,7 +143,7 @@ public function testXmlWithItems() {
$coupon->invoice_description = 'Invoice description';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<coupon><coupon_code>twenty-off</coupon_code><name>$20 Off</name><discount_type>dollar</discount_type><discount_in_cents><USD>2000</USD></discount_in_cents><item_codes><item_code>item_one</item_code><item_code>item_two</item_code><item_code>item_three</item_code></item_codes><invoice_description>Invoice description</invoice_description></coupon>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coupon><coupon_code>twenty-off</coupon_code><name>$20 Off</name><discount_type>dollar</discount_type><discount_in_cents><USD>2000</USD></discount_in_cents><item_codes><item_code>item_one</item_code><item_code>item_two</item_code><item_code>item_three</item_code></item_codes><invoice_description>Invoice description</invoice_description></coupon>\n",
$coupon->xml()
);
}
Expand All @@ -167,7 +167,7 @@ public function testCreateUpdateXML() {
$coupon->description = 'New Description';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<coupon><name>$15 Off</name><max_redemptions>100</max_redemptions><max_redemptions_per_account>3</max_redemptions_per_account><hosted_description></hosted_description><invoice_description>Invoice description</invoice_description><redeem_by_date>2017-12-01</redeem_by_date><description>New Description</description></coupon>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<coupon><name>$15 Off</name><max_redemptions>100</max_redemptions><max_redemptions_per_account>3</max_redemptions_per_account><hosted_description></hosted_description><invoice_description>Invoice description</invoice_description><redeem_by_date>2017-12-01</redeem_by_date><description>New Description</description></coupon>\n",
$coupon->createUpdateXML()
);
}
Expand Down
7 changes: 5 additions & 2 deletions Tests/Recurly/Currency_List_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ public function testCreateXml() {
$currencyList->addCurrency('EUR', 1200);

$doc = new DOMDocument("1.0");
$doc->encoding = 'utf-8';
$doc->encoding = 'utf-8';
$root = $doc->appendChild($doc->createElement('wrapper'));
$currencyList->populateXmlDoc($doc, $root);

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<wrapper><element_name><USD>1500</USD><EUR>1200</EUR></element_name></wrapper>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<wrapper><element_name><USD>1500</USD><EUR>1200</EUR></element_name></wrapper>\n",
$doc->saveXML()
);
}
Expand All @@ -22,11 +24,12 @@ public function testCreateXml_EmptyCreatesNoElement() {
$currencyList = new Recurly_CurrencyList('setup_fee_in_cents');

$doc = new DOMDocument("1.0");
$doc->encoding = 'utf-8';
$root = $doc->appendChild($doc->createElement('wrapper'));
$currencyList->populateXmlDoc($doc, $root);

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<wrapper/>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<wrapper/>\n",
$doc->saveXML()
);
}
Expand Down
4 changes: 3 additions & 1 deletion Tests/Recurly/Currency_Percentage_Tier_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public function testCreateXml() {
$percentageTierByCurrency->usage_percentage = '10.0';

$doc = new DOMDocument("1.0");
$doc->encoding = 'utf-8';
$root = $doc->appendChild($doc->createElement('tiers'));
$percentageTierByCurrency->populateXmlDoc($doc, $root, $percentageTierByCurrency);

Expand All @@ -25,11 +26,12 @@ public function testCreateXml_EmptyCreatesNoElement() {
$percentageTierByCurrency = new Recurly_CurrencyPercentageTier();

$doc = new DOMDocument("1.0");
$doc->encoding = 'utf-8';
$root = $doc->appendChild($doc->createElement('wrapper'));
$percentageTierByCurrency->populateXmlDoc($doc, $root, $percentageTierByCurrency);

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<wrapper/>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<wrapper/>\n",
$doc->saveXml()
);
}
Expand Down
13 changes: 7 additions & 6 deletions Tests/Recurly/CustomFieldList_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ class Recurly_CustomFieldListTest extends Recurly_TestCase
{
function asXml($list) {
$doc = new DOMDocument("1.0");
$doc->encoding = 'utf-8';
$list->populateXmlDoc($doc, $doc);
return $doc->saveXML(null, LIBXML_NOEMPTYTAG);
}

public function testEmptyListXml() {
$list = new Recurly_CustomFieldList();
$this->assertEquals("<?xml version=\"1.0\"?>\n", $this->asXml($list));
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n", $this->asXml($list));
}

public function testRejectsOtherObjects() {
Expand Down Expand Up @@ -39,23 +40,23 @@ public function testAssignFieldWithStringValue() {

$this->assertEquals('bar', $list['foo']->value);
$this->assertTrue($list['foo']->has_changed());
$this->assertEquals("<?xml version=\"1.0\"?>\n<custom_fields><custom_field><name>foo</name><value>bar</value></custom_field></custom_fields>\n", $this->asXml($list));
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<custom_fields><custom_field><name>foo</name><value>bar</value></custom_field></custom_fields>\n", $this->asXml($list));
}

public function testAssignFieldWithEmptyValue() {
$list = new Recurly_CustomFieldList();
$list[] = new Recurly_CustomField('empty_value', '');

$this->assertEquals('', $list['empty_value']->value);
$this->assertEquals("<?xml version=\"1.0\"?>\n<custom_fields><custom_field><name>empty_value</name><value></value></custom_field></custom_fields>\n", $this->asXml($list));
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<custom_fields><custom_field><name>empty_value</name><value></value></custom_field></custom_fields>\n", $this->asXml($list));
}

public function testAssignFieldWithNilValue() {
$list = new Recurly_CustomFieldList();
$list[] = new Recurly_CustomField('nil_value', null);

$this->assertEquals('', $list['nil_value']->value);
$this->assertEquals("<?xml version=\"1.0\"?>\n<custom_fields><custom_field><name>nil_value</name><value nil=\"nil\"></value></custom_field></custom_fields>\n", $this->asXml($list));
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<custom_fields><custom_field><name>nil_value</name><value nil=\"nil\"></value></custom_field></custom_fields>\n", $this->asXml($list));
}

public function testUnset() {
Expand All @@ -64,7 +65,7 @@ public function testUnset() {

$this->assertTrue(isset($list['foo']));
$this->assertEquals(null, $list['foo']->value);
$this->assertEquals("<?xml version=\"1.0\"?>\n<custom_fields><custom_field><name>foo</name><value nil=\"nil\"></value></custom_field></custom_fields>\n", $this->asXml($list));
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<custom_fields><custom_field><name>foo</name><value nil=\"nil\"></value></custom_field></custom_fields>\n", $this->asXml($list));
}

public function testSeralizesChanged() {
Expand All @@ -79,7 +80,7 @@ public function testSeralizesChanged() {
$list['foo']->value = 'baz';
$this->assertEquals('baz', $list['foo']->value);
$this->assertTrue($list['foo']->has_changed());
$this->assertEquals("<?xml version=\"1.0\"?>\n<custom_fields><custom_field><name>foo</name><value>baz</value></custom_field></custom_fields>\n", $this->asXml($list));
$this->assertEquals("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<custom_fields><custom_field><name>foo</name><value>baz</value></custom_field></custom_fields>\n", $this->asXml($list));
}

public function testIteration() {
Expand Down
2 changes: 1 addition & 1 deletion Tests/Recurly/Invoice_Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testUpdateInvoice() {
$invoice->gateway_code = 'A new gateway code';

$this->assertEquals(
"<?xml version=\"1.0\"?>\n<invoice><address><first_name>Spongebob</first_name><last_name>Squarepants</last_name><name_on_account>Patrick Star</name_on_account><company>Krusty Krab</company><address1>124 Conch Street</address1><address2>Pineapple</address2><city>Bikini Bottom</city><state>Dead Eye Gulch</state><zip>96970</zip><country>Pacific Ocean</country><phone>509-990-3551</phone></address><terms_and_conditions>Never disclose the location of the Krabby Patty secret formula.</terms_and_conditions><customer_notes>Is this the Krusty Krab?</customer_notes><vat_reverse_charge_notes>can't be changed when invoice was not a reverse charge</vat_reverse_charge_notes><net_terms>60</net_terms><po_number>3699</po_number><gateway_code>A new gateway code</gateway_code></invoice>\n",
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<invoice><address><first_name>Spongebob</first_name><last_name>Squarepants</last_name><name_on_account>Patrick Star</name_on_account><company>Krusty Krab</company><address1>124 Conch Street</address1><address2>Pineapple</address2><city>Bikini Bottom</city><state>Dead Eye Gulch</state><zip>96970</zip><country>Pacific Ocean</country><phone>509-990-3551</phone></address><terms_and_conditions>Never disclose the location of the Krabby Patty secret formula.</terms_and_conditions><customer_notes>Is this the Krusty Krab?</customer_notes><vat_reverse_charge_notes>can't be changed when invoice was not a reverse charge</vat_reverse_charge_notes><net_terms>60</net_terms><po_number>3699</po_number><gateway_code>A new gateway code</gateway_code></invoice>\n",
$invoice->xml()
);
$invoice->update();
Expand Down
Loading

0 comments on commit f498af1

Please sign in to comment.