Move into nested docroot

This commit is contained in:
Rob Davies 2017-02-13 15:31:17 +00:00
parent 83a0d3a149
commit c8b70abde9
13405 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,6 @@
name: 'Aggregator module tests'
type: module
description: 'Support module for aggregator related testing.'
package: Testing
version: VERSION
core: 8.x

View file

@ -0,0 +1,17 @@
aggregator_test.feed:
path: '/aggregator/test-feed/{use_last_modified}/{use_etag}'
defaults:
_controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::testFeed'
_title: 'Test feed static last modified date'
use_last_modified: FALSE
use_etag: FALSE
requirements:
_access: 'TRUE'
aggregator_test.redirect:
path: '/aggregator/redirect'
defaults:
_controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::testRedirect'
_title: 'Test feed with a redirect'
requirements:
_access: 'TRUE'

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/" />
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
</author>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03" />
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
<entry>
<title>We tried to stop them, but we failed.</title>
<link href="http://example.org/2003/12/14/atom03" />
<id>urn:uuid:1225c695-cfb8-4ebb-bbbb-80da344efa6a</id>
<updated>2003-12-14T16:30:02Z</updated>
<summary>Some other text.</summary>
</entry>
</feed>

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.91">
<channel>
<title>Example</title>
<link>http://example.com</link>
<description>Example updates</description>
<language>en-us</language>
<copyright>Copyright 2000, Example team.</copyright>
<managingEditor>editor@example.com</managingEditor>
<webMaster>webmaster@example.com</webMaster>
<image>
<title>Example</title>
<url>http://example.com/images/druplicon.png</url>
<link>http://example.com</link>
<width>88</width>
<height>100</height>
<description>Example updates</description>
</image>
<item>
<title>First example feed item title</title>
<link>http://example.com/example-turns-one</link>
<description>First example feed item description.</description>
</item>
<item>
<title>Second example feed item title. This title is extremely long so that it exceeds the 255 character limit for titles in feed item storage. In fact it's so long that this sentence isn't long enough so I'm rambling a bit to make it longer, nearly there now. Ah now it's long enough so I'll shut up.</title>
<link>http://example.com/example-turns-two</link>
<description>Second example feed item description.</description>
</item>
<item>
<title>Long link feed item title.</title>
<link>http://example.com/tomorrow/and/tomorrow/and/tomorrow/creeps/in/this/petty/pace/from/day/to/day/to/the/last/syllable/of/recorded/time/and/all/our/yesterdays/have/lighted/fools/the/way/to/dusty/death/out/out/brief/candle/life/is/but/a/walking/shadow/a/poor/player/that/struts/and/frets/his/hour/upon/the/stage/and/is/heard/no/more/it/is/a/tale/told/by/an/idiot/full/of/sound/and/fury/signifying/nothing</link>
<description>Long link feed item description.</description>
</item>
<item>
<title>Long author feed item title.</title>
<link>http://example.com/long/author</link>
<author>I wanted to get out and walk eastward toward the park through the soft twilight, but each time I tried to go I became entangled in some wild, strident argument which pulled me back, as if with ropes, into my chair. Yet high over the city our line of yellow windows must have contributed their share of human secrecy to the casual watcher in the darkening streets, and I was him too, looking up and wondering. I was within and without, simultaneously enchanted and repelled by the inexhaustible variety of life.</author>
<description>Long author feed item description.</description>
</item>
<item>
<title></title>
<link>http://example.com/empty/title</link>
<description>This is an item with an empty title.</description>
</item>
<item>
<title>Empty description feed item title.</title>
<link>http://example.com/empty/description</link>
<description></description>
</item>
<item>
<title>Empty link feed item title.</title>
<link></link>
<description>This is an item with an empty link.</description>
</item>
<item>
<title>Empty author feed item title.</title>
<link>http://example.com/empty/author</link>
<author></author>
<description>We've tested items with no author, but what about an empty author tag?</description>
</item>
</channel>
</rss>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.91">
<channel>
<title>Example with Entities</title>
<link>http://example.com</link>
<description>Example RSS Feed With HTML Entities in Title</description>
<language>en-us</language>
<item>
<title>Quote&quot; Amp&amp;</title>
<link>http://example.com/example-turns-one</link>
<description>Some text.</description>
</item>
</channel>
</rss>

View file

@ -0,0 +1,13 @@
# Schema for the configuration files of the Aggregator Test module.
aggregator_test.settings:
type: config_object
label: 'Aggregator test settings'
mapping:
items:
type: mapping
label: 'Items'
mapping:
dummy_length:
type: integer
label: 'Dummy length'

View file

