| 1 |
<?php
|
| 2 |
// $Id: country_code.test,v 1.25 2008/11/13 12:16:37 snpower Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Test file for the country code module.
|
| 7 |
*/
|
| 8 |
|
| 9 |
class CountryCodeTestCase extends DrupalWebTestCase {
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Implementation of getInfo().
|
| 13 |
*/
|
| 14 |
function getInfo() {
|
| 15 |
return array(
|
| 16 |
'name' => t('Country code'),
|
| 17 |
'description' => t('Test functionality of the country code module.'),
|
| 18 |
'group' => t('Country code')
|
| 19 |
);
|
| 20 |
}
|
| 21 |
|
| 22 |
/**
|
| 23 |
* Implementation of setUp().
|
| 24 |
*/
|
| 25 |
function setUp() {
|
| 26 |
parent::setUp('locale', 'translation', 'site_country', 'country_code');
|
| 27 |
$this->admin_user = $admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'administer site configuration', 'access administration pages', 'administer blocks'));
|
| 28 |
$this->translator = $translator = $this->drupalCreateUser(array('create story content', 'edit own story content', 'translate content'));
|
| 29 |
$this->visitor = $visitor = $this->drupalCreateUser();
|
| 30 |
$this->drupalLogin($this->admin_user);
|
| 31 |
$this->addLanguage('fr');
|
| 32 |
// Set the default country - note, this also adds it!
|
| 33 |
variable_set('site_country_default_country', 'ie');
|
| 34 |
}
|
| 35 |
|
| 36 |
/**
|
| 37 |
* Implementation of tearDown().
|
| 38 |
*/
|
| 39 |
function tearDown() {
|
| 40 |
$this->removeLanguage('fr');
|
| 41 |
$this->removeCountries(TRUE);
|
| 42 |
parent::tearDown();
|
| 43 |
}
|
| 44 |
|
| 45 |
/**
|
| 46 |
* Test adding, deleting and updating of countries.
|
| 47 |
*/
|
| 48 |
function testCountryCodeCountryAdmin() {
|
| 49 |
// Log in the admin user and visit the country code main settings page.
|
| 50 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 51 |
$this->assertResponse(200, t('Admin user has access to country code settings.'));
|
| 52 |
|
| 53 |
// Visit the country code settings pages.
|
| 54 |
$this->drupalGet('admin/settings/country-code');
|
| 55 |
$this->assertResponse(200, t('Admin user has access to country code settings.'));
|
| 56 |
|
| 57 |
// Ensure 'ie' country is present, is enabled and is the default.
|
| 58 |
// This is the country set in the setUp() as the site default.
|
| 59 |
$this->assertText(t('Ireland'));
|
| 60 |
$country = country_code_country_load('ie');
|
| 61 |
$this->assertTrue($country['country'] == 'ie', t('Site default country is present in country_code_country table.'));
|
| 62 |
$this->assertTrue($country['enabled'] == 1, t('Site default country is enabled.'));
|
| 63 |
$this->assertTrue(variable_get('site_country_default_country', '') == 'ie', t('Site default country is set correctly.'));
|
| 64 |
|
| 65 |
|
| 66 |
// Add countries.
|
| 67 |
$this->clickLink(t('Add country'));
|
| 68 |
$this->assertResponse('200', t('Admin user has access to add countries.'));
|
| 69 |
|
| 70 |
$this->addCountry('ca', TRUE);
|
| 71 |
$this->addCountry('us');
|
| 72 |
$this->addCountry('fr', FALSE); // Add a disabled country.
|
| 73 |
|
| 74 |
// Check we can enable and disable the country 'France' via the overview
|
| 75 |
// page.
|
| 76 |
$this->changeCountryStatus('fr', TRUE); // Enable it.
|
| 77 |
$this->changeCountryStatus('fr', FALSE); // Disable it.
|
| 78 |
|
| 79 |
// Check we can change the default country via the overview page.
|
| 80 |
$this->changeDefaultCountry('us');
|
| 81 |
// Try to disable a default country.
|
| 82 |
$this->changeCountryStatus('us', FALSE, TRUE);
|
| 83 |
|
| 84 |
// Check we can enable and disable the country 'France' via the edit page.
|
| 85 |
$this->drupalGet('admin/settings/country-code-country/fr');
|
| 86 |
$this->assertResponse(200, t('Admin user has access to edit country code settings.'));
|
| 87 |
$this->drupalPost(NULL, array('enabled' => 1), t('Save'));
|
| 88 |
$country = country_code_country_load('fr');
|
| 89 |
$this->assertTrue($country['enabled'] == 1, t('Country successfully enabled.'));
|
| 90 |
|
| 91 |
$this->drupalGet('admin/settings/country-code-country/fr');
|
| 92 |
$this->drupalPost(NULL, array('enabled' => FALSE), t('Save'));
|
| 93 |
$country = country_code_country_load('fr');
|
| 94 |
$this->assertTrue($country['enabled'] == 0, t('Country successfully disabled.'));
|
| 95 |
|
| 96 |
// Check we can remove a country.
|
| 97 |
$this->removeCountry('fr');
|
| 98 |
}
|
| 99 |
|
| 100 |
|
| 101 |
/**
|
| 102 |
* Test the main country code configuration page.
|
| 103 |
*
|
| 104 |
* Tests for changing default user's country/language option have been moved
|
| 105 |
* to testUserEditForm().
|
| 106 |
* TODO: split this up so we're also testing the functionality.
|
| 107 |
*/
|
| 108 |
function testCountryCodeGeneralAdmin() {
|
| 109 |
// Test changing of fallback country.
|
| 110 |
$this->changeCountryFallback('default');
|
| 111 |
$this->changeCountryFallback('xx');
|
| 112 |
|
| 113 |
// Test changing of country by path option.
|
| 114 |
$this->changeCountryPathOption(1);
|
| 115 |
$this->changeCountryPathOption(0);
|
| 116 |
|
| 117 |
// Test changing of user's browser language option.
|
| 118 |
$this->changeUserBrowserLanguageOption(0);
|
| 119 |
$this->changeUserBrowserLanguageOption(1);
|
| 120 |
|
| 121 |
// Test changing of translation links on node option.
|
| 122 |
$this->changeNodeTranslationLinksOption(0);
|
| 123 |
$this->changeNodeTranslationLinksOption(1);
|
| 124 |
}
|
| 125 |
|
| 126 |
/**
|
| 127 |
* Test user default country settings.
|
| 128 |
*/
|
| 129 |
function testUserDefaultCountry() {
|
| 130 |
|
| 131 |
// Enable countries and languages.
|
| 132 |
$this->changeUserDefaultCountryOption(1);
|
| 133 |
$this->addCountry('ca');
|
| 134 |
$this->addCountry('us');
|
| 135 |
$this->addLanguage('es');
|
| 136 |
$this->addCountryLanguage('en', 'ca');
|
| 137 |
$this->addCountryLanguage('fr', 'ca');
|
| 138 |
$this->addCountryLanguage('en', 'us');
|
| 139 |
$this->addCountryLanguage('es', 'us');
|
| 140 |
|
| 141 |
// Enable the language switcher block.
|
| 142 |
$this->drupalGet('admin/build/block');
|
| 143 |
$this->assertText(t('Language switcher'));
|
| 144 |
$edit = array();
|
| 145 |
$edit['locale_0[region]'] = 'left';
|
| 146 |
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
| 147 |
$this->assertText(t('The block settings have been updated.'), t('Language switcher block successfully moved to left region.'));
|
| 148 |
|
| 149 |
// The language switcher block doesn't show up without path negotiation.
|
| 150 |
$edit = array();
|
| 151 |
$edit['language_negotiation'] = 15;
|
| 152 |
$this->drupalPost('admin/settings/language/configure', $edit, t('Save settings'));
|
| 153 |
|
| 154 |
// Visit the front page with no country set, ensure all languages are available.
|
| 155 |
$this->drupalGet('node');
|
| 156 |
$this->assertText(t('English'), t('English found in language switcher block'));
|
| 157 |
$this->assertNoText(t('English (us)'), t('US English not found in language switcher block'));
|
| 158 |
$this->assertText(t('Français'), t('French found in language switcher block'));
|
| 159 |
$this->assertNoText(t('Français (ca)'), t('Canadian French not found in language switcher block'));
|
| 160 |
$this->assertText(t('Español'), t('Spanish found in language switcher block'));
|
| 161 |
|
| 162 |
// Change the user country default to Canada.
|
| 163 |
$this->drupalGet('user/' . $this->admin_user->uid . '/edit');
|
| 164 |
|
| 165 |
$edit = array();
|
| 166 |
$edit['country_code'] = 'ca';
|
| 167 |
$this->drupalPost('user/' . $this->admin_user->uid . '/edit', $edit, t('Save'));
|
| 168 |
|
| 169 |
// Assert that languages for Canada appear. And that languages for other
|
| 170 |
// countries don't appear.
|
| 171 |
|
| 172 |
$this->drupalGet('node');
|
| 173 |
$this->assertText(t('English'), t('English found in language switcher block.'));
|
| 174 |
$this->assertNoText(t('English (ca)'), t('Canadian English not found in Language switcher block.'));
|
| 175 |
$this->assertNoText(t('English (us)'), t('US English not found in language switcher block.'));
|
| 176 |
$this->assertText(t('Français'), t('French found in language switcher block.'));
|
| 177 |
$this->assertNoText(t('Français (ca)'), t('Canadian French not found in language switcher block.'));
|
| 178 |
$this->assertNoText(t('Español'), t('Spanish not found in language switcher block.'));
|
| 179 |
}
|
| 180 |
|
| 181 |
/**
|
| 182 |
* Enable three countries, then assign languages to those countries.
|
| 183 |
*/
|
| 184 |
function testCountryLanguages() {
|
| 185 |
// Add countries.
|
| 186 |
$this->addCountry('ca');
|
| 187 |
$this->addCountry('us');
|
| 188 |
$this->addCountry('fr', FALSE); // Add a disabled country.
|
| 189 |
|
| 190 |
// Enable English for Canada.
|
| 191 |
$this->addCountryLanguage('en', 'ca');
|
| 192 |
|
| 193 |
// Enable French for Canada.
|
| 194 |
$this->addCountryLanguage('fr', 'ca');
|
| 195 |
|
| 196 |
// Enable English for United States.
|
| 197 |
$this->addCountryLanguage('en', 'us');
|
| 198 |
|
| 199 |
// Enable French for France, so we can check disabled countries can still
|
| 200 |
// have languages added.
|
| 201 |
$this->addCountryLanguage('fr', 'fr');
|
| 202 |
|
| 203 |
// Set Story content type to use multilingual support with translation.
|
| 204 |
$this->drupalGet('admin/content/node-type/story');
|
| 205 |
$edit = array();
|
| 206 |
$edit['language_content_type'] = 2;
|
| 207 |
|
| 208 |
$this->drupalPost('admin/content/node-type/story', $edit, t('Save content type'));
|
| 209 |
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Story')), t('Story content type has been updated.'));
|
| 210 |
}
|
| 211 |
|
| 212 |
/**
|
| 213 |
* Test country switcher block.
|
| 214 |
*/
|
| 215 |
function testCountrySwitcherBlock() {
|
| 216 |
// Add a some countries.
|
| 217 |
$this->addCountry('ca');
|
| 218 |
$this->addCountry('us');
|
| 219 |
|
| 220 |
// Get list of enabled countries.
|
| 221 |
$countries = country_code_countries(TRUE, TRUE);
|
| 222 |
|
| 223 |
// Visit the block administration page.
|
| 224 |
$this->drupalGet('admin/build/block');
|
| 225 |
$this->assertResponse(200, t('Admin user has access to block configuration page.'));
|
| 226 |
|
| 227 |
// Ensure 'country switcher' block appears and enable it.
|
| 228 |
$this->assertRaw(t('Country switcher'), t('Country switcher block installed.'));
|
| 229 |
$edit = array();
|
| 230 |
$edit['country_code_0[region]'] = 'left';
|
| 231 |
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
|
| 232 |
$this->assertText(t('The block settings have been updated.'), t('Country switcher block successfully moved to left region.'));
|
| 233 |
|
| 234 |
// Ensure countries appear in the block.
|
| 235 |
$this->assertRaw('href="' . url('ca/admin/build/block') . '"', t('Country switcher block visible.'));
|
| 236 |
|
| 237 |
// Ensure we can switch countries.
|
| 238 |
$this->clickLink($countries['ca']->name);
|
| 239 |
|
| 240 |
// Check the URL to confirm.
|
| 241 |
$this->assertTrue(strpos($this->getURL(), 'ca/admin/build/block') == TRUE, t('Switched countries successfully.'));
|
| 242 |
|
| 243 |
// Ensure we can switch again. Need a second switch to ensure we weren't
|
| 244 |
// previously viewing the page with the other country set.
|
| 245 |
$this->clickLink($countries['us']->name);
|
| 246 |
|
| 247 |
// Check the URL to confirm.
|
| 248 |
$this->assertTrue(strpos($this->getURL(), 'us/admin/build/block') == TRUE, t('Switched countries successfully.'));
|
| 249 |
}
|
| 250 |
|
| 251 |
/**
|
| 252 |
* Test changes to user edit form.
|
| 253 |
*
|
| 254 |
* TODO: check user default country / language options actually work.
|
| 255 |
*/
|
| 256 |
function testUserEditForm() {
|
| 257 |
// Add some countries and languages.
|
| 258 |
$this->addCountry('ca');
|
| 259 |
$this->addCountry('us');
|
| 260 |
$this->addCountryLanguage('en', 'ca');
|
| 261 |
$this->addCountryLanguage('fr', 'ca');
|
| 262 |
$this->addCountryLanguage('en', 'us');
|
| 263 |
|
| 264 |
// Visit the user settings page.
|
| 265 |
$this->drupalGet('user/' . $this->admin_user->uid . '/edit');
|
| 266 |
$this->assertResponse(200, t('User can edit their profile.'));
|
| 267 |
|
| 268 |
// Ensure language selection appears by default, and country doesn't.
|
| 269 |
$this->assertRaw('<fieldset><legend>Language settings</legend>', t('Language settings appear by default.'));
|
| 270 |
$this->assertNoRaw('<fieldset><legend>Country settings</legend>', t("Country settings don't appear by default."));
|
| 271 |
|
| 272 |
// Enable country setting and ensure user can modify their default country.
|
| 273 |
$this->changeUserDefaultCountryOption(1); // Enable country option.
|
| 274 |
$this->drupalGet('user/' . $this->admin_user->uid . '/edit');
|
| 275 |
$this->assertRaw('<fieldset><legend>Country settings</legend>', t('Country settings appear.'));
|
| 276 |
|
| 277 |
// Change user's default country.
|
| 278 |
$this->changeUserDefaultCountry($this->admin_user, 'xx');
|
| 279 |
$this->changeUserDefaultCountry($this->admin_user, 'ca');
|
| 280 |
|
| 281 |
// Change user's default language - need 2 separate posts as Canadian
|
| 282 |
// langauges not available until default country has changed.
|
| 283 |
$this->changeUserDefaultLanguage($this->admin_user, 'fr-ca');
|
| 284 |
|
| 285 |
// Disable language option and ensure it doesn't appear on the user edit
|
| 286 |
// profile form.
|
| 287 |
$this->changeUserDefaultLanguageOption(0); // Disable language option.
|
| 288 |
$this->drupalGet('user/' . $this->admin_user->uid . '/edit');
|
| 289 |
$this->assertNoRaw('<fieldset><legend>Language settings</legend>', t("Language settings don't appear."));
|
| 290 |
|
| 291 |
// Restore language / country settings.
|
| 292 |
$this->changeUserDefaultCountryOption(0); // Disable country option.
|
| 293 |
$this->changeUserDefaultLanguageOption(1); // Enable language option.
|
| 294 |
$this->drupalGet('user/' . $this->admin_user->uid . '/edit');
|
| 295 |
$this->assertRaw('<fieldset><legend>Language settings</legend>', t('Language settings appear.'));
|
| 296 |
$this->assertNoRaw('<fieldset><legend>Country settings</legend>', t("Country settings don't appear."));
|
| 297 |
}
|
| 298 |
|
| 299 |
/**
|
| 300 |
* Enable a country.
|
| 301 |
*
|
| 302 |
* @param $country_code
|
| 303 |
* A two digit country code.
|
| 304 |
* @param $enable_country
|
| 305 |
* Whether or not the country should be enabled.
|
| 306 |
*/
|
| 307 |
function addCountry($country_code, $enable_country = TRUE) {
|
| 308 |
$edit = array();
|
| 309 |
$edit['country'] = $country_code;
|
| 310 |
$edit['enabled'] = $enable_country;
|
| 311 |
$this->drupalPost('admin/settings/country-code/add', $edit, t('Add country'));
|
| 312 |
|
| 313 |
// Load the country from the database.
|
| 314 |
$country = country_code_country_load($country_code);
|
| 315 |
$this->assertTrue($country['country'] == $country_code, t('Country code returned from database.'));
|
| 316 |
$this->drupalGet('admin/settings/country-code');
|
| 317 |
$this->assertText($country['name'], t('Country is displayed in overview.'));
|
| 318 |
$this->assertTrue($country['enabled'] == $enable_country, t('Country status set successfully.'));
|
| 319 |
}
|
| 320 |
|
| 321 |
/**
|
| 322 |
* Enable a country language.
|
| 323 |
*
|
| 324 |
* @param $language_code
|
| 325 |
* A two digit language code.
|
| 326 |
* @param $country_code
|
| 327 |
* A two digit country code.
|
| 328 |
* @param $create_country_language
|
| 329 |
* Whether or not a new country language should be created.
|
| 330 |
*/
|
| 331 |
function addCountryLanguage($language_code, $country_code, $create_country_language = TRUE) {
|
| 332 |
$edit = array();
|
| 333 |
$edit['language'] = $language_code;
|
| 334 |
$this->drupalPost('admin/settings/country-code-country/' . $country_code . '/languages/add', $edit, t('Add language'));
|
| 335 |
$country_language = $language_code . '-' . $country_code;
|
| 336 |
$this->assertTrue(country_code_language_exists($country_language), t('New country-language was enabled.'));
|
| 337 |
}
|
| 338 |
|
| 339 |
/**
|
| 340 |
* Enable the specified language if it has not been already.
|
| 341 |
*
|
| 342 |
* @param string $language_code
|
| 343 |
* The language code to enable.
|
| 344 |
*/
|
| 345 |
function addLanguage($language_code) {
|
| 346 |
// Check to make sure that language has not already been installed.
|
| 347 |
$this->drupalGet('admin/settings/language');
|
| 348 |
|
| 349 |
if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') === FALSE) {
|
| 350 |
// Doesn't have language installed so add it.
|
| 351 |
$edit = array();
|
| 352 |
$edit['langcode'] = $language_code;
|
| 353 |
$this->drupalPost('admin/settings/language/add', $edit, t('Add language'));
|
| 354 |
|
| 355 |
$languages = language_list('language', TRUE); // Make sure not using cached version.
|
| 356 |
$this->assertTrue(array_key_exists($language_code, $languages), t('Language was installed successfully.'));
|
| 357 |
|
| 358 |
if (array_key_exists($language_code, $languages)) {
|
| 359 |
$this->assertRaw(t('The language %language has been created and can now be used.', array('%language' => $languages[$language_code]->name)), t('Language has been created.'));
|
| 360 |
}
|
| 361 |
}
|
| 362 |
else {
|
| 363 |
// Ensure that it is enabled.
|
| 364 |
$this->drupalPost(NULL, array('enabled[' . $language_code . ']' => TRUE), t('Save configuration'));
|
| 365 |
|
| 366 |
$this->assertRaw(t('Configuration saved.'), t('Language %language successfully enabled.', array('%language' => $language_code)));
|
| 367 |
}
|
| 368 |
}
|
| 369 |
|
| 370 |
/**
|
| 371 |
* Disable the specified language if it has not been already.
|
| 372 |
*
|
| 373 |
* @param string $language_code
|
| 374 |
* The language code to disable.
|
| 375 |
*/
|
| 376 |
function disableLanguage($language_code) {
|
| 377 |
// Check to make sure that language has not already been removed.
|
| 378 |
$this->drupalGet('admin/settings/language');
|
| 379 |
|
| 380 |
if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') == TRUE) {
|
| 381 |
// Language is installed, so disable it.
|
| 382 |
$this->drupalPost(NULL, array('enabled[' . $language_code . ']' => FALSE), t('Save configuration'));
|
| 383 |
$this->assertRaw(t('Configuration saved.'), t('Language %language successfully disabled.', array('%language' => $language_code)));
|
| 384 |
}
|
| 385 |
}
|
| 386 |
|
| 387 |
/**
|
| 388 |
* Remove the specified language if it has not been already.
|
| 389 |
*
|
| 390 |
* @param string $language_code
|
| 391 |
* The language code to remove.
|
| 392 |
*/
|
| 393 |
function removeLanguage($language_code) {
|
| 394 |
// Check to make sure that language has not already been removed.
|
| 395 |
$this->drupalGet('admin/settings/language');
|
| 396 |
|
| 397 |
// Check if we can disable the language first.
|
| 398 |
$this->disableLanguage($language_code);
|
| 399 |
|
| 400 |
if (strpos($this->drupalGetContent(), 'enabled[' . $language_code . ']') == TRUE) {
|
| 401 |
$languages = language_list('language', TRUE); // Make sure not using cached version.
|
| 402 |
$this->drupalGet('admin/settings/language/delete/' . $language_code);
|
| 403 |
$this->drupalPost(NULL, array(), t('Delete'));
|
| 404 |
$this->assertRaw(t('The language %language has been removed.', array('%language' => $languages[$language_code]->name)), t('Language %language successfully deleted.', array('%language' => $languages[$language_code]->name)));
|
| 405 |
}
|
| 406 |
}
|
| 407 |
|
| 408 |
/**
|
| 409 |
* Change the status of the specified country.
|
| 410 |
*
|
| 411 |
* @param string $country_code
|
| 412 |
* The country code to disable.
|
| 413 |
* @param string $status
|
| 414 |
* The country's new status.
|
| 415 |
* @param string $default
|
| 416 |
* Whether or not the country is the default country.
|
| 417 |
*/
|
| 418 |
function changeCountryStatus($country_code, $status, $default = FALSE) {
|
| 419 |
// Check to make sure that country exists.
|
| 420 |
$this->drupalGet('admin/settings/country-code');
|
| 421 |
if (strpos($this->drupalGetContent(), 'enabled[' . $country_code . ']') == TRUE) {
|
| 422 |
$this->drupalPost(NULL, array('enabled[' . $country_code . ']' => $status), t('Save configuration'));
|
| 423 |
$country = country_code_country_load($country_code);
|
| 424 |
if ($default) {
|
| 425 |
$this->assertTrue($country['enabled'] == 1, $status ? t('Country %country successfully enabled.', array('%country' => $country['name'])) : t('Country %country successfully not disabled.', array('%country' => $country['name'])));
|
| 426 |
}
|
| 427 |
else {
|
| 428 |
$this->assertTrue($country['enabled'] == $status, $status ? t('Country %country successfully enabled.', array('%country' => $country['name'])) : t('Country %country successfully disabled.', array('%country' => $country['name'])));
|
| 429 |
}
|
| 430 |
}
|
| 431 |
}
|
| 432 |
|
| 433 |
/**
|
| 434 |
* Change the default country to be the specified country.
|
| 435 |
*
|
| 436 |
* @param string $country_code
|
| 437 |
* The country code to make the default.
|
| 438 |
*/
|
| 439 |
function changeDefaultCountry($country_code) {
|
| 440 |
// Check to make sure that country exists.
|
| 441 |
$this->drupalGet('admin/settings/country-code');
|
| 442 |
if (strpos($this->drupalGetContent(), 'enabled[' . $country_code . ']') == TRUE) {
|
| 443 |
$this->drupalPost(NULL, array('site_default' => $country_code), t('Save configuration'));
|
| 444 |
$this->assertRaw('name="site_default" value="' . $country_code . '" checked="checked"', t('Default country successfully set to %country.', array('%country' => $country_code)));
|
| 445 |
}
|
| 446 |
}
|
| 447 |
|
| 448 |
|
| 449 |
/**
|
| 450 |
* Remove the specified country if it has not been already.
|
| 451 |
*
|
| 452 |
* @param string $country_code
|
| 453 |
* The country code to remove.
|
| 454 |
* @param string $force
|
| 455 |
* Force removal of all countries for tearDown().
|
| 456 |
*/
|
| 457 |
function removeCountry($country_code, $force = FALSE) {
|
| 458 |
// Check to make sure that country has not already been removed.
|
| 459 |
$this->drupalGet('admin/settings/country-code');
|
| 460 |
|
| 461 |
if (strpos($this->drupalGetContent(), 'enabled[' . $country_code . ']') == TRUE) {
|
| 462 |
$country_count = count(country_code_countries(FALSE, TRUE));
|
| 463 |
$country = country_code_country_load($country_code);
|
| 464 |
$this->drupalGet('admin/settings/country-code/delete/' . $country_code);
|
| 465 |
$this->drupalPost(NULL, array(), t('Delete'));
|
| 466 |
if ($country_count == 1) {
|
| 467 |
$this->assertRaw(t('The country %country could not be removed as it is the default and last country.', array('%country' => $country['name'])), t('Country %country successfully not deleted.', array('%country' => $country_code)));
|
| 468 |
if ($force) {
|
| 469 |
db_query('DELETE FROM {country_code_country}');
|
| 470 |
}
|
| 471 |
}
|
| 472 |
else {
|
| 473 |
$this->assertRaw(t('The country %country has been removed.', array('%country' => $country['name'])), t('Country %country successfully deleted.', array('%country' => $country_code)));
|
| 474 |
}
|
| 475 |
}
|
| 476 |
}
|
| 477 |
|
| 478 |
/**
|
| 479 |
* Remove all the configured countries.
|
| 480 |
*
|
| 481 |
* @param string $force
|
| 482 |
* Force removal of all countries for tearDown().
|
| 483 |
*/
|
| 484 |
function removeCountries($force = FALSE) {
|
| 485 |
// Get list of all configured countries.
|
| 486 |
$countries = country_code_countries(TRUE);
|
| 487 |
foreach ($countries as $country_code => $country) {
|
| 488 |
$this->removeCountry($country_code, $force);
|
| 489 |
}
|
| 490 |
}
|
| 491 |
|
| 492 |
|
| 493 |
/**
|
| 494 |
* Change the country fallback option.
|
| 495 |
*
|
| 496 |
* @param string $fallback
|
| 497 |
* 'xx' for Global, 'default' for Default country.
|
| 498 |
*/
|
| 499 |
function changeCountryFallback($fallback) {
|
| 500 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 501 |
$this->drupalPost(NULL, array('country_code_fallback' => $fallback), t('Save configuration'));
|
| 502 |
$current_setting = variable_get('country_code_fallback', 'xx');
|
| 503 |
$this->assertTrue($current_setting == $fallback, t('Country fallback option changed successfully.'));
|
| 504 |
}
|
| 505 |
|
| 506 |
/**
|
| 507 |
* Change the user default country option.
|
| 508 |
*
|
| 509 |
* @param string $enabled
|
| 510 |
* Whether or not the user can specify a default country in their account.
|
| 511 |
*/
|
| 512 |
function changeUserDefaultCountryOption($enabled) {
|
| 513 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 514 |
$this->drupalPost(NULL, array('country_code_user_country' => $enabled), t('Save configuration'));
|
| 515 |
$current_setting = variable_get('country_code_user_country', 0);
|
| 516 |
$this->assertTrue($current_setting == $enabled, $enabled ? t('User default country option successfully enabled.') : t('User default country option successfully disabled.'));
|
| 517 |
}
|
| 518 |
|
| 519 |
/**
|
| 520 |
* Set the country by path for initial or external links.
|
| 521 |
*
|
| 522 |
* @param string $enabled
|
| 523 |
* Whether or not this feature is enabled.
|
| 524 |
*/
|
| 525 |
function changeCountryPathOption($enabled) {
|
| 526 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 527 |
$this->drupalPost(NULL, array('country_code_external' => $enabled), t('Save configuration'));
|
| 528 |
$current_setting = variable_get('country_code_external', 0);
|
| 529 |
$this->assertTrue($current_setting == $enabled, $enabled ? t('Country by path option successfully enabled.') : t('Country by path option successfully disabled.'));
|
| 530 |
}
|
| 531 |
|
| 532 |
/**
|
| 533 |
* Change the user default language option.
|
| 534 |
*
|
| 535 |
* @param string $enabled
|
| 536 |
* Whether or not the user can specify a default language in their account.
|
| 537 |
*/
|
| 538 |
function changeUserDefaultLanguageOption($enabled) {
|
| 539 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 540 |
$this->drupalPost(NULL, array('country_code_user_language' => $enabled), t('Save configuration'));
|
| 541 |
$current_setting = variable_get('country_code_user_language', 1);
|
| 542 |
$this->assertTrue($current_setting == $enabled, $enabled ? t('User default language option successfully enabled.') : t('User default language option successfully disabled.'));
|
| 543 |
}
|
| 544 |
|
| 545 |
/**
|
| 546 |
* Change the user browser language option.
|
| 547 |
*
|
| 548 |
* @param string $enabled
|
| 549 |
* Whether or not the user's browser language is taken into consideration.
|
| 550 |
*/
|
| 551 |
function changeUserBrowserLanguageOption($enabled) {
|
| 552 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 553 |
$this->drupalPost(NULL, array('country_code_browser_language' => $enabled), t('Save configuration'));
|
| 554 |
$current_setting = variable_get('country_code_browser_language', 1);
|
| 555 |
$this->assertTrue($current_setting == $enabled, $enabled ? t('User browser language option successfully enabled.') : t('User browser language option successfully disabled.'));
|
| 556 |
}
|
| 557 |
|
| 558 |
/**
|
| 559 |
* Control whether or not links to translations appear in the node links.
|
| 560 |
*
|
| 561 |
* @param string $enabled
|
| 562 |
* Whether or not the translation links appear on nodes.
|
| 563 |
*/
|
| 564 |
function changeNodeTranslationLinksOption($enabled) {
|
| 565 |
$this->drupalGet('admin/settings/country-code/configure');
|
| 566 |
$this->drupalPost(NULL, array('country_code_node_links' => $enabled), t('Save configuration'));
|
| 567 |
$current_setting = variable_get('country_code_node_links', 1);
|
| 568 |
$this->assertTrue($current_setting == $enabled, $enabled ? t('Translation links option successfully enabled.') : t('Translation links option successfully disabled.'));
|
| 569 |
}
|
| 570 |
|
| 571 |
/**
|
| 572 |
* Modify the user's default language.
|
| 573 |
*
|
| 574 |
* Requires the option to be enabled at admin/settings/country-code/configure
|
| 575 |
* @param string $user
|
| 576 |
* The user object to modify.
|
| 577 |
* @param string $language
|
| 578 |
* The language code to set.
|
| 579 |
*/
|
| 580 |
function changeUserDefaultLanguage($user, $language) {
|
| 581 |
$edit = array();
|
| 582 |
$edit['language'] = $language;
|
| 583 |
$this->drupalPost('user/' . $user->uid . '/edit', $edit, t('Save'));
|
| 584 |
$updated_user = user_load($user->uid);
|
| 585 |
$this->assertTrue($updated_user->language == $language, t("User's default language successfully updated to %language.", array('%language' => $language)));
|
| 586 |
}
|
| 587 |
|
| 588 |
/**
|
| 589 |
* Modify the user's default country.
|
| 590 |
*
|
| 591 |
* Requires the option to be enabled at admin/settings/country-code/configure
|
| 592 |
* @param string $user
|
| 593 |
* The user object to modify.
|
| 594 |
* @param string $country_code
|
| 595 |
* The country code to set.
|
| 596 |
*/
|
| 597 |
function changeUserDefaultCountry($user, $country_code) {
|
| 598 |
$edit = array();
|
| 599 |
$edit['country_code'] = $country_code;
|
| 600 |
$this->drupalPost('user/' . $user->uid . '/edit', $edit, t('Save'));
|
| 601 |
$updated_user = user_load($user->uid);
|
| 602 |
$this->assertTrue($updated_user->country_code == $country_code, t("User's default country successfully updated to %country.", array('%country' => $country_code)));
|
| 603 |
}
|
| 604 |
|
| 605 |
/**
|
| 606 |
* Create a page in the specified language.
|
| 607 |
*
|
| 608 |
* @param string $title
|
| 609 |
* Title of page in specified language.
|
| 610 |
* @param string $body
|
| 611 |
* Body of page in specified language.
|
| 612 |
* @param string $language
|
| 613 |
* Language code.
|
| 614 |
*/
|
| 615 |
function createPage($title, $body, $language) {
|
| 616 |
$edit = array();
|
| 617 |
$edit['title'] = $title;
|
| 618 |
$edit['body'] = $body;
|
| 619 |
$edit['language'] = $language;
|
| 620 |
$this->drupalPost('node/add/page', $edit, t('Save'));
|
| 621 |
$this->assertRaw(t('Page %title has been created.', array('%title' => $edit['title'])), t('Page created.'));
|
| 622 |
|
| 623 |
// Check to make sure the node was created.
|
| 624 |
$node = node_load(array('title' => $edit['title']));
|
| 625 |
$this->assertTrue($node, t('Node found in database.'));
|
| 626 |
|
| 627 |
return $node;
|
| 628 |
}
|
| 629 |
|
| 630 |
/**
|
| 631 |
* Create a translation for the specified page in the specified language.
|
| 632 |
*
|
| 633 |
* @param integer $nid
|
| 634 |
* Node id of page to create translation for.
|
| 635 |
* @param string $title
|
| 636 |
* Title of page in specified language.
|
| 637 |
* @param string $body
|
| 638 |
* Body of page in specified language.
|
| 639 |
* @param string $language
|
| 640 |
* Language code.
|
| 641 |
*/
|
| 642 |
function createTranslation($nid, $title, $body, $language) {
|
| 643 |
$this->drupalGet('node/add/page', array('query' => array('translation' => $nid, 'language' => $language)));
|
| 644 |
|
| 645 |
$edit = array();
|
| 646 |
$edit['title'] = $title;
|
| 647 |
$edit['body'] = $body;
|
| 648 |
$this->drupalPost(NULL, $edit, t('Save'));
|
| 649 |
$this->assertRaw(t('Page %title has been created.', array('%title' => $edit['title'])), t('Translation created.'));
|
| 650 |
|
| 651 |
// Check to make sure that translation was successful.
|
| 652 |
$node = node_load(array('title' => $edit['title']));
|
| 653 |
$this->assertTrue($node, t('Node found in database.'));
|
| 654 |
|
| 655 |
return $node;
|
| 656 |
}
|
| 657 |
}
|