View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\Component\Render\FormattableMarkup;
class AggregatorAdminTest extends AggregatorTestBase {
protected $defaultTheme = 'stark';
public function testSettingsPage() {
$this
->drupalGet('admin/config');
$this
->clickLink('Aggregator');
$this
->clickLink('Settings');
$this
->assertText('Test fetcher');
$this
->assertText('Test parser');
$this
->assertText('Test processor');
$edit = [
'aggregator_allowed_html_tags' => '<a>',
'aggregator_summary_items' => 10,
'aggregator_clear' => 3600,
'aggregator_teaser_length' => 200,
'aggregator_fetcher' => 'aggregator_test_fetcher',
'aggregator_parser' => 'aggregator_test_parser',
'aggregator_processors[aggregator_test_processor]' => 'aggregator_test_processor',
];
$this
->drupalPostForm('admin/config/services/aggregator/settings', $edit, t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
foreach ($edit as $name => $value) {
$this
->assertFieldByName($name, $value, new FormattableMarkup('"@name" has correct default value.', [
'@name' => $name,
]));
}
$this
->assertText(t('Dummy length setting'));
$edit = [
'dummy_length' => 100,
];
$this
->drupalPostForm('admin/config/services/aggregator/settings', $edit, t('Save configuration'));
$this
->assertText(t('The configuration options have been saved.'));
$this
->assertFieldByName('dummy_length', 100, '"dummy_length" has correct default value.');
$this->container
->get('module_installer')
->uninstall([
'aggregator_test',
]);
$this
->resetAll();
$this
->drupalGet('admin/config/services/aggregator/settings');
$this
->assertSession()
->statusCodeEquals(200);
}
public function testOverviewPage() {
$feed = $this
->createFeed($this
->getRSS091Sample());
$this
->drupalGet('admin/config/services/aggregator');
$result = $this
->xpath('//table/tbody/tr');
$this
->assertCount(1, $result, 'Created feed is found in the overview');
$link = $this
->xpath('//table/tbody/tr//td[1]/a');
$this
->assertEquals($feed
->label(), $link[0]
->getText());
$count = $this->container
->get('entity_type.manager')
->getStorage('aggregator_item')
->getItemCount($feed);
$td = $this
->xpath('//table/tbody/tr//td[2]');
$this
->assertEquals(\Drupal::translation()
->formatPlural($count, '1 item', '@count items'), $td[0]
->getText());
$feed
->refreshItems();
$this
->drupalGet('admin/config/services/aggregator');
$result = $this
->xpath('//table/tbody/tr');
$link = $this
->xpath('//table/tbody/tr//td[1]/a');
$this
->assertEquals($feed
->label(), $link[0]
->getText());
$count = $this->container
->get('entity_type.manager')
->getStorage('aggregator_item')
->getItemCount($feed);
$td = $this
->xpath('//table/tbody/tr//td[2]');
$this
->assertEquals(\Drupal::translation()
->formatPlural($count, '1 item', '@count items'), $td[0]
->getText());
}
}