/** * @Given /^the "([^"]*)" "([^"]*)" is "([^"]*)" at index (\d+)$/ */ public function theWidgetPropertyIsAtIndex($widgetName, $property, $value, $index, $stringSearch = false) { $widget = Widget::getPostWidgetsFiltered(self::$post, $widgetName, $index); Assert::assertNotNull($widget); Assert::assertTrue(isset($widget[$property])); if ($stringSearch) { Assert::assertContains($value, $widget[$property]); } else { Assert::assertEquals($value, $widget[$property]); } }
public static function getPostFromUrl($postUrl) { $fail = false; $postJsonUrl = $postUrl . '.json'; try { $postString = file_get_contents($postJsonUrl); } catch (Exception $e) { self::notifyError('Unable to retrieve JSON from URL ' . $postJsonUrl); return false; } if (!($object = json_decode($postString))) { self::notifyError('Unable to retrieve JSON from URL ' . $postJsonUrl); $fail = true; } if (!isset($object->article)) { self::notifyError('"Article" property does not exist in JSON, might be a full page embed or microsite'); $fail = true; } if ($fail) { return false; } $postObject = $object->article; $postDom = HtmlDomParser::str_get_html($object->content); $postReformatted = new stdClass(); $meshPost = new \Mesh\Post($postObject->slug); $meshPost->set('catfish_importer_url', $postUrl, true); $meshPost->set('catfish_importer_imported', true, true); $meshPost->set('catfish_importer_date_updated', time(), true); $meshPost->set('post_title', $postObject->headline); $meshPost->set('header_type', 'standard-hero'); $meshPost->set('header_display_headline', true); $meshPost->set('header_display_sell', true); // Set post published date $displayDate = strtotime($postObject->displayDate); $displayDate = date('o\\-m\\-d G\\:i\\:s', $displayDate); wp_update_post(array('ID' => $meshPost->id, 'post_date' => $displayDate, 'post_date_gmt' => $displayDate, 'post_modified' => $displayDate, 'post_modified_gmt' => $displayDate)); if (isset($object->article->__author) && isset($object->article->__author->emailAddress) && $object->article->__author->emailAddress) { $meshPost->set('post_author', self::setAuthor($object->article->__author)); } else { $get_author_details = get_field('catfish_default_author', 'option'); $default_author = $get_author_details['ID']; $meshPost->set('post_author', $default_author, true); } Category::attachCategories($object->article->section, $postUrl, $meshPost->id); $postTags = array(); foreach ($object->article->tags as $tag) { if ($tag->type !== 'System') { array_push($postTags, ucwords($tag->tag)); } } wp_set_post_tags($meshPost->id, $postTags); $sell = !empty($postObject->sell) ? $postObject->sell : $postObject->headline; $meshPost->set('short_headline', $postObject->shortHeadline, true); $meshPost->set('sell', $sell, true); $meshPost->set('catfish_importer_imported', true, true); // If automated testing, set some metadata if (isset($_SERVER['is-automated-testing'])) { $meshPost->set('automated_testing', true, true); } if (!($post = new TimberPost($meshPost->id))) { self::notifyError('Unexpected exception where Mesh did not create/fetch a post'); } $show_header = self::setHeroImages($post, $postDom, $postObject); $meshPost->set('header_display_hero_image', $show_header); $widgets = Widget::getWidgetsFromDom($postDom); Widget::setPostWidgets($post, $widgets, $postObject); do_action('catfish_importer_post', $post->ID); return $post; }