@ -0,0 +1,77 @@
<?php
namespace Drupal\aggregator_test\Controller;
use Drupal\Component\Datetime\DateTimePlus;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Component\Utility\Crypt;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
/**
* Controller for the aggregator_test module.
*/
class AggregatorTestRssController extends ControllerBase {
/**
* Generates a test feed and simulates last-modified and etags.
*
* @param bool $use_last_modified
* Set TRUE to send a last modified header.
* @param bool $use_etag
* Set TRUE to send an etag.
* @param \Symfony\Component\HttpFoundation\Request $request
* Information about the current HTTP request.
*
* @return \Symfony\Component\HttpFoundation\Response
* A feed that forces cache validation.
*/
public function testFeed($use_last_modified, $use_etag, Request $request) {
$response = new Response();
$last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
$etag = Crypt::hashBase64($last_modified);
$if_modified_since = strtotime($request->server->get('HTTP_IF_MODIFIED_SINCE'));
$if_none_match = stripslashes($request->server->get('HTTP_IF_NONE_MATCH'));
// Send appropriate response. We respond with a 304 not modified on either
// etag or on last modified.
if ($use_last_modified) {
$response->headers->set('Last-Modified', gmdate(DateTimePlus::RFC7231, $last_modified));
}
if ($use_etag) {
$response->headers->set('ETag', $etag);
}
// Return 304 not modified if either last modified or etag match.
if ($last_modified == $if_modified_since || $etag == $if_none_match) {
$response->setStatusCode(304);
return $response;
}
// The following headers force validation of cache.
$response->headers->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
$response->headers->set('Cache-Control', 'must-revalidate');
$response->headers->set('Content-Type', 'application/rss+xml; charset=utf-8');
// Read actual feed from file.
$file_name = __DIR__ . '/../../aggregator_test_rss091.xml';
$handle = fopen($file_name, 'r');
$feed = fread($handle, filesize($file_name));
fclose($handle);
$response->setContent($feed);
return $response;
}
/**
* Generates a rest redirect to the test feed.
*
* @return \Symfony\Component\HttpFoundation\RedirectResponse
* A response that redirects users to the test feed.
*/
public function testRedirect() {
return $this->redirect('aggregator_test.feed', [], [], 301);
}
}

View file

