class FeedLanguageTest
Same name and namespace in other branches
- 8.9.x core/modules/aggregator/tests/src/Functional/FeedLanguageTest.php \Drupal\Tests\aggregator\Functional\FeedLanguageTest
Tests aggregator feeds in multiple languages.
@group aggregator @group legacy
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\aggregator\Functional\AggregatorTestBase extends \Drupal\Tests\BrowserTestBase
- class \Drupal\Tests\aggregator\Functional\FeedLanguageTest uses \Drupal\Tests\Traits\Core\CronRunTrait extends \Drupal\Tests\aggregator\Functional\AggregatorTestBase
- class \Drupal\Tests\aggregator\Functional\AggregatorTestBase extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of FeedLanguageTest
File
-
core/
modules/ aggregator/ tests/ src/ Functional/ FeedLanguageTest.php, line 14
Namespace
Drupal\Tests\aggregator\FunctionalView source
class FeedLanguageTest extends AggregatorTestBase {
use CronRunTrait;
/**
* Modules to install.
*
* @var array
*/
protected static $modules = [
'language',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* List of langcodes.
*
* @var string[]
*/
protected $langcodes = [];
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
// Create test languages.
$this->langcodes = [
ConfigurableLanguage::load('en'),
];
for ($i = 1; $i < 3; ++$i) {
$language = ConfigurableLanguage::create([
'id' => 'l' . $i,
'label' => $this->randomString(),
]);
$language->save();
$this->langcodes[$i] = $language->id();
}
}
/**
* Tests creation of feeds with a language.
*/
public function testFeedLanguage() {
$admin_user = $this->drupalCreateUser([
'administer languages',
'access administration pages',
'administer news feeds',
'access news feeds',
'create article content',
]);
$this->drupalLogin($admin_user);
// Enable language selection for feeds.
$edit['entity_types[aggregator_feed]'] = TRUE;
$edit['settings[aggregator_feed][aggregator_feed][settings][language][language_alterable]'] = TRUE;
$this->drupalGet('admin/config/regional/content-language');
$this->submitForm($edit, 'Save configuration');
/** @var \Drupal\aggregator\FeedInterface[] $feeds */
$feeds = [];
// Create feeds.
$feeds[1] = $this->createFeed(NULL, [
'langcode[0][value]' => $this->langcodes[1],
]);
$feeds[2] = $this->createFeed(NULL, [
'langcode[0][value]' => $this->langcodes[2],
]);
// Make sure that the language has been assigned.
$this->assertEquals($this->langcodes[1], $feeds[1]->language()
->getId());
$this->assertEquals($this->langcodes[2], $feeds[2]->language()
->getId());
// Create example nodes to create feed items from and then update the feeds.
$this->createSampleNodes();
$this->cronRun();
// Loop over the created feed items and verify that their language matches
// the one from the feed.
foreach ($feeds as $feed) {
/** @var \Drupal\aggregator\ItemInterface[] $items */
$items = \Drupal::entityTypeManager()->getStorage('aggregator_item')
->loadByProperties([
'fid' => $feed->id(),
]);
// Verify that the feed items were created.
$this->assertNotEmpty($items);
foreach ($items as $item) {
$this->assertEquals($feed->language()
->getId(), $item->language()
->getId());
}
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.