/**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Llama" feed.
     $feed = Feed::create(array('title' => 'Llama', 'url' => 'https://www.drupal.org/', 'refresh' => 900, 'checked' => 1389919932, 'description' => 'Drupal.org'));
     $feed->save();
     return $feed;
 }
예제 #2
0
 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->assertTrue(strpos($result, 'testing title'));
     $this->assertTrue(strpos($result, 'href="' . $aggregator_feed->getUrl()) . '"');
     $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
     $result = $this->render($build);
     $this->assertTrue(strpos($result, 'testing title') === 0);
     $this->assertTrue(strpos($result, $aggregator_feed->getUrl()) === FALSE);
     // 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->assertTrue(strpos($result, 'test title'));
     $this->assertTrue(strpos($result, 'href="' . $aggregator_item->getLink()) . '"');
     $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]);
     $result = $this->render($build);
     $this->assertTrue(strpos($result, 'test title') === 0);
     $this->assertTrue(strpos($result, $aggregator_item->getLink()) === FALSE);
 }
 /**
  * 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());
 }
 /**
  * {@inheritdoc}
  */
 protected function createEntity()
 {
     // Create a "Camelids" feed.
     $feed = Feed::create(array('title' => 'Camelids', 'url' => 'https://groups.drupal.org/not_used/167169', 'refresh' => 900, 'checked' => 1389919932, 'description' => 'Drupal Core Group feed'));
     $feed->save();
     // Create a "Llama" aggregator feed item.
     $item = Item::create(array('fid' => $feed->id(), 'title' => t('Llama'), 'path' => 'https://www.drupal.org/'));
     $item->save();
     return $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());
 }
예제 #6
0
 /**
  * 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()]));
 }
예제 #7
0
 /**
  * Returns a randomly generated feed edit object.
  *
  * @param string $feed_url
  *   (optional) If given, feed will be created with this URL, otherwise
  *   /rss.xml will be used. Defaults to NULL.
  * @param array $values
  *   (optional) Default values to initialize object properties with.
  *
  * @return \Drupal\aggregator\FeedInterface
  *   A feed object.
  */
 public function getFeedEditObject($feed_url = NULL, array $values = array())
 {
     $feed_name = $this->randomMachineName(10);
     if (!$feed_url) {
         $feed_url = \Drupal::url('view.frontpage.feed_1', array('query' => array('feed' => $feed_name), 'absolute' => TRUE));
     }
     $values += array('title' => $feed_name, 'url' => $feed_url, 'refresh' => '900');
     return Feed::create($values);
 }
예제 #8
0
 /**
  * Tests error handling when an invalid feed is added.
  */
 public function testInvalidFeed()
 {
     // Simulate a typo in the URL to force a curl exception.
     $invalid_url = 'http:/www.drupal.org';
     $feed = Feed::create(array('url' => $invalid_url, 'title' => $this->randomMachineName()));
     $feed->save();
     // Update the feed. Use the UI to be able to check the message easily.
     $this->drupalGet('admin/config/services/aggregator');
     $this->clickLink(t('Update items'));
     $this->assertRaw(t('The feed from %title seems to be broken because of error', array('%title' => $feed->label())));
 }
예제 #9
0
<?php

use Drupal\aggregator\Entity\Feed;
// Create a new feed.
$feed = Feed::create(array('title' => 'test', 'url' => 'http://drupal.org/project/issues/rss/drupal?categories=All', 'refresh' => 3600));
$feed->save();
// Let cron call QueueInterface::createItem() for us.
aggregator_cron();