@ -0,0 +1,32 @@
<?php
namespace Drupal\aggregator_test\Plugin\aggregator\fetcher;
use Drupal\aggregator\Plugin\FetcherInterface;
use Drupal\aggregator\Plugin\aggregator\fetcher\DefaultFetcher;
use Drupal\aggregator\FeedInterface;
/**
* Defines a test fetcher implementation.
*
* Uses http_client class to download the feed.
*
* @AggregatorFetcher(
* id = "aggregator_test_fetcher",
* title = @Translation("Test fetcher"),
* description = @Translation("Dummy fetcher for testing purposes.")
* )
*/
class TestFetcher extends DefaultFetcher implements FetcherInterface {
/**
* {@inheritdoc}
*/
public function fetch(FeedInterface $feed) {
if ($feed->label() == 'Do not fetch') {
return FALSE;
}
return parent::fetch($feed);
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace Drupal\aggregator_test\Plugin\aggregator\parser;
use Drupal\aggregator\Plugin\ParserInterface;
use Drupal\aggregator\FeedInterface;
use Drupal\aggregator\Plugin\aggregator\parser\DefaultParser;
/**
* Defines a Test parser implementation.
*
* Parses RSS, Atom and RDF feeds.
*
* @AggregatorParser(
* id = "aggregator_test_parser",
* title = @Translation("Test parser"),
* description = @Translation("Dummy parser for testing purposes.")
* )
*/
class TestParser extends DefaultParser implements ParserInterface {
/**
* Implements \Drupal\aggregator\Plugin\ParserInterface::parse().
*
* @todo Actually test this.
*/
public function parse(FeedInterface $feed) {
return parent::parse($feed);
}
}

View file

@ -0,0 +1,148 @@
<?php
namespace Drupal\aggregator_test\Plugin\aggregator\processor;
use Drupal\aggregator\Plugin\AggregatorPluginSettingsBase;
use Drupal\aggregator\Plugin\ProcessorInterface;
use Drupal\aggregator\FeedInterface;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\ConfigFormBaseTrait;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Defines a default processor implementation.
*
* Creates lightweight records from feed items.
*
* @AggregatorProcessor(
* id = "aggregator_test_processor",
* title = @Translation("Test processor"),
* description = @Translation("Test generic processor functionality.")
* )
*/
class TestProcessor extends AggregatorPluginSettingsBase implements ProcessorInterface, ContainerFactoryPluginInterface {
use ConfigFormBaseTrait;
/**
* Contains the configuration object factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->get('config.factory')
);
}
/**
* Constructs a TestProcessor object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param mixed $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The configuration factory object.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, ConfigFactoryInterface $config) {
$this->configFactory = $config;
parent::__construct($configuration + $this->getConfiguration(), $plugin_id, $plugin_definition);
}
/**
* {@inheritdoc}
*/
protected function getEditableConfigNames() {
return ['aggregator_test.settings'];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$processors = $this->config('aggregator.settings')->get('processors');
$info = $this->getPluginDefinition();
$form['processors'][$info['id']] = array(
'#type' => 'details',
'#title' => t('Test processor settings'),
'#description' => $info['description'],
'#open' => in_array($info['id'], $processors),
);
// Add some dummy settings to verify settingsForm is called.
$form['processors'][$info['id']]['dummy_length'] = array(
'#title' => t('Dummy length setting'),
'#type' => 'number',
'#min' => 1,
'#max' => 1000,
'#default_value' => $this->configuration['items']['dummy_length'],
);
return $form;
}
/**
* {@inheritdoc}
*/
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
$this->configuration['items']['dummy_length'] = $form_state->getValue('dummy_length');
$this->setConfiguration($this->configuration);
}
/**
* {@inheritdoc}
*/
public function process(FeedInterface $feed) {
foreach ($feed->items as &$item) {
// Prepend our test string.
$item['title'] = 'testProcessor' . $item['title'];
}
}
/**
* {@inheritdoc}
*/
public function delete(FeedInterface $feed) {
// Append a random number, just to change the feed description.
$feed->description->value .= rand(0, 10);
}
/**
* {@inheritdoc}
*/
public function postProcess(FeedInterface $feed) {
// Double the refresh rate.
$feed->refresh->value *= 2;
$feed->save();
}
/**
* {@inheritdoc}
*/
public function getConfiguration() {
return $this->configFactory->get('aggregator_test.settings')->get();
}
/**
* {@inheritdoc}
*/
public function setConfiguration(array $configuration) {
$config = $this->config('aggregator_test.settings');
foreach ($configuration as $key => $value) {
$config->set($key, $value);
}
$config->save();
}
}

View file

@ -0,0 +1,9 @@
name: 'Aggregator test views'
type: module
description: 'Provides default views for views aggregator tests.'
package: Testing
version: VERSION
core: 8.x
dependencies:
- aggregator
- views

View file

@ -0,0 +1,195 @@
langcode: en
status: true
dependencies:
module:
- aggregator
id: test_aggregator_items
label: test_aggregator_items
module: views
description: ''
tag: ''
base_table: aggregator_item
base_field: iid
core: 8.x
display:
default:
display_plugin: default
id: default
display_title: Master
position: null
display_options:
access:
type: none
cache:
type: tag
query:
type: views_query
exposed_form:
type: basic
pager:
type: full
style:
type: default
row:
type: fields
fields:
iid:
table: aggregator_item
field: iid
id: iid
plugin_id: field
entity_type: aggregator_item
entity_field: iid
title:
table: aggregator_item
field: title
id: title
plugin_id: field
type: aggregator_title
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
entity_type: aggregator_item
entity_field: title
timestamp:
table: aggregator_item
field: timestamp
id: timestamp
type: timestamp
settings:
date_format: medium
custom_date_format: ''
timezone: ''
plugin_id: field
entity_type: aggregator_item
entity_field: timestamp
author:
table: aggregator_item
field: author
id: author
plugin_id: field
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
entity_type: aggregator_item
entity_field: author
description:
id: description
table: aggregator_item
field: description
relationship: none
group_type: group
admin_label: ''
label: Body
exclude: false
alter:
alter_text: false
text: ''
make_link: false
path: ''
absolute: false
external: false
replace_spaces: false
path_case: none
trim_whitespace: false
alt: ''
rel: ''
link_class: ''
prefix: ''
suffix: ''
target: ''
nl2br: false
max_length: 0
word_boundary: true
ellipsis: true
more_link: false
more_link_text: ''
more_link_path: ''
strip_tags: false
trim: false
preserve_tags: ''
html: false
element_type: ''
element_class: ''
element_label_type: ''
element_label_class: ''
element_label_colon: true
element_wrapper_type: ''
element_wrapper_class: ''
element_default_classes: true
empty: ''
hide_empty: false
empty_zero: false
hide_alter_empty: true
plugin_id: field
entity_type: aggregator_item
entity_field: description
filters: { }
sorts:
iid:
id: iid
table: aggregator_item
field: iid
plugin_id: standard
entity_type: aggregator_item
entity_field: iid
order: 'ASC'
feed_1:
display_plugin: feed
id: feed_1
display_title: Feed
position: null
display_options:
path: test-aggregator-items-feed
row:
type: aggregator_rss
options:
view_mode: default

View file

@ -0,0 +1,90 @@
<?php
namespace Drupal\Tests\aggregator\Kernel;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests the aggregator_title formatter.
*
* @group field
*/
class AggregatorTitleTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = ['file', 'field', 'options', 'aggregator', 'system'];
/**
* The field name that is tested.
*
* @var string
*/
protected $fieldName;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(['field']);
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
\Drupal::service('router.builder')->rebuild();
$this->fieldName = 'title';
}
/**
* Tests the formatter output.
*/
public function testStringFormatter() {
// Create an aggregator feed.
$aggregator_feed = Feed::create([
'title' => 'testing title',
'url' => 'http://www.example.com',
]);
$aggregator_feed->save();
// Create an aggregator feed item.
$aggregator_item = Item::create([
'title' => 'test title',
'fid' => $aggregator_feed->id(),
'link' => 'http://www.example.com',
]);
$aggregator_item->save();
// Verify aggregator feed title with and without links.
$build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
$result = $this->render($build);
$this->assertContains('testing title', $result);
$this->assertContains('href="' . $aggregator_feed->getUrl() . '"', $result);
$build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
$result = $this->render($build);
$this->assertContains('testing title', $result);
$this->assertNotContains($aggregator_feed->getUrl(), $result);
// Verify aggregator item title with and without links.
$build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]);
$result = $this->render($build);
$this->assertContains('test title', $result);
$this->assertContains('href="' . $aggregator_item->getLink() . '"', $result);
$build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
$result = $this->render($build);
$this->assertContains('test title', $result);
$this->assertNotContains($aggregator_item->getLink(), $result);
}
}

