- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
<?php
// $Id$
2009-02-13 00:45:18 +00:00
/**
* @file
* Tests for Locale module.
2009-02-22 20:55:18 +00:00
*
2009-02-13 00:45:18 +00:00
* The test file includes:
2009-02-22 20:55:18 +00:00
* - a functional test for the language configuration forms;
* - functional tests for the translation functionalities, including searching;
* - a functional test for the PO files import feature, including validation;
* - functional tests for translations and templates export feature;
* - functional tests for the uninstall process;
* - a functional test for the language switching feature;
* - a functional test for a user's ability to change their default language;
* - a functional test for configuring a different path alias per language;
* - a functional test for configuring a different path alias per language;
* - a functional test for multilingual support by content type and on nodes.
2009-02-13 00:45:18 +00:00
*/
2009-02-22 20:55:18 +00:00
/**
* Functional tests for the language configuration forms.
*/
class LocaleConfigurationTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-22 20:55:18 +00:00
return array(
'name' => t('Language configuration'),
'description' => t('Adds a new locale and tests changing its status and the default language.'),
'group' => t('Locale'),
);
}
function setUp() {
parent::setUp('locale');
}
/**
* Functional tests for adding, editing and deleting languages.
*/
function testLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
$this->drupalLogin($admin_user);
// Add predefined language.
$edit = array(
'langcode' => 'fr',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add language'));
2009-02-22 20:55:18 +00:00
$this->assertText('fr', t('Language added successfully.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
// Add custom language.
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
2009-02-22 20:55:18 +00:00
// The English name for the language.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
2009-02-22 20:55:18 +00:00
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertText($langcode, t('Language code found.'));
$this->assertText($name, t('Name found.'));
$this->assertText($native, t('Native found.'));
$this->assertText($native, t('Test language added.'));
// Check if we can change the default language.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language';
2009-02-22 20:55:18 +00:00
$this->drupalGet($path);
// Set up the raw HTML strings we need to search for.
$elements = $this->xpath('//input[@id="edit-site-default-en"]');
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('English is the default language.'));
// Change the default language.
$edit = array(
'site_default' => $langcode,
);
$this->drupalPost($path, $edit, t('Save configuration'));
$elements = $this->xpath('//input[@id="edit-site-default-en"]');
$this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), t('Default language updated.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
// Ensure we can't delete the default language.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language/delete/' . $langcode;
2009-02-22 20:55:18 +00:00
$this->drupalGet($path);
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('The default language cannot be deleted.'), t('Failed to delete the default language.'));
// Check if we can disable a language.
$edit = array(
'enabled[en]' => FALSE,
);
$this->drupalPost($path, $edit, t('Save configuration'));
$elements = $this->xpath('//input[@id="edit-enabled-en"]');
$this->assertTrue(isset($elements[0]) && empty($elements[0]['checked']), t('Language disabled.'));
// Set disabled language to be the default and ensure it is re-enabled.
$edit = array(
'site_default' => 'en',
);
$this->drupalPost($path, $edit, t('Save configuration'));
$elements = $this->xpath('//input[@id="edit-enabled-en"]');
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Default language re-enabled.'));
// Ensure 'edit' link works.
$this->clickLink(t('edit'));
$this->assertTitle(t('Edit language | Drupal'), t('Page title is "Edit language".'));
// Edit a language.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language/edit/' . $langcode;
2009-02-22 20:55:18 +00:00
$name = $this->randomName(16);
$edit = array(
'name' => $name,
);
$this->drupalPost($path, $edit, t('Save language'));
$this->assertRaw($name, t('The language has been updated.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
// Ensure 'delete' link works.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language';
2009-02-22 20:55:18 +00:00
$this->drupalGet($path);
$this->clickLink(t('delete'));
$this->assertText(t('Are you sure you want to delete the language'), t('"delete" link is correct.'));
// Delete the language.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language/delete/' . $langcode;
2009-02-22 20:55:18 +00:00
$this->drupalGet($path);
// First test the 'cancel' link.
$this->clickLink(t('Cancel'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertRaw($name, t('The language was not deleted.'));
// Delete the language for real. This a confirm form, we do not need any
// fields changed.
$this->drupalPost($path, array(), t('Delete'));
// We need raw here because %locale will add HTML.
$this->assertRaw(t('The language %locale has been removed.', array('%locale' => $name)), t('The test language has been removed.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
// Reload to remove $name.
$this->drupalGet($path);
$this->assertNoText($langcode, t('Language code not found.'));
$this->assertNoText($name, t('Name not found.'));
$this->assertNoText($native, t('Native not found.'));
// Ensure we can't delete the English language.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language/delete/en';
2009-02-22 20:55:18 +00:00
$this->drupalGet($path);
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('The English language cannot be deleted.'), t('Failed to delete English language.'));
$this->drupalLogout();
}
}
2009-02-13 00:45:18 +00:00
/**
* Functional test for string translation and validation.
*/
class LocaleTranslationFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
return array(
2009-02-22 20:55:18 +00:00
'name' => t('String translate, search and validate'),
'description' => t('Adds a new locale and translates its name. Checks the validation of translation strings and search results.'),
'group' => t('Locale'),
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
);
}
function setUp() {
parent::setUp('locale');
}
2009-02-13 00:45:18 +00:00
/**
* Adds a language and tests string translation by users with the appropriate permissions.
*/
function testStringTranslation() {
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
// User to translate and delete string.
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// The English name for the language. This will be translated.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
2009-02-22 20:55:18 +00:00
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// This is the language indicator on the translation search screen for
// untranslated strings. Copied straight from locale.inc.
$language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
// This will be the translation of $name.
$translation = $this->randomName(16);
2009-02-22 20:55:18 +00:00
// Add custom language.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalLogin($admin_user);
2009-02-05 00:32:47 +00:00
$edit = array(
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Add string.
t($name, array(), $langcode);
// Reset locale cache.
locale(NULL, NULL, TRUE);
2009-02-22 20:55:18 +00:00
$this->assertText($langcode, t('Language code found.'));
$this->assertText($name, t('Name found.'));
$this->assertText($native, t('Native found.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// No t() here, we do not want to add this string to the database and it's
// surely not translated yet.
2009-02-22 20:55:18 +00:00
$this->assertText($native, t('Test language added.'));
2008-11-29 09:33:51 +00:00
$this->drupalLogout();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Search for the name and translate it.
$this->drupalLogin($translate_user);
2009-02-22 20:55:18 +00:00
$search = array(
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
'string' => $name,
'language' => 'all',
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
// assertText() seems to remove the input field where $name always could be
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// found, so this is not a false assert. See how assertNoText succeeds
// later.
2009-02-22 20:55:18 +00:00
$this->assertText($name, t('Search found the name.'));
$this->assertRaw($language_indicator, t('Name is untranslated.'));
// Assume this is the only result, given the random name.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->clickLink(t('edit'));
// We save the lid from the path.
2009-02-05 00:32:47 +00:00
$matches = array();
2009-03-31 02:02:23 +00:00
preg_match('!admin/international/translate/edit/(\d)+!', $this->getUrl(), $matches);
2009-02-05 00:32:47 +00:00
$lid = $matches[1];
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// No t() here, it's surely not translated yet.
2009-02-22 20:55:18 +00:00
$this->assertText($name, t('name found on edit screen.'));
$edit = array(
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
"translations[$langcode]" => $translation,
);
$this->drupalPost(NULL, $edit, t('Save translations'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('The string has been saved.'), t('The string has been saved.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertTrue($name != $translation && t($name, array(), $langcode) == $translation, t('t() works.'));
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// The indicator should not be here.
2009-02-22 20:55:18 +00:00
$this->assertNoRaw($language_indicator, t('String is translated.'));
// Try to edit a non-existent string and ensure we're redirected correctly.
// Assuming we don't have 999,999 strings already.
$random_lid = 999999;
2009-03-31 02:02:23 +00:00
$this->drupalGet('admin/international/translate/edit/' . $random_lid);
2009-02-22 20:55:18 +00:00
$this->assertText(t('String not found'), t('String not found.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
2008-11-29 09:33:51 +00:00
$this->drupalLogout();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2008-04-25 18:26:02 +00:00
// Delete the language.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalLogin($admin_user);
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language/delete/' . $langcode;
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// This a confirm form, we do not need any fields changed.
$this->drupalPost($path, array(), t('Delete'));
// We need raw here because %locale will add HTML.
2009-02-22 20:55:18 +00:00
$this->assertRaw(t('The language %locale has been removed.', array('%locale' => $name)), t('The test language has been removed.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Reload to remove $name.
$this->drupalGet($path);
2009-02-22 20:55:18 +00:00
$this->assertNoText($langcode, t('Language code not found.'));
$this->assertNoText($name, t('Name not found.'));
$this->assertNoText($native, t('Native not found.'));
2008-11-29 09:33:51 +00:00
$this->drupalLogout();
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2009-02-22 20:55:18 +00:00
// Delete the string.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalLogin($translate_user);
2009-02-22 20:55:18 +00:00
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
// Assume this is the only result, given the random name.
$this->clickLink(t('delete'));
$this->assertText(t('Are you sure you want to delete the string'), t('"delete" link is correct.'));
// Delete the string.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/translate/delete/' . $lid;
2009-02-22 20:55:18 +00:00
$this->drupalGet($path);
// First test the 'cancel' link.
$this->clickLink(t('Cancel'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertRaw($name, t('The string was not deleted.'));
// Delete the name string.
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/delete/' . $lid, array(), t('Delete'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('The string has been removed.'), t('The string has been removed message.'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/translate/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertNoText($name, t('Search now can not find the name.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-12-09 19:53:36 +00:00
2009-02-13 00:45:18 +00:00
/**
* Tests the validation of the translation input.
*/
function testStringValidation() {
2008-12-09 19:53:36 +00:00
global $base_url;
2009-02-22 20:55:18 +00:00
// User to add language and strings.
2008-12-09 19:53:36 +00:00
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages', 'translate interface'));
$this->drupalLogin($admin_user);
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
2008-12-09 19:53:36 +00:00
// The English name for the language. This will be translated.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
2009-02-22 20:55:18 +00:00
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
2008-12-09 19:53:36 +00:00
// This is the language indicator on the translation search screen for
// untranslated strings. Copied straight from locale.inc.
$language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
// These will be the invalid translations of $name.
$key = $this->randomName(16);
$bad_translations[$key] = "<script>alert('xss');</script>" . $key;
$key = $this->randomName(16);
$bad_translations[$key] = '<img SRC="javascript:alert(\'xss\');">' . $key;
$key = $this->randomName(16);
$bad_translations[$key] = '<<SCRIPT>alert("xss");//<</SCRIPT>' . $key;
$key = $this->randomName(16);
$bad_translations[$key] ="<BODY ONLOAD=alert('xss')>" . $key;
2009-02-22 20:55:18 +00:00
// Add custom language.
$edit = array(
2008-12-09 19:53:36 +00:00
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2008-12-09 19:53:36 +00:00
// Add string.
t($name, array(), $langcode);
// Reset locale cache.
2009-02-22 20:55:18 +00:00
$search = array(
2008-12-09 19:53:36 +00:00
'string' => $name,
'language' => 'all',
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
// Find the edit path.
2008-12-09 19:53:36 +00:00
$content = $this->drupalGetContent();
2009-03-31 02:02:23 +00:00
$this->assertTrue(preg_match('@(admin/international/translate/edit/[0-9]+)@', $content, $matches), t('Found the edit path.'));
2008-12-09 19:53:36 +00:00
$path = $matches[0];
foreach ($bad_translations as $key => $translation) {
2009-02-22 20:55:18 +00:00
$edit = array(
2008-12-09 19:53:36 +00:00
"translations[$langcode]" => $translation,
);
$this->drupalPost($path, $edit, t('Save translations'));
// Check for a form error on the textarea.
$form_class = $this->xpath('//form[@id="locale-translate-edit-form"]//textarea/@class');
$this->assertNotIdentical(FALSE, strpos($form_class[0], 'error'), t('The string was rejected as unsafe.'));
$this->assertNoText(t('The string has been saved.'), t('The string was not saved.'));
}
}
2009-02-22 20:55:18 +00:00
/**
* Tests translation search form.
*/
function testStringSearch() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
// User to translate and delete string.
$translate_user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
2009-02-22 20:55:18 +00:00
// The English name for the language. This will be translated.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
2009-02-22 20:55:18 +00:00
// This is the language indicator on the translation search screen for
// untranslated strings. Copied straight from locale.inc.
$language_indicator = "<em class=\"locale-untranslated\">$langcode</em> ";
2009-04-20 02:23:17 +00:00
// This will be the translation of $name.
$translation = $this->randomName(16);
2009-02-22 20:55:18 +00:00
// Add custom language.
$this->drupalLogin($admin_user);
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Add string.
t($name, array(), $langcode);
// Reset locale cache.
locale(NULL, NULL, TRUE);
$this->drupalLogout();
// Search for the name.
$this->drupalLogin($translate_user);
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
// assertText() seems to remove the input field where $name always could be
// found, so this is not a false assert. See how assertNoText succeeds
// later.
$this->assertText($name, t('Search found the string.'));
// Ensure untranslated string doesn't appear if searching on 'only
// translated strings'.
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'translated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('No strings found for your search.'), t("Search didn't find the string."));
// Ensure untranslated string appears if searching on 'only untranslated
// strings'.
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'untranslated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertNoText(t('No strings found for your search.'), t('Search found the string.'));
// Add translation.
// Assume this is the only result, given the random name.
$this->clickLink(t('edit'));
// We save the lid from the path.
$matches = array();
2009-03-31 02:02:23 +00:00
preg_match('!admin/international/translate/edit/(\d)+!', $this->getUrl(), $matches);
2009-02-22 20:55:18 +00:00
$lid = $matches[1];
$edit = array(
"translations[$langcode]" => $translation,
);
$this->drupalPost(NULL, $edit, t('Save translations'));
// Ensure translated string does appear if searching on 'only
// translated strings'.
$search = array(
'string' => $translation,
'language' => 'all',
'translation' => 'translated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertNoText(t('No strings found for your search.'), t('Search found the translation.'));
// Ensure translated source string doesn't appear if searching on 'only
// untranslated strings'.
$search = array(
'string' => $name,
'language' => 'all',
'translation' => 'untranslated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('No strings found for your search.'), t("Search didn't find the source string."));
// Ensure translated string doesn't appear if searching on 'only
// untranslated strings'.
$search = array(
'string' => $translation,
'language' => 'all',
'translation' => 'untranslated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('No strings found for your search.'), t("Search didn't find the translation."));
// Ensure translated string does appear if searching on the custom language.
$search = array(
'string' => $translation,
'language' => $langcode,
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertNoText(t('No strings found for your search.'), t('Search found the translation.'));
// Ensure translated string doesn't appear if searching on English.
$search = array(
'string' => $translation,
'language' => 'en',
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('No strings found for your search.'), t("Search didn't find the translation."));
// Search for a string that isn't in the system.
$unavailable_string = $this->randomName(16);
$search = array(
'string' => $unavailable_string,
'language' => 'all',
'translation' => 'all',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('No strings found for your search.'), t("Search didn't find the invalid string."));
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-11-11 20:22:17 +00:00
/**
* Functional tests for the import of translation files.
*/
class LocaleImportFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-11-11 20:22:17 +00:00
return array(
'name' => t('Translation import'),
'description' => t('Tests the importation of locale files.'),
'group' => t('Locale'),
);
}
/**
* A user able to create languages and import translations.
*/
protected $admin_user = NULL;
function setUp() {
2009-01-22 03:29:01 +00:00
parent::setUp('locale', 'locale_test');
2008-11-11 20:22:17 +00:00
$this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
$this->drupalLogin($this->admin_user);
}
/**
* Test importation of standalone .po files.
*/
function testStandalonePoFile() {
// Try importing a .po file.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getPoFile());
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2008-11-11 20:22:17 +00:00
'langcode' => 'fr',
'files[file]' => $name,
), t('Import'));
unlink($name);
2009-02-22 20:55:18 +00:00
// The import should automatically create the corresponding language.
$this->assertRaw(t('The language %language has been created.', array('%language' => 'French')), t('The language has been automatically created.'));
// The import should have created 7 strings.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 7, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
2008-11-11 20:22:17 +00:00
2009-02-22 20:55:18 +00:00
// Ensure we were redirected correctly.
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/translate', array('absolute' => TRUE)), t('Correct page redirection.'));
2008-12-09 19:53:36 +00:00
2009-01-22 03:29:01 +00:00
// Try importing a .po file with invalid tags in the default text group.
2008-12-09 19:53:36 +00:00
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getBadPoFile());
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2008-12-09 19:53:36 +00:00
'langcode' => 'fr',
'files[file]' => $name,
), t('Import'));
unlink($name);
2009-02-22 20:55:18 +00:00
// The import should have created 1 string and rejected 2.
2008-12-09 19:53:36 +00:00
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
$skip_message = format_plural(2, 'One translation string was skipped because it contains disallowed HTML.', '@count translation strings were skipped because they contain disallowed HTML.');
$this->assertRaw($skip_message, t('Unsafe strings were skipped.'));
2009-01-22 03:29:01 +00:00
// Try importing a .po file with invalid tags in a non default text group.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getBadPoFile());
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2009-01-22 03:29:01 +00:00
'langcode' => 'fr',
'files[file]' => $name,
'group' => 'custom',
), t('Import'));
unlink($name);
2009-02-22 20:55:18 +00:00
// The import should have created 3 strings.
2009-01-22 03:29:01 +00:00
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 3, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
2009-02-22 20:55:18 +00:00
// Try importing a .po file which doesn't exist.
$name = $this->randomName(16);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2009-02-22 20:55:18 +00:00
'langcode' => 'fr',
'files[file]' => $name,
'group' => 'custom',
), t('Import'));
2009-03-31 02:02:23 +00:00
$this->assertEqual($this->getUrl(), url('admin/international/translate/import', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('File to import not found.'), t('File to import not found message.'));
// Try importing a .po file with overriding strings, and ensure existing
// strings are kept.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getOverwritePoFile());
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2009-02-22 20:55:18 +00:00
'langcode' => 'fr',
'files[file]' => $name,
'mode' => 1, // Existing strings are kept, only new strings are added.
), t('Import'));
unlink($name);
// The import should have created 1 string.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 1, '%update' => 0, '%delete' => 0)), t('The translation file was successfully imported.'));
// Ensure string wasn't overwritten.
$search = array(
'string' => 'Montag',
'language' => 'fr',
'translation' => 'translated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertText(t('No strings found for your search.'), t('String not overwritten by imported string.'));
// Try importing a .po file with overriding strings, and ensure existing
// strings are overwritten.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getOverwritePoFile());
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2009-02-22 20:55:18 +00:00
'langcode' => 'fr',
'files[file]' => $name,
'mode' => 0, // Strings in the uploaded file replace existing ones, new ones are added.
), t('Import'));
unlink($name);
// The import should have updated 2 strings.
$this->assertRaw(t('The translation was successfully imported. There are %number newly created translated strings, %update strings were updated and %delete strings were removed.', array('%number' => 0, '%update' => 2, '%delete' => 0)), t('The translation file was successfully imported.'));
// Ensure string was overwritten.
$search = array(
'string' => 'Montag',
'language' => 'fr',
'translation' => 'translated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertNoText(t('No strings found for your search.'), t('String overwritten by imported string.'));
}
/**
* Test automatic importation of a module's translation files when a language
* is enabled.
*/
function testAutomaticModuleTranslationImportLanguageEnable() {
2009-02-24 16:46:52 +00:00
// Code for the language - manually set to match the test translation file.
$langcode = 'xx';
2009-02-22 20:55:18 +00:00
// The English name for the language.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
2009-02-22 20:55:18 +00:00
// Create a custom language.
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Ensure the translation file was automatically imported when language was
// added.
$this->assertText(t('One translation file imported for the enabled modules.'), t('Language file automatically imported.'));
// Ensure strings were successfully imported.
$search = array(
'string' => 'lundi',
'language' => $langcode,
'translation' => 'translated',
'group' => 'all',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/translate', $search, t('Filter'));
2009-02-22 20:55:18 +00:00
$this->assertNoText(t('No strings found for your search.'), t('String successfully imported.'));
2008-11-11 20:22:17 +00:00
}
/**
* Helper function that returns a proper .po file.
*/
function getPoFile() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 6\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "lundi"
msgid "Tuesday"
msgstr "mardi"
msgid "Wednesday"
msgstr "mercredi"
msgid "Thursday"
msgstr "jeudi"
msgid "Friday"
msgstr "vendredi"
msgid "Saturday"
msgstr "samedi"
msgid "Sunday"
msgstr "dimanche"
2008-12-09 19:53:36 +00:00
EOF;
}
/**
2009-02-22 20:55:18 +00:00
* Helper function that returns a bad .po file.
2008-12-09 19:53:36 +00:00
*/
function getBadPoFile() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 6\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Save configuration"
msgstr "Enregistrer la configuration"
msgid "edit"
msgstr "modifier<img SRC="javascript:alert(\'xss\');">"
msgid "delete"
msgstr "supprimer<script>alert('xss');</script>"
2008-11-11 20:22:17 +00:00
EOF;
}
2009-02-22 20:55:18 +00:00
/**
* Helper function that returns a proper .po file, for testing overwriting
* existing translations.
*/
function getOverwritePoFile() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 6\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "Montag"
msgid "Day"
msgstr "Jour"
EOF;
}
}
/**
* Functional tests for the export of translation files.
*/
class LocaleExportFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-22 20:55:18 +00:00
return array(
'name' => t('Translation export'),
'description' => t('Tests the exportation of locale files.'),
'group' => t('Locale'),
);
}
/**
* A user able to create languages and export translations.
*/
protected $admin_user = NULL;
function setUp() {
parent::setUp('locale', 'locale_test');
$this->admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages'));
$this->drupalLogin($this->admin_user);
}
/**
* Test exportation of translations.
*/
function testExportTranslation() {
// First import some known translations.
// This will also automatically enable the 'fr' language.
$name = tempnam(file_directory_temp(), "po_");
file_put_contents($name, $this->getPoFile());
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/import', array(
2009-02-22 20:55:18 +00:00
'langcode' => 'fr',
'files[file]' => $name,
), t('Import'));
unlink($name);
// Get the French translations.
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/export', array(
2009-02-22 20:55:18 +00:00
'langcode' => 'fr',
), t('Export'));
// Ensure we have a translation file.
$this->assertRaw('# French translation of Drupal', t('Exported French translation file.'));
// Ensure our imported translations exist in the file.
$this->assertRaw('msgstr "lundi"', t('French translations present in exported file.'));
}
/**
* Test exportation of translation template file.
*/
function testExportTranslationTemplateFile() {
// Get the translation template file.
// There are two 'Export' buttons on this page, but it somehow works. It'd
// be better if we could use the submit button id like documented but that
// doesn't work.
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/export', array(), t('Export'));
2009-02-22 20:55:18 +00:00
// Ensure we have a translation file.
$this->assertRaw('# LANGUAGE translation of PROJECT', t('Exported translation template file.'));
}
/**
* Helper function that returns a proper .po file.
*/
function getPoFile() {
return <<< EOF
msgid ""
msgstr ""
"Project-Id-Version: Drupal 6\\n"
"MIME-Version: 1.0\\n"
"Content-Type: text/plain; charset=UTF-8\\n"
"Content-Transfer-Encoding: 8bit\\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\\n"
msgid "Monday"
msgstr "lundi"
EOF;
}
2008-11-11 20:22:17 +00:00
}
2009-01-22 03:18:30 +00:00
2009-02-13 00:45:18 +00:00
/**
* Locale uninstall with English UI functional test.
*/
class LocaleUninstallFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-13 00:45:18 +00:00
return array(
'name' => t('Locale uninstall (EN)'),
'description' => t('Tests the uninstall process using the built-in UI language.'),
'group' => t('Locale'),
);
}
/**
* The default language set for the UI before uninstall.
*/
protected $ui_language;
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
function setUp() {
parent::setUp('locale');
$this->ui_language = 'en';
}
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
/**
* Check if the values of the Locale variables are correct after uninstall.
*/
function testUninstallProcess() {
$locale_module = array('locale');
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Add a new language and optionally set it as default.
require_once DRUPAL_ROOT . '/includes/locale.inc';
locale_add_language('fr', 'French', 'Français', LANGUAGE_LTR, '', '', TRUE, $this->ui_language == 'fr');
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Check the UI language.
drupal_init_language();
global $language;
$this->assertEqual($language->language, $this->ui_language, t('Current language: %lang', array('%lang' => $language->language)));
// Change language negotiation options.
variable_set('language_negotiation', LANGUAGE_NEGOTIATION_PATH_DEFAULT);
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Enable multilingual workflow option for articles.
variable_set('language_content_type_article', 1);
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Change JavaScript translations directory.
variable_set('locale_js_directory', 'js_translations');
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Build the JavaScript translation file for French.
$user = $this->drupalCreateUser(array('translate interface', 'access administration pages'));
$this->drupalLogin($user);
2009-03-31 02:02:23 +00:00
$this->drupalGet('admin/international/translate/translate');
2009-05-27 11:45:00 +00:00
$string = db_query('SELECT min(lid) AS lid FROM {locales_source} WHERE location LIKE :location AND textgroup = :textgroup', array(
':location' => '%.js%',
':textgroup' => 'default',
))->fetchObject();
2009-02-13 00:45:18 +00:00
$edit = array('translations[fr]' => 'french translation');
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/translate/edit/' . $string->lid, $edit, t('Save translations'));
2009-02-13 00:45:18 +00:00
_locale_rebuild_js('fr');
2009-05-27 11:45:00 +00:00
$file = db_query('SELECT javascript FROM {languages} WHERE language = :language', array(':language' => 'fr'))->fetchObject();
2009-02-22 20:55:18 +00:00
$js_file = file_create_path(variable_get('locale_js_directory', 'languages')) . '/fr_' . $file->javascript . '.js';
2009-02-13 00:45:18 +00:00
$this->assertTrue($result = file_exists($js_file), t('JavaScript file created: %file', array('%file' => $result ? $js_file : t('none'))));
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Disable string caching.
variable_set('locale_cache_strings', 0);
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Uninstall Locale.
module_disable($locale_module);
drupal_uninstall_modules($locale_module);
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Visit the front page.
$this->drupalGet('');
// Check the init language logic.
drupal_init_language();
$this->assertEqual($language->language, 'en', t('Language after uninstall: %lang', array('%lang' => $language->language)));
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Check JavaScript files deletion.
$this->assertTrue($result = !file_exists($js_file), t('JavaScript file deleted: %file', array('%file' => $result ? $js_file : t('found'))));
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Check language count.
$language_count = variable_get('language_count', 1);
$this->assertEqual($language_count, 1, t('Language count: %count', array('%count' => $language_count)));
// Check language negotiation.
$language_negotiation = variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE) == LANGUAGE_NEGOTIATION_NONE;
$this->assertTrue($language_negotiation, t('Language negotiation: %setting', array('%setting' => t($language_negotiation ? 'none' : 'set'))));
// Check JavaScript parsed.
$javascript_parsed_count = count(variable_get('javascript_parsed', array()));
$this->assertEqual($javascript_parsed_count, 0, t('JavaScript parsed count: %count', array('%count' => $javascript_parsed_count)));
// Check multilingual workflow option for articles.
$multilingual = variable_get('language_content_type_article', 0);
$this->assertEqual($multilingual, 0, t('Multilingual workflow option: %status', array('%status' => t($multilingual ? 'enabled': 'disabled'))));
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Check JavaScript translations directory.
$locale_js_directory = variable_get('locale_js_directory', 'languages');
$this->assertEqual($locale_js_directory, 'languages', t('JavaScript translations directory: %dir', array('%dir' => $locale_js_directory)));
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
// Check string caching.
$locale_cache_strings = variable_get('locale_cache_strings', 1);
2009-02-22 20:55:18 +00:00
$this->assertEqual($locale_cache_strings, 1, t('String caching: %status', array('%status' => t($locale_cache_strings ? 'enabled': 'disabled'))));
2009-02-13 00:45:18 +00:00
}
}
/**
* Locale uninstall with French UI functional test.
2009-02-22 20:55:18 +00:00
*
2009-02-13 00:45:18 +00:00
* Because this class extends LocaleUninstallFunctionalTest, it doesn't require a new
* test of its own. Rather, it switches the default UI language in setUp and then
* runs the testUninstallProcess (which it inherits from LocaleUninstallFunctionalTest)
* to test with this new language.
*/
class LocaleUninstallFrenchFunctionalTest extends LocaleUninstallFunctionalTest {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-13 00:45:18 +00:00
return array(
'name' => t('Locale uninstall (FR)'),
'description' => t('Tests the uninstall process using French as UI language.'),
'group' => t('Locale'),
);
}
2009-02-22 20:55:18 +00:00
2009-02-13 00:45:18 +00:00
function setUp() {
parent::setUp();
$this->ui_language = 'fr';
}
}
2009-01-22 03:18:30 +00:00
/**
* Functional tests for the language switching feature.
*/
class LanguageSwitchingFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-22 03:18:30 +00:00
return array(
'name' => t('Language switching'),
'description' => t('Tests for the language switching feature.'),
'group' => t('Locale'),
);
}
function setUp() {
parent::setUp('locale');
2009-02-22 20:55:18 +00:00
// Create and login user.
2009-01-22 03:18:30 +00:00
$admin_user = $this->drupalCreateUser(array('administer blocks', 'administer languages', 'translate interface', 'access administration pages'));
$this->drupalLogin($admin_user);
}
2009-02-22 20:55:18 +00:00
/**
* Functional tests for the language switcher block.
*/
2009-01-22 03:18:30 +00:00
function testLanguageBlock() {
// Enable the language switching block.
$edit = array(
'locale_language-switcher[region]' => 'left',
);
$this->drupalPost('admin/build/block', $edit, t('Save blocks'));
// Add language.
$edit = array(
'langcode' => 'fr',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add language'));
2009-01-22 03:18:30 +00:00
// Set language negotiation.
$edit = array(
'language_negotiation' => LANGUAGE_NEGOTIATION_PATH_DEFAULT,
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/configure', $edit, t('Save settings'));
$this->assertEqual($this->getUrl(), url('admin/international/language', array('absolute' => TRUE)), t('Correct page redirection.'));
2009-01-22 03:18:30 +00:00
// Assert that the language switching block is displayed on the frontpage.
$this->drupalGet('');
2009-02-22 20:55:18 +00:00
$this->assertText(t('Languages'), t('Language switcher block found.'));
2009-01-22 03:18:30 +00:00
// Assert that only the current language is marked as active.
list($language_switcher) = $this->xpath('//div[@id="block-locale-language-switcher"]');
$links = array(
'active' => array(),
'inactive' => array(),
);
$anchors = array(
'active' => array(),
'inactive' => array(),
);
foreach ($language_switcher->div->ul->li as $link) {
$classes = explode(" ", (string) $link['class']);
list($language) = array_intersect($classes, array('en', 'fr'));
if (in_array('active', $classes)) {
$links['active'][] = $language;
}
else {
$links['inactive'][] = $language;
}
$anchor_classes = explode(" ", (string) $link->a['class']);
if (in_array('active', $anchor_classes)) {
$anchors['active'][] = $language;
}
else {
$anchors['inactive'][] = $language;
}
}
2009-02-22 20:55:18 +00:00
$this->assertIdentical($links, array('active' => array('en'), 'inactive' => array('fr')), t('Only the current language list item is marked as active on the language switcher block.'));
$this->assertIdentical($anchors, array('active' => array('en'), 'inactive' => array('fr')), t('Only the current language anchor is marked as active on the language switcher block.'));
2009-01-22 03:18:30 +00:00
}
}
2009-02-22 20:55:18 +00:00
/**
* Functional tests for a user's ability to change their default language.
*/
class LocaleUserLanguageFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-22 20:55:18 +00:00
return array(
'name' => t('User language settings'),
'description' => t("Tests user's ability to change their default language."),
'group' => t('Locale'),
);
}
function setUp() {
parent::setUp('locale');
}
/**
* Test if user can change their default language.
*/
function testUserLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'access administration pages'));
// User to change their default language.
$web_user = $this->drupalCreateUser();
// Add custom language.
$this->drupalLogin($admin_user);
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
2009-02-22 20:55:18 +00:00
// The English name for the language.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = 'xx';
2009-02-22 20:55:18 +00:00
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Add custom language and disable it.
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode_disabled = 'xx-yy';
2009-02-22 20:55:18 +00:00
// The English name for the language. This will be translated.
$name_disabled = $this->randomName(16);
// The native name for the language.
$native_disabled = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix_disabled = $langcode_disabled;
2009-02-22 20:55:18 +00:00
$edit = array(
'langcode' => $langcode_disabled,
'name' => $name_disabled,
'native' => $native_disabled,
'prefix' => $prefix_disabled,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Disable the language.
$edit = array(
'enabled[' . $langcode_disabled . ']' => FALSE,
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language', $edit, t('Save configuration'));
2009-02-22 20:55:18 +00:00
$this->drupalLogout();
// Login as normal user and edit account settings.
$this->drupalLogin($web_user);
$path = 'user/' . $web_user->uid . '/edit';
$this->drupalGet($path);
// Ensure language settings fieldset is available.
$this->assertText(t('Language settings'), t('Language settings available.'));
// Ensure custom language is present.
$this->assertText($name, t('Language present on form.'));
// Ensure disabled language isn't present.
$this->assertNoText($name_disabled, t('Disabled language not present on form.'));
// Switch to our custom language.
$edit = array(
'language' => $langcode,
);
$this->drupalPost($path, $edit, t('Save'));
// Ensure form was submitted successfully.
$this->assertText(t('The changes have been saved.'), t('Changes were saved.'));
// Check if language was changed.
$elements = $this->xpath('//input[@id="edit-language-' . $langcode . '"]');
$this->assertTrue(isset($elements[0]) && !empty($elements[0]['checked']), t('Default language successfully updated.'));
$this->drupalLogout();
}
}
/**
* Functional tests for configuring a different path alias per language.
*/
class LocalePathFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-22 20:55:18 +00:00
return array(
'name' => t('Path language settings'),
'description' => t('Checks you can configure a language for individual url aliases.'),
'group' => t('Locale'),
);
}
function setUp() {
parent::setUp('locale', 'path');
}
/**
* Test if a language can be associated with a path alias.
*/
function testPathLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'create page content', 'administer url aliases', 'create url aliases', 'access administration pages'));
// Add custom language.
$this->drupalLogin($admin_user);
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
2009-02-22 20:55:18 +00:00
// The English name for the language.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
2009-02-22 20:55:18 +00:00
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Set language negotiation.
$edit = array(
'language_negotiation' => LANGUAGE_NEGOTIATION_PATH_DEFAULT,
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/configure', $edit, t('Save settings'));
2009-02-22 20:55:18 +00:00
// Create a node.
$node = $this->drupalCreateNode(array('type' => 'page'));
// Create a path alias in default language (English).
$path = 'admin/build/path/add';
$english_path = $this->randomName(8);
$edit = array(
'src' => 'node/' . $node->nid,
'dst' => $english_path,
'language' => 'en',
);
$this->drupalPost($path, $edit, t('Create new alias'));
// Create a path alias in new custom language.
$custom_language_path = $this->randomName(8);
$edit = array(
'src' => 'node/' . $node->nid,
'dst' => $custom_language_path,
'language' => $langcode,
);
$this->drupalPost($path, $edit, t('Create new alias'));
// Confirm English language path alias works.
$this->drupalGet($english_path);
$this->assertText($node->title, t('English alias works.'));
// Confirm custom language path alias works.
$this->drupalGet($prefix . '/' . $custom_language_path);
$this->assertText($node->title, t('Custom language alias works.'));
$this->drupalLogout();
}
}
/**
* Functional tests for multilingual support on nodes.
*/
class LocaleContentFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-22 20:55:18 +00:00
return array(
'name' => t('Content language settings'),
'description' => t('Checks you can enable multilingual support on content types and configure a language for a node.'),
'group' => t('Locale'),
);
}
function setUp() {
parent::setUp('locale');
}
/**
* Test if a content type can be set to multilingual and language setting is
* present on node add and edit forms.
*/
function testContentTypeLanguageConfiguration() {
global $base_url;
// User to add and remove language.
$admin_user = $this->drupalCreateUser(array('administer languages', 'administer content types', 'access administration pages'));
// User to create a node.
$web_user = $this->drupalCreateUser(array('create page content', 'edit any page content'));
// Add custom language.
$this->drupalLogin($admin_user);
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode = 'xx';
2009-02-22 20:55:18 +00:00
// The English name for the language.
$name = $this->randomName(16);
// The native name for the language.
$native = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix = $langcode;
2009-02-22 20:55:18 +00:00
$edit = array(
'langcode' => $langcode,
'name' => $name,
'native' => $native,
'prefix' => $prefix,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Add disabled custom language.
// Code for the language.
2009-02-24 16:46:52 +00:00
$langcode_disabled = 'xx-yy';
2009-02-22 20:55:18 +00:00
// The English name for the language.
$name_disabled = $this->randomName(16);
// The native name for the language.
$native_disabled = $this->randomName(16);
// The domain prefix.
2009-02-24 16:46:52 +00:00
$prefix_disabled = $langcode_disabled;
2009-02-22 20:55:18 +00:00
$edit = array(
'langcode' => $langcode_disabled,
'name' => $name_disabled,
'native' => $native_disabled,
'prefix' => $prefix_disabled,
'direction' => '0',
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/add', $edit, t('Add custom language'));
2009-02-22 20:55:18 +00:00
// Disable second custom language.
2009-03-31 02:02:23 +00:00
$path = 'admin/international/language';
2009-02-22 20:55:18 +00:00
$edit = array(
'enabled[' . $langcode_disabled . ']' => FALSE,
);
$this->drupalPost($path, $edit, t('Save configuration'));
// Set language negotiation.
$edit = array(
'language_negotiation' => LANGUAGE_NEGOTIATION_PATH_DEFAULT,
);
2009-03-31 02:02:23 +00:00
$this->drupalPost('admin/international/language/configure', $edit, t('Save settings'));
2009-02-22 20:55:18 +00:00
// Set page content type to use multilingual support.
$this->drupalGet('admin/build/node-type/page');
$this->assertText(t('Multilingual support:'), t('Multilingual support fieldset present on content type configuration form.'));
$edit = array(
'language_content_type' => 1,
);
$this->drupalPost('admin/build/node-type/page', $edit, t('Save content type'));
$this->assertRaw(t('The content type %type has been updated.', array('%type' => 'Page')), t('Page content type has been updated.'));
$this->drupalLogout();
// Verify language selection is not present on add article form.
$this->drupalLogin($web_user);
$this->drupalGet('node/add/article');
// Verify language select list is not present.
$this->assertNoRaw('<select name="language" class="form-select" id="edit-language" >', t('Language select not present on add article form.'));
// Verify language selection appears on add page form.
$this->drupalGet('node/add/page');
// Verify language select list is present.
$this->assertRaw('<select name="language" class="form-select" id="edit-language" >', t('Language select present on add page form.'));
// Ensure enabled language appears.
$this->assertText($name, t('Enabled language present.'));
// Ensure disabled language doesn't appear.
$this->assertNoText($name_disabled, t('Disabled language not present.'));
// Create page content.
$node_title = $this->randomName();
$node_body = $this->randomName();
$edit = array(
'type' => 'page',
'title' => $node_title,
'body' => $node_body,
'language' => $langcode,
);
$node = $this->drupalCreateNode($edit);
// Edit the page content and ensure correct language is selected.
$path = 'node/' . $node->nid . '/edit';
$this->drupalGet($path);
$this->assertRaw('<option value="' . $langcode . '" selected="selected">' . $name . '</option>', t('Correct language selected.'));
// Ensure we can change the node language.
$edit = array(
'language' => 'en',
);
$this->drupalPost($path, $edit, t('Save'));
$this->assertRaw(t('Page %title has been updated.', array('%title' => $node_title)), t('Page updated.'));
$this->drupalLogout();
}
}