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); }
/** * Test processing functionality. */ public function testProcess() { $feed = $this->createFeed(); $this->updateFeedItems($feed); foreach ($feed->items as $iid) { $item = Item::load($iid); $this->assertTrue(strpos($item->label(), 'testProcessor') === 0); } }
/** * 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()); }
/** * Tests that when creating a feed item, the feed tag is invalidated. */ public function testEntityCreation() { // Create a cache entry that is tagged with a feed cache tag. \Drupal::cache('render')->set('foo', 'bar', \Drupal\Core\Cache\CacheBackendInterface::CACHE_PERMANENT, $this->entity->getCacheTag()); // Verify a cache hit. $this->verifyRenderCache('foo', array('aggregator_feed:1')); // Now create a feed item in that feed. Item::create(array('fid' => $this->entity->getFeedId(), 'title' => t('Llama 2'), 'path' => 'https://groups.drupal.org/'))->save(); // Verify a cache miss. $this->assertFalse(\Drupal::cache('render')->get('foo'), 'Creating a new feed item invalidates the cache tag of the feed.'); }
/** * Test Drupal 6 aggregator item migration to Drupal 8. */ public function testAggregatorItem() { /** @var 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()); }
/** * 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()); } }
/** * 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); }
/** * {@inheritdoc} */ public function process(FeedInterface $feed) { if (!is_array($feed->items)) { return; } foreach ($feed->items as $item) { // @todo: The default entity view builder always returns an empty // array, which is ignored in aggregator_save_item() currently. Should // probably be fixed. if (empty($item['title'])) { continue; } // Save this item. Try to avoid duplicate entries as much as possible. If // we find a duplicate entry, we resolve it and pass along its ID is such // that we can update it if needed. if (!empty($item['guid'])) { $values = array('fid' => $feed->id(), 'guid' => $item['guid']); } elseif ($item['link'] && $item['link'] != $feed->link && $item['link'] != $feed->url) { $values = array('fid' => $feed->id(), 'link' => $item['link']); } else { $values = array('fid' => $feed->id(), 'title' => $item['title']); } // Try to load an existing entry. if ($entry = entity_load_multiple_by_properties('aggregator_item', $values)) { $entry = reset($entry); } else { $entry = Item::create(array('langcode' => $feed->language()->getId())); } if ($item['timestamp']) { $entry->setPostedTime($item['timestamp']); } // Make sure the item title and author fit in the 255 varchar column. $entry->setTitle(Unicode::truncate($item['title'], 255, TRUE, TRUE)); $entry->setAuthor(Unicode::truncate($item['author'], 255, TRUE, TRUE)); $entry->setFeedId($feed->id()); $entry->setLink($item['link']); $entry->setGuid($item['guid']); $description = ''; if (!empty($item['description'])) { $description = $item['description']; } $entry->setDescription($description); $entry->save(); } }