View file

@ -0,0 +1,67 @@
<?php
namespace Drupal\Tests\aggregator\Kernel;
use Drupal\aggregator\Entity\Feed;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
/**
* Tests feed validation constraints.
*
* @group aggregator
*/
class FeedValidationTest extends EntityKernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('aggregator', 'options');
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
}
/**
* Tests the feed validation constraints.
*/
public function testValidation() {
// Add feed.
$feed = Feed::create([
'title' => 'Feed 1',
'url' => 'https://www.drupal.org/planet/rss.xml',
'refresh' => 900,
]);
$violations = $feed->validate();
$this->assertEqual(count($violations), 0);
$feed->save();
// Add another feed.
/* @var \Drupal\aggregator\FeedInterface $feed */
$feed = Feed::create([
'title' => 'Feed 1',
'url' => 'https://www.drupal.org/planet/rss.xml',
'refresh' => 900,
]);
$violations = $feed->validate();
$this->assertEqual(count($violations), 2);
$this->assertEqual($violations[0]->getPropertyPath(), 'title');
$this->assertEqual($violations[0]->getMessage(), t('A feed named %value already exists. Enter a unique title.', [
'%value' => $feed->label(),
]));
$this->assertEqual($violations[1]->getPropertyPath(), 'url');
$this->assertEqual($violations[1]->getMessage(), t('A feed with this URL %value already exists. Enter a unique URL.', [
'%value' => $feed->getUrl(),
]));
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Drupal\Tests\aggregator\Kernel;
use Drupal\aggregator\Entity\Item;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests clean handling of an item with a missing feed ID.
*
* @group aggregator
*/
class ItemWithoutFeedTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator', 'options'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
}
/**
* Tests attempting to create a feed item without a feed.
*/
public function testEntityCreation() {
$entity = Item::create([
'title' => t('Llama 2'),
'path' => 'https://groups.drupal.org/',
]);
$violations = $entity->validate();
$this->assertCount(1, $violations);
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate;
use Drupal\migrate\MigrateException;
use Drupal\Tests\migrate_drupal\Kernel\MigrateDrupalTestBase;
use Drupal\migrate_drupal\Tests\StubTestTrait;
/**
* Test stub creation for aggregator feeds and items.
*
* @group aggregator
*/
class MigrateAggregatorStubTest extends MigrateDrupalTestBase {
use StubTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
}
/**
* Tests creation of aggregator feed stubs.
*/
public function testFeedStub() {
$this->performStubTest('aggregator_feed');
}
/**
* Tests creation of aggregator feed items.
*/
public function testItemStub() {
try {
// We expect an exception, because there's no feed to reference.
$this->performStubTest('aggregator_item');
$this->fail('Expected exception has not been thrown.');
}
catch (MigrateException $e) {
$this->assertIdentical($e->getMessage(),
'Stubbing failed, unable to generate value for field fid');
}
// The stub should pass when there's a feed to point to.
$this->createStub('aggregator_feed');
$this->performStubTest('aggregator_item');
}
}

View file

