Skip to content

Commit

Permalink
xml/templates/civicrm_state_province.tpl: regroup state/provinces by …
Browse files Browse the repository at this point in the history
…country
  • Loading branch information
mlutfy committed Nov 16, 2023
1 parent 0080ded commit d2ce7f7
Show file tree
Hide file tree
Showing 5 changed files with 525 additions and 610 deletions.
20 changes: 10 additions & 10 deletions tests/phpunit/CRM/Contact/Import/Parser/ContactTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1353,13 +1353,13 @@ public function testImportCountryStateCounty(): void {
$countyID = County::create()->setValues([
'name' => 'Farnell',
'abbreviation' => '',
'state_province_id' => 1640,
'state_province_id:name' => 'New South Wales',
])->execute()->first()['id'];
// What if there are two counties with the same name?
County::create()->setValues([
'name' => 'Farnell',
'abbreviation' => '',
'state_province_id' => 1641,
'state_province_id:name' => 'Queensland',
])->execute()->first()['id'];

$childKey = $this->getRelationships()['Child of']['id'] . '_a_b';
Expand Down Expand Up @@ -1408,9 +1408,9 @@ public function testImportCountryStateCounty(): void {
$this->importCSV($csv, $mapper);
$contacts = $this->getImportedContacts();
foreach ($contacts as $contact) {
$this->assertEquals($countyID, $contact['address'][0]['county_id']);
$this->assertEquals(1013, $contact['address'][0]['country_id']);
$this->assertEquals(1640, $contact['address'][0]['state_province_id']);
$this->assertEquals($countyID, $contact['address_primary.county_id']);
$this->assertEquals('Australia', $contact['address_primary.country_id.name']);
$this->assertEquals('New South Wales', $contact['address_primary.state_province_id.name']);
}
$this->assertCount(2, $contacts);
$dataSource = $this->getDataSource();
Expand Down Expand Up @@ -1644,10 +1644,10 @@ public function testImportLocations(): void {
$this->assertCount(1, $contacts['Mum Jones']['im']);
$this->assertCount(0, $contacts['sis@example.com']['im']);
$this->assertCount(0, $contacts['Soccer Superstars']['im']);
$this->assertCount(1, $contacts['Susie Jones']['address']);
$this->assertCount(1, $contacts['Mum Jones']['address']);
$this->assertCount(1, $contacts['sis@example.com']['address']);
$this->assertCount(1, $contacts['Soccer Superstars']['address']);
$this->assertTrue($contacts['Susie Jones']['address_primary.id'] > 0);
$this->assertTrue($contacts['Mum Jones']['address_primary.id'] > 0);
$this->assertTrue($contacts['sis@example.com']['address_primary.id'] > 0);
$this->assertTrue($contacts['Soccer Superstars']['address_primary.id'] > 0);
$this->assertCount(1, $contacts['Susie Jones']['openid']);
}

Expand Down Expand Up @@ -2330,14 +2330,14 @@ private function validateMultiRowCsv(string $csv, array $mapper, string $field,
*/
public function getImportedContacts(): array {
return (array) Contact::get()
->addSelect('*', 'address_primary.*', 'address_primary.country_id.name', 'address_primary.state_province_id.name')
->addWhere('display_name', 'IN', [
'Susie Jones',
'Mum Jones',
'sis@example.com',
'Soccer Superstars',
])
->addChain('phone', Phone::get()->addWhere('contact_id', '=', '$id'))
->addChain('address', Address::get()->addWhere('contact_id', '=', '$id'))
->addChain('website', Website::get()->addWhere('contact_id', '=', '$id'))
->addChain('im', IM::get()->addWhere('contact_id', '=', '$id'))
->addChain('email', Email::get()->addWhere('contact_id', '=', '$id'))
Expand Down
11 changes: 8 additions & 3 deletions tests/phpunit/CRM/Contribute/Form/AdditionalPaymentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public function testAddPaymentUsingCreditCardForPartiallyPaidContribution(): voi
'Total Fee: $100.00',
'This Payment Amount: $70.00',
'Billing Name and Address',
'Vancouver, AE 1321312',
'Vancouver, BC 1321312',
'Visa',
'***********1111',
'Expires: May 2025',
Expand Down Expand Up @@ -249,7 +249,7 @@ public function testAddPaymentUsingCreditCardForPendingPayLaterContribution(): v
'Paid By: Credit Card',
'***********1111',
'Billing Name and Address',
'Vancouver, AE 1321312',
'Vancouver, BC 1321312',
'Expires: May 2025',

]);
Expand Down Expand Up @@ -364,6 +364,11 @@ public function submitPayment(float $amount, string $mode = NULL, bool $isEmailR
];
if ($mode) {
$_REQUEST['mode'] = $mode;
$stateProvinceBC = \Civi\Api4\StateProvince::get()
->addWhere('abbreviation', '=', 'BC')
->addWhere('country_id', '=', 1039)
->execute()
->single();
$submitParams += [
'payment_instrument_id' => array_search('Credit Card', $this->paymentInstruments, TRUE),
'payment_processor_id' => $this->paymentProcessorID,
Expand All @@ -372,7 +377,7 @@ public function submitPayment(float $amount, string $mode = NULL, bool $isEmailR
'cvv2' => 234,
'credit_card_type' => 'Visa',
'billing_city-5' => 'Vancouver',
'billing_state_province_id-5' => 1059,
'billing_state_province_id-5' => $stateProvinceBC['id'],
'billing_postal_code-5' => 1321312,
'billing_country_id-5' => 1228,
];
Expand Down
13 changes: 10 additions & 3 deletions tests/phpunit/api/v3/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,18 @@ public function testCreateAddressStateProvinceIDCorrectForCountry(): void {
// Now try it in Liberia
$params = $this->_params;
$params['sequential'] = 1;
// Liberia country id
$params['country_id'] = '1122';
$params['country_id'] = \Civi\Api4\Country::get()
->addWhere('name', '=', 'Liberia')
->execute()
->single()['id'];
$params['state_province_id'] = 'Maryland';
$address2 = $this->callAPISuccess('address', 'create', $params);
$this->assertEquals('3497', $address2['values'][0]['state_province_id']);
$liberia_maryland_id = \Civi\Api4\StateProvince::get()
->addWhere('country_id', '=', $params['country_id'])
->addWhere('name', '=', 'Maryland')
->execute()
->single()['id'];
$this->assertEquals($liberia_maryland_id, $address2['values'][0]['state_province_id']);
}

public function getSymbolicCountryStateExamples() {
Expand Down
9 changes: 5 additions & 4 deletions tests/phpunit/api/v4/Entity/ContactJoinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,13 @@ public function testCreateWithPrimaryAndBilling_Nigeria(): void {
'address_billing.country_id:abbr' => 'NG',
]);
$addr = Address::get(FALSE)
->addSelect('country_id:label', 'state_province_id:label')
->addWhere('contact_id', '=', $contact['id'])
->execute();
$this->assertCount(1, $addr);
->execute()
->single();
$this->assertEquals('Hello', $contact['address_billing.city']);
$this->assertEquals(3885, $contact['address_billing.state_province_id']);
$this->assertEquals(1157, $contact['address_billing.country_id']);
$this->assertEquals('Akwa Ibom', $addr['state_province_id:label']);
$this->assertEquals('Nigeria', $addr['country_id:label']);
$emails = Email::get(FALSE)
->addWhere('contact_id', '=', $contact['id'])
->execute();
Expand Down
Loading

0 comments on commit d2ce7f7

Please sign in to comment.