FeedLanguageTest.php in Drupal 9
File
core/modules/aggregator/tests/src/Functional/FeedLanguageTest.php
View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\Tests\Traits\Core\CronRunTrait;
class FeedLanguageTest extends AggregatorTestBase {
use CronRunTrait;
protected static $modules = [
'language',
];
protected $defaultTheme = 'stark';
protected $langcodes = [];
protected function setUp() : void {
parent::setUp();
$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();
}
}
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);
$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');
$feeds = [];
$feeds[1] = $this
->createFeed(NULL, [
'langcode[0][value]' => $this->langcodes[1],
]);
$feeds[2] = $this
->createFeed(NULL, [
'langcode[0][value]' => $this->langcodes[2],
]);
$this
->assertEquals($this->langcodes[1], $feeds[1]
->language()
->getId());
$this
->assertEquals($this->langcodes[2], $feeds[2]
->language()
->getId());
$this
->createSampleNodes();
$this
->cronRun();
foreach ($feeds as $feed) {
$items = \Drupal::entityTypeManager()
->getStorage('aggregator_item')
->loadByProperties([
'fid' => $feed
->id(),
]);
$this
->assertNotEmpty($items);
foreach ($items as $item) {
$this
->assertEquals($feed
->language()
->getId(), $item
->language()
->getId());
}
}
}
}