- <?php
- * @file
- * Tests for translation functionality within block.module.
- */
-
- class BlockTranslationTestCase extends BackdropWebTestCase {
- protected $profile = 'testing';
- protected $admin_user;
-
- function setUp() {
- $modules = array(
- 'layout',
- 'block',
- 'block_test',
- 'language',
- 'locale',
- );
- parent::setUp($modules);
-
-
- $full_html_format = array(
- 'format' => 'full_html',
- 'name' => 'Raw HTML',
- 'weight' => 1,
- 'editor' => NULL,
- 'filters' => array(),
- );
- $full_html_format = (object) $full_html_format;
- filter_format_save($full_html_format);
-
-
-
- $permissions = array(
- 'administer blocks',
- filter_permission_name($full_html_format),
- 'access administration pages',
- 'administer layouts',
- 'administer languages',
- );
- $this->checkPermissions($permissions, TRUE);
- $this->admin_user = $this->backdropCreateUser($permissions);
- $this->backdropLogin($this->admin_user);
- }
-
-
- * Test creating custom block, translate it, and then deleting it.
- */
- function testTranslateCustomBlock() {
-
-
- $this->assertTrue(module_exists('language'), 'Language module was enabled successfully.');
-
- $languages = array(
- 'it' => 'italian',
- 'fr' => 'french',
- 'es' => 'spanish',
- 'fi' => 'finnish',
- 'nl' => 'dutch',
- );
-
-
- foreach ($languages as $key => $value) {
- $this->addLanguage($key);
- }
-
- backdrop_static_reset('language_list');
-
-
- $this->backdropGet('admin/structure/block');
- $this->assertRaw(l('Add custom block', 'admin/structure/block/add'), 'Add block link is present on block overview page for default theme.');
-
-
- $this->backdropGet('admin/structure/block/add');
-
-
- $block_delta = strtolower($this->randomName(8));
- $custom_block = array();
- $custom_block['info'] = $this->randomName(8);
- $custom_block['delta'] = $block_delta;
- $custom_block['title'] = 'Testblock created in default language';
- $custom_block['body[value]'] = $this->randomName(32);
- $this->backdropPost(NULL, $custom_block, t('Save block'));
-
-
- $this->assertText(t('The block has been created.'), 'Custom block successfully created.');
-
-
- $custom_block = config_get('block.custom.' . $block_delta);
- $this->assertNotNull($custom_block, 'Custom block found in configuration.');
-
-
- $this->assertLinkByHref('admin/structure/block/manage/' . $block_delta . '/configure', 0, 'Custom block configure link found.');
- $this->assertNoLinkByHref('admin/structure/block/manage/' . $block_delta . '/translation', 'Custom block translate link not found when translation disabled.');
- $this->backdropGet('admin/structure/block/manage/' . $block_delta . '/translation');
- $this->assertResponse(403, 'Access not allowed to translation page when translation disabled.');
- $this->backdropGet('admin/structure/block/manage/' . $block_delta . '/translate/fr');
- $this->assertResponse(403, 'Access not allowed to individual translate page when translation disabled.');
-
-
- $edit = array(
- 'default_langcode' => language_default()->langcode,
- );
- $this->backdropPost('admin/structure/block/manage/' . $block_delta, $edit, t('Save block'));
-
-
- $this->backdropGet('admin/structure/block');
- $this->assertLinkByHref('admin/structure/block/manage/' . $block_delta . '/configure', 0, 'Custom block configure link found.');
- $this->assertLinkByHref('admin/structure/block/manage/' . $block_delta . '/translation', 0, 'Custom block translate link found.');
-
-
- $this->backdropGet('admin/structure/block/manage/' . $block_delta . '/translation');
-
-
- foreach ($languages as $key => $value) {
- $this->assertLinkByHref('admin/structure/block/manage/' . $block_delta . '/translate/' . $key, 0, 'Found custom block translate link for ' . $value . '.');
- }
-
-
- foreach ($languages as $key => $value) {
- $this->backdropGet('admin/structure/block/manage/' . $block_delta . '/translate/' . $key);
-
- $translated_block = array();
- $translated_block['info'] = $this->randomName(8);
- $translated_block['title'] = 'Testblock translated to ' . $value;
- $translated_block['body[value]'] = $this->randomName(32);
- $this->backdropPost(NULL, $translated_block, t('Save block'));
- }
-
-
- $layout = layout_load('default');
- $layout->addBlock('block', $block_delta, 'sidebar');
- $layout->save();
-
-
- $this->backdropGet('user');
- $this->assertText('Testblock created in default language', 'Custom block successfully being displayed.');
-
-
- foreach ($languages as $key => $value) {
-
-
- $core_config = config('system.core');
- $core_config->set('language_default', $key);
- $core_config->save();
-
- $this->resetAll();
-
-
- $this->backdropGet('user');
- $this->assertText('Testblock translated to ' . $value, 'Translated block successfully being displayed in ' . $value . '.');
- }
- }
-
- private function addLanguage($language_code) {
- if (strpos($this->backdropGetContent(), 'enabled[' . $language_code . ']') === FALSE) {
-
- $edit = array(
- 'predefined_langcode' => $language_code,
- );
- $this->backdropPost('admin/config/regional/language/add', $edit, t('Add language'));
- }
- }
- }