@ -0,0 +1,45 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate\d6;
use Drupal\config\Tests\SchemaCheckTestTrait;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Upgrade variables to aggregator.settings.yml.
*
* @group migrate_drupal_6
*/
class MigrateAggregatorConfigsTest extends MigrateDrupal6TestBase {
use SchemaCheckTestTrait;
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->executeMigration('d6_aggregator_settings');
}
/**
* Tests migration of aggregator variables to aggregator.settings.yml.
*/
public function testAggregatorSettings() {
$config = $this->config('aggregator.settings');
$this->assertIdentical('aggregator', $config->get('fetcher'));
$this->assertIdentical('aggregator', $config->get('parser'));
$this->assertIdentical(array('aggregator'), $config->get('processors'));
$this->assertIdentical(600, $config->get('items.teaser_length'));
$this->assertIdentical('<a> <b> <br /> <dd> <dl> <dt> <em> <i> <li> <ol> <p> <strong> <u> <ul>', $config->get('items.allowed_html'));
$this->assertIdentical(9676800, $config->get('items.expire'));
$this->assertIdentical(3, $config->get('source.list_max'));
$this->assertConfigSchema(\Drupal::service('config.typed'), 'aggregator.settings', $config->get());
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate\d6;
use Drupal\aggregator\Entity\Feed;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of aggregator feeds.
*
* @group migrate_drupal_6
*/
class MigrateAggregatorFeedTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->executeMigration('d6_aggregator_feed');
}
/**
* Tests migration of aggregator feeds.
*/
public function testAggregatorFeedImport() {
/** @var \Drupal\aggregator\Entity\Feed $feed */
$feed = Feed::load(5);
$this->assertIdentical('Know Your Meme', $feed->title->value);
$this->assertIdentical('en', $feed->language()->getId());
$this->assertIdentical('http://knowyourmeme.com/newsfeed.rss', $feed->url->value);
$this->assertIdentical('900', $feed->refresh->value);
$this->assertIdentical('1387659487', $feed->checked->value);
$this->assertIdentical('0', $feed->queued->value);
$this->assertIdentical('http://knowyourmeme.com', $feed->link->value);
$this->assertIdentical('New items added to the News Feed', $feed->description->value);
$this->assertIdentical('http://b.thumbs.redditmedia.com/harEHsUUZVajabtC.png', $feed->image->value);
$this->assertIdentical('"213cc1365b96c310e92053c5551f0504"', $feed->etag->value);
$this->assertIdentical('0', $feed->modified->value);
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate\d6;
use Drupal\aggregator\Entity\Item;
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
/**
* Tests migration of aggregator items.
*
* @group migrate_drupal_6
*/
class MigrateAggregatorItemTest extends MigrateDrupal6TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
$this->executeMigrations(['d6_aggregator_feed', 'd6_aggregator_item']);
}
/**
* Test Drupal 6 aggregator item migration to Drupal 8.
*/
public function testAggregatorItem() {
/** @var \Drupal\aggregator\Entity\Item $item */
$item = Item::load(1);
$this->assertIdentical('1', $item->id());
$this->assertIdentical('5', $item->getFeedId());
$this->assertIdentical('This (three) weeks in Drupal Core - January 10th 2014', $item->label());
$this->assertIdentical('larowlan', $item->getAuthor());
$this->assertIdentical("<h2 id='new'>What's new with Drupal 8?</h2>", $item->getDescription());
$this->assertIdentical('https://groups.drupal.org/node/395218', $item->getLink());
$this->assertIdentical('1389297196', $item->getPostedTime());
$this->assertIdentical('en', $item->language()->getId());
$this->assertIdentical('395218 at https://groups.drupal.org', $item->getGuid());
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate\d7;
use Drupal\aggregator\Entity\Feed;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Test migration to aggregator_feed entities.
*
* @group migrate_drupal_7
*/
class MigrateAggregatorFeedTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->executeMigration('d7_aggregator_feed');
}
/**
* Tests migration of aggregator feeds.
*/
public function testAggregatorFeedImport() {
/** @var \Drupal\aggregator\FeedInterface $feed */
$feed = Feed::load(1);
$this->assertIdentical('Know Your Meme', $feed->label());
$this->assertIdentical('en', $feed->language()->getId());
$this->assertIdentical('http://knowyourmeme.com/newsfeed.rss', $feed->getUrl());
$this->assertIdentical('900', $feed->getRefreshRate());
// The feed's last checked time can change as the fixture is updated, so
// assert that its format is correct.
$checked_time = $feed->getLastCheckedTime();
$this->assertTrue(is_numeric($checked_time));
$this->assertTrue($checked_time > 1000000000);
$this->assertIdentical('0', $feed->getQueuedTime());
$this->assertIdentical('http://knowyourmeme.com', $feed->link->value);
$this->assertIdentical('New items added to the News Feed', $feed->getDescription());
$this->assertNull($feed->getImage());
// As with getLastCheckedTime(), the etag can change as the fixture is
// updated normally, so assert that its format is correct.
$this->assertTrue(preg_match('/^"[a-z0-9]{32}"$/', $feed->getEtag()));
$this->assertIdentical('0', $feed->getLastModified());
}
}

View file

@ -0,0 +1,58 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate\d7;
use Drupal\aggregator\Entity\Item;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of aggregator items.
*
* @group migrate_drupal_7
*/
class MigrateAggregatorItemTest extends MigrateDrupal7TestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
$this->executeMigration('d7_aggregator_feed');
$this->executeMigration('d7_aggregator_item');
}
/**
* Test Drupal 7 aggregator item migration to Drupal 8.
*/
public function testAggregatorItem() {
// Since the feed items can change as the fixture is updated normally,
// assert all migrated feed items against the values in the fixture.
$items = $this->sourceDatabase
->select('aggregator_item', 'ai')
->fields('ai')
->execute();
foreach ($items as $original) {
/** @var \Drupal\aggregator\ItemInterface $item */
$item = Item::load($original->iid);
$this->assertIdentical($original->fid, $item->getFeedId());
$this->assertIdentical($original->title, $item->label());
// If $original->author is an empty string, getAuthor() returns NULL so
// we need to use assertEqual() here.
$this->assertEqual($original->author, $item->getAuthor());
$this->assertIdentical($original->description, $item->getDescription());
$this->assertIdentical($original->link, $item->getLink());
$this->assertIdentical($original->timestamp, $item->getPostedTime());
$this->assertIdentical('en', $item->language()->getId());
$this->assertIdentical($original->guid, $item->getGuid());
}
}
}

