public function test() { $feed = $this->getMock('Drupal\\feeds\\FeedInterface'); $result = $this->getMock('Drupal\\feeds\\Result\\FetcherResultInterface'); $event = new FetchEvent($feed); $event->setFetcherResult($result); $this->assertSame($result, $event->getFetcherResult()); }
/** * Subscribes to a feed. */ public function onPostFetch(FetchEvent $event) { $feed = $event->getFeed(); $fetcher = $feed->getType()->getFetcher(); $subscription = $this->storage->load($feed->id()); if (!$fetcher->getConfiguration('use_pubsubhubbub')) { return $this->unsubscribe($feed, $subscription); } if (!($hub = $this->findRelation($event->getFetcherResult(), 'hub'))) { $hub = $fetcher->getConfiguration('fallback_hub'); } // No hub found. if (!$hub) { return $this->unsubscribe($feed, $subscription); } // Used to make other URLs absolute. $source_url = Url::fromString($feed->getSource()); $hub = (string) $source_url->combine($hub); // If there is a rel="self" relation. if ($topic = $this->findRelation($event->getFetcherResult(), 'self')) { $topic = (string) $source_url->combine($topic); $feed->setSource($topic); } else { $topic = $feed->getSource(); } // Subscription does not exist yet. if (!$subscription) { $subscription = $this->storage->create(['fid' => $feed->id(), 'topic' => $topic, 'hub' => $hub]); return $this->subscribe($feed, $subscription); } if ($topic !== $subscription->getTopic() || $subscription->getHub() !== $hub || $subscription->getState() !== 'subscribed') { // Unsubscribe from the old feed. $this->unsubscribe($feed, $subscription); $subscription = $this->storage->create(['fid' => $feed->id(), 'topic' => $topic, 'hub' => $hub]); return $this->subscribe($feed, $subscription); } }