public function testGetJSONReturnsValidJSON() { global $CONFIG; $jsonCache = new JsonCache(); $API_CALL = "/wp-json/posts?filter[orderby]=date&filter[posts_per_page]=3"; $queryURL = $CONFIG['blogURL'] . $API_CALL; $result = json_decode($jsonCache->get_json($queryURL, $CONFIG['cacheDir'], $CONFIG['cacheExpires'])); $this->assertInternaltype('array', $result); }
/** * @covers ::__construct * @covers ::get * @covers ::loadMessages * @covers ::getAvailableLanguages */ public function testHappyPath() { $fixture = new JsonCache(__DIR__ . '/fixtures/JsonCacheTest'); $langs = $fixture->getAvailableLanguages(); $this->assertEquals(array('en', 'foo'), $langs); foreach ($langs as $lang) { $this->assertEquals($lang, $fixture->get('lang', $lang)); $this->assertFalse($fixture->get('key-not-found', $lang)); } }
<?php $API_CALL = "/wp-json/posts?filter[orderby]=date&filter[posts_per_page]=3"; require_once 'includes/config.php'; require_once 'includes/jsonCache.php'; $jsonCache = new JsonCache(); $queryURL = $CONFIG['blogURL'] . $API_CALL; $topnews = json_decode($jsonCache->get_json($queryURL, $CONFIG['cacheDir'], $CONFIG['cacheExpires'])); //template for output foreach ($topnews as $item) { ?> <a href="post.php?id=<?php echo $item->ID; ?> "> <?php echo $item->title; ?> </a> <br> <?php }