View file

@ -0,0 +1,39 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Migrate\d7;
use Drupal\Tests\migrate_drupal\Kernel\d7\MigrateDrupal7TestBase;
/**
* Tests migration of Aggregator's variables to configuration.
*
* @group aggregator
*/
class MigrateAggregatorSettingsTest extends MigrateDrupal7TestBase {
public static $modules = ['aggregator'];
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->installConfig(static::$modules);
$this->executeMigration('d7_aggregator_settings');
}
/**
* Tests migration of Aggregator variables to configuration.
*/
public function testMigration() {
$config = \Drupal::config('aggregator.settings')->get();
$this->assertIdentical('aggregator', $config['fetcher']);
$this->assertIdentical('aggregator', $config['parser']);
$this->assertIdentical(['aggregator'], $config['processors']);
$this->assertIdentical('<p> <div> <a>', $config['items']['allowed_html']);
$this->assertIdentical(500, $config['items']['teaser_length']);
$this->assertIdentical(86400, $config['items']['expire']);
$this->assertIdentical(6, $config['source']['list_max']);
}
}

View file

@ -0,0 +1,60 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Plugin\migrate\source;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests D6 aggregator feed source plugin.
*
* @covers \Drupal\aggregator\Plugin\migrate\source\AggregatorFeed
* @group aggregator
*/
class AggregatorFeedTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
$tests[0]['database']['aggregator_feed'] = [
[
'fid' => 1,
'title' => 'feed title 1',
'url' => 'http://example.com/feed.rss',
'refresh' => 900,
'checked' => 0,
'link' => 'http://example.com',
'description' => 'A vague description',
'image' => '',
'etag' => '',
'modified' => 0,
'block' => 5,
],
[
'fid' => 2,
'title' => 'feed title 2',
'url' => 'http://example.net/news.rss',
'refresh' => 1800,
'checked' => 0,
'link' => 'http://example.net',
'description' => 'An even more vague description',
'image' => '',
'etag' => '',
'modified' => 0,
'block' => 5,
],
];
// The expected results are identical to the source data.
$tests[0]['expected_results'] = $tests[0]['database']['aggregator_feed'];
return $tests;
}
}

View file

@ -0,0 +1,44 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Plugin\migrate\source;
use Drupal\Tests\migrate\Kernel\MigrateSqlSourceTestBase;
/**
* Tests aggregator item source plugin.
*
* @covers \Drupal\aggregator\Plugin\migrate\source\AggregatorItem
* @group aggregator
*/
class AggregatorItemTest extends MigrateSqlSourceTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator', 'migrate_drupal'];
/**
* {@inheritdoc}
*/
public function providerSource() {
$tests = [];
$tests[0]['database']['aggregator_item'] = [
[
'iid' => 1,
'fid' => 1,
'title' => 'This (three) weeks in Drupal Core - January 10th 2014',
'link' => 'https://groups.drupal.org/node/395218',
'author' => 'larowlan',
'description' => "<h2 id='new'>What's new with Drupal 8?</h2>",
'timestamp' => 1389297196,
'guid' => '395218 at https://groups.drupal.org',
],
];
// The expected results are identical to the source data.
$tests[0]['expected_results'] = $tests[0]['database']['aggregator_item'];
return $tests;
}
}

View file

@ -0,0 +1,47 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Views;
use Drupal\aggregator\Entity\Feed;
use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
/**
* Tests base field access in Views for the aggregator_feed entity.
*
* @group aggregator
*/
class AggregatorFeedViewsFieldAccessTest extends FieldFieldAccessTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator', 'entity_test', 'options'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('aggregator_feed');
}
/**
* Checks access for aggregator_feed fields.
*/
public function testAggregatorFeedFields() {
$feed = Feed::create([
'title' => 'Drupal org',
'url' => 'https://www.drupal.org/rss.xml',
'link' => 'https://www.drupal.org/rss.xml',
]);
$feed->save();
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
// $this->assertFieldAccess('aggregator_feed', 'title', $feed->label());
$this->assertFieldAccess('aggregator_feed', 'langcode', $feed->language()->getName());
$this->assertFieldAccess('aggregator_feed', 'url', $feed->getUrl());
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Views;
use Drupal\aggregator\Entity\Feed;
use Drupal\aggregator\Entity\Item;
use Drupal\Tests\views\Kernel\Handler\FieldFieldAccessTestBase;
/**
* Tests base field access in Views for the aggregator_item entity.
*
* @group aggregator
*/
class AggregatorItemViewsFieldAccessTest extends FieldFieldAccessTestBase {
/**
* {@inheritdoc}
*/
public static $modules = ['aggregator', 'entity_test', 'options'];
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this->installEntitySchema('aggregator_feed');
$this->installEntitySchema('aggregator_item');
}
/**
* Checks access for aggregator_item fields.
*/
public function testAggregatorItemFields() {
$feed = Feed::create([
'title' => 'Drupal org',
'url' => 'https://www.drupal.org/rss.xml',
]);
$feed->save();
$item = Item::create([
'title' => 'Test title',
'fid' => $feed->id(),
'description' => 'Test description',
]);
$item->save();
// @todo Expand the test coverage in https://www.drupal.org/node/2464635
$this->assertFieldAccess('aggregator_item', 'title', $item->getTitle());
$this->assertFieldAccess('aggregator_item', 'langcode', $item->language()->getName());
$this->assertFieldAccess('aggregator_item', 'description', $item->getDescription());
}
}

