/** * {@inheritdoc} * This provider only provide post (post_type = 'post') * and resource (post_type = 'attachment') items. */ public function getItems() { $items = []; $xml = Xml::loadFile($this->file); $this->processVersion($xml); $this->processNamespaces($xml); foreach ($xml->channel->item as $item) { $attributes = []; $wp = $item->children($this->namespaces['wp']); $content = $item->children('http://purl.org/rss/1.0/modules/content/'); $excerpt = $item->children($this->namespaces['excerpt']); $permalink = (string) $item->link; if ((string) $wp->post_type == 'attachment') { $permalink = $wp->attachment_url; } $importedItem = $this->makeItem($wp, (string) $permalink); if (is_null($importedItem)) { continue; } $importedItem->setTitle((string) $item->title); $importedItem->setContent((string) $content->encoded); $importedItem->setDate(new \DateTime((string) $wp->post_date_gmt)); $dc = $item->children('http://purl.org/dc/elements/1.1/'); if ((string) $wp->status == 'draft') { $attributes['draft'] = true; } $attributes['author'] = (string) $dc->creator; $attributes['excerpt'] = (string) $excerpt->encoded; $attributes['categories'] = []; $attributes['tags'] = []; foreach ($item->category as $category) { $att = $category->attributes(); if (isset($att['nicename']) === true) { if (isset($att['domain']) === true && (string) $att['domain'] == 'post_tag') { $attributes['tags'][] = (string) $category; continue; } $attributes['categories'][] = (string) $category; } } $importedItem->setAttributes($attributes); $items[] = $importedItem; } return $items; }
/** * @expectedException RuntimeException * @expectedExceptionMessage File "./not-found.xml" not found. */ public function testFailLoadNotFoundXmlFile() { $xml = Xml::loadFile('./not-found.xml'); }