ConfigTranslationViewListUiTest.php in Drupal 9
File
core/modules/config_translation/tests/src/Functional/ConfigTranslationViewListUiTest.php
View source
<?php
namespace Drupal\Tests\config_translation\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\views_ui\Functional\UITestBase;
use Drupal\views\Views;
class ConfigTranslationViewListUiTest extends UITestBase {
public static $testViews = [
'node',
'test_view',
];
protected static $modules = [
'config_translation',
'views_ui',
];
protected $defaultTheme = 'stark';
protected function setUp($import_test_views = TRUE) : void {
parent::setUp($import_test_views);
$permissions = [
'administer views',
'translate configuration',
'access content overview',
'administer languages',
];
$this
->drupalLogin($this
->drupalCreateUser($permissions));
}
public function testTranslateOperationInViewListUi() {
$this
->drupalGet('admin/structure/views');
$translate_link = 'admin/structure/views/view/test_view/translate';
$this
->assertSession()
->linkByHrefExists($translate_link);
$this
->drupalGet($translate_link);
$this
->assertSession()
->responseContains('<th>Language</th>');
$this
->assertSession()
->linkByHrefExists('admin/structure/views/view/test_view');
}
public function testTimestampFormatterTranslation() {
ConfigurableLanguage::createFromLangcode('de')
->save();
$this
->drupalCreateContentType([
'type' => 'article',
]);
$node = $this
->drupalCreateNode([
'type' => 'article',
'title' => $this
->randomMachineName(),
]);
$view = Views::getView('content');
$display =& $view->storage
->getDisplay('default');
$display['display_options']['fields']['changed']['type'] = 'timestamp_ago';
$display['display_options']['fields']['changed']['settings'] = [
'future_format' => '@interval hence',
'past_format' => '@interval ago',
'granularity' => 1,
];
$view
->save();
$this
->drupalGet('admin/structure/views/view/content/translate/de/edit');
$edit = [
'translation[config_names][views.view.content][display][default][display_options][fields][changed][settings][future_format]' => '@interval später',
'translation[config_names][views.view.content][display][default][display_options][fields][changed][settings][past_format]' => 'vor @interval',
];
$this
->submitForm($edit, 'Save translation');
$past_timestamp = \Drupal::time()
->getCurrentTime() - 3700;
$node
->setChangedTime($past_timestamp);
$node
->save();
$this
->drupalGet('/de/admin/content');
$this
->assertSession()
->pageTextContains('vor 1 hour');
$past_timestamp = \Drupal::time()
->getCurrentTime() + 3700;
$node
->setChangedTime($past_timestamp);
$node
->save();
$this
->drupalGet('/de/admin/content');
$this
->assertSession()
->pageTextContains('1 hour später');
}
}