View file

@ -0,0 +1,134 @@
<?php
namespace Drupal\Tests\aggregator\Kernel\Views;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Render\RenderContext;
use Drupal\Core\Url;
use Drupal\Tests\views\Kernel\ViewsKernelTestBase;
use Drupal\views\Views;
use Drupal\views\Tests\ViewTestData;
/**
* Tests basic integration of views data from the aggregator module.
*
* @group aggregator
*/
class IntegrationTest extends ViewsKernelTestBase {
/**
* Modules to install.
*
* @var array
*/
public static $modules = array('aggregator', 'aggregator_test_views', 'system', 'field', 'options', 'user');
/**
* Views used by this test.
*
* @var array
*/
public static $testViews = array('test_aggregator_items');
/**
* The entity storage for aggregator items.
*
* @var \Drupal\aggregator\ItemStorage
*/
protected $itemStorage;
/**
* The entity storage for aggregator feeds.
*
* @var \Drupal\aggregator\FeedStorage
*/
protected $feedStorage;
/**
* {@inheritdoc}
*/
protected function setUp($import_test_views = TRUE) {
parent::setUp();
$this->installEntitySchema('aggregator_item');
$this->installEntitySchema('aggregator_feed');
ViewTestData::createTestViews(get_class($this), array('aggregator_test_views'));
$this->itemStorage = $this->container->get('entity.manager')->getStorage('aggregator_item');
$this->feedStorage = $this->container->get('entity.manager')->getStorage('aggregator_feed');
}
/**
* Tests basic aggregator_item view.
*/
public function testAggregatorItemView() {
/** @var \Drupal\Core\Render\RendererInterface $renderer */
$renderer = \Drupal::service('renderer');
$feed = $this->feedStorage->create(array(
'title' => $this->randomMachineName(),
'url' => 'https://www.drupal.org/',
'refresh' => 900,
'checked' => 123543535,
'description' => $this->randomMachineName(),
));
$feed->save();
$items = array();
$expected = array();
for ($i = 0; $i < 10; $i++) {
$values = array();
$values['fid'] = $feed->id();
$values['timestamp'] = mt_rand(REQUEST_TIME - 10, REQUEST_TIME + 10);
$values['title'] = $this->randomMachineName();
$values['description'] = $this->randomMachineName();
// Add a image to ensure that the sanitizing can be tested below.
$values['author'] = $this->randomMachineName() . '<img src="http://example.com/example.png" \>"';
$values['link'] = 'https://www.drupal.org/node/' . mt_rand(1000, 10000);
$values['guid'] = $this->randomString();
$aggregator_item = $this->itemStorage->create($values);
$aggregator_item->save();
$items[$aggregator_item->id()] = $aggregator_item;
$values['iid'] = $aggregator_item->id();
$expected[] = $values;
}
$view = Views::getView('test_aggregator_items');
$this->executeView($view);
$column_map = array(
'iid' => 'iid',
'title' => 'title',
'aggregator_item_timestamp' => 'timestamp',
'description' => 'description',
'aggregator_item_author' => 'author',
);
$this->assertIdenticalResultset($view, $expected, $column_map);
// Ensure that the rendering of the linked title works as expected.
foreach ($view->result as $row) {
$iid = $view->field['iid']->getValue($row);
$expected_link = \Drupal::l($items[$iid]->getTitle(), Url::fromUri($items[$iid]->getLink(), ['absolute' => TRUE]));
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
return $view->field['title']->advancedRender($row);
});
$this->assertEqual($output, $expected_link->getGeneratedLink(), 'Ensure the right link is generated');
$expected_author = Xss::filter($items[$iid]->getAuthor(), _aggregator_allowed_tags());
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
return $view->field['author']->advancedRender($row);
});
$this->assertEqual($output, $expected_author, 'Ensure the author got filtered');
$expected_description = Xss::filter($items[$iid]->getDescription(), _aggregator_allowed_tags());
$output = $renderer->executeInRenderContext(new RenderContext(), function () use ($view, $row) {
return $view->field['description']->advancedRender($row);
});
$this->assertEqual($output, $expected_description, 'Ensure the author got filtered');
}
}
}

View file

@ -0,0 +1,65 @@
<?php
namespace Drupal\Tests\aggregator\Unit\Menu;
use Drupal\Tests\Core\Menu\LocalTaskIntegrationTestBase;
/**
* Tests existence of aggregator local tasks.
*
* @group aggregator
*/
class AggregatorLocalTasksTest extends LocalTaskIntegrationTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->directoryList = array('aggregator' => 'core/modules/aggregator');
parent::setUp();
}
/**
* Tests local task existence.
*
* @dataProvider getAggregatorAdminRoutes
*/
public function testAggregatorAdminLocalTasks($route) {
$this->assertLocalTasks($route, array(
0 => array('aggregator.admin_overview', 'aggregator.admin_settings'),
));
}
/**
* Provides a list of routes to test.
*/
public function getAggregatorAdminRoutes() {
return array(
array('aggregator.admin_overview'),
array('aggregator.admin_settings'),
);
}
/**
* Checks aggregator source tasks.
*
* @dataProvider getAggregatorSourceRoutes
*/
public function testAggregatorSourceLocalTasks($route) {
$this->assertLocalTasks($route, array(
0 => array('entity.aggregator_feed.canonical', 'entity.aggregator_feed.edit_form', 'entity.aggregator_feed.delete_form'),
));
;
}
/**
* Provides a list of source routes to test.
*/
public function getAggregatorSourceRoutes() {
return array(
array('entity.aggregator_feed.canonical'),
array('entity.aggregator_feed.edit_form'),
);
}
}

View file

@ -0,0 +1,113 @@
<?php
namespace Drupal\Tests\aggregator\Unit\Plugin;
use Drupal\aggregator\Form\SettingsForm;
use Drupal\Core\Form\FormState;
use Drupal\Tests\UnitTestCase;
/**
* Tests settings configuration of individual aggregator plugins.
*
* @group aggregator
*/
class AggregatorPluginSettingsBaseTest extends UnitTestCase {
/**
* The aggregator settings form object under test.
*
* @var \Drupal\aggregator\Form\SettingsForm
*/
protected $settingsForm;
/**
* The stubbed config factory object.
*
* @var \PHPUnit_Framework_MockObject_MockBuilder
*/
protected $configFactory;
/**
* The stubbed aggregator plugin managers array.
*
* @var array
*/
protected $managers;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->configFactory = $this->getConfigFactoryStub(
array(
'aggregator.settings' => array(
'processors' => array('aggregator_test'),
),
'aggregator_test.settings' => array(),
)
);
foreach (array('fetcher', 'parser', 'processor') as $type) {
$this->managers[$type] = $this->getMockBuilder('Drupal\aggregator\Plugin\AggregatorPluginManager')
->disableOriginalConstructor()
->getMock();
$this->managers[$type]->expects($this->once())
->method('getDefinitions')
->will($this->returnValue(array('aggregator_test' => array('title' => '', 'description' => ''))));
}
$this->settingsForm = new SettingsForm(
$this->configFactory,
$this->managers['fetcher'],
$this->managers['parser'],
$this->managers['processor'],
$this->getStringTranslationStub()
);
}
/**
* Test for AggregatorPluginSettingsBase.
*
* Ensure that the settings form calls build, validate and submit methods on
* plugins that extend AggregatorPluginSettingsBase.
*/
public function testSettingsForm() {
// Emulate a form state of a submitted form.
$form_state = (new FormState())->setValues([
'dummy_length' => '',
'aggregator_allowed_html_tags' => '',
]);
$test_processor = $this->getMock(
'Drupal\aggregator_test\Plugin\aggregator\processor\TestProcessor',
array('buildConfigurationForm', 'validateConfigurationForm', 'submitConfigurationForm'),
array(array(), 'aggregator_test', array('description' => ''), $this->configFactory)
);
$test_processor->expects($this->at(0))
->method('buildConfigurationForm')
->with($this->anything(), $form_state)
->will($this->returnArgument(0));
$test_processor->expects($this->at(1))
->method('validateConfigurationForm')
->with($this->anything(), $form_state);
$test_processor->expects($this->at(2))
->method('submitConfigurationForm')
->with($this->anything(), $form_state);
$this->managers['processor']->expects($this->once())
->method('createInstance')
->with($this->equalTo('aggregator_test'))
->will($this->returnValue($test_processor));
$form = $this->settingsForm->buildForm(array(), $form_state);
$this->settingsForm->validateForm($form, $form_state);
$this->settingsForm->submitForm($form, $form_state);
}
}
// @todo Delete after https://www.drupal.org/node/2278383 is in.
namespace Drupal\Core\Form;
if (!function_exists('drupal_set_message')) {
function drupal_set_message() {}
}