/** * Parses the raw result data for validity and then into formatted data * * @param stdClass $resultData */ protected function parse(stdClass $resultData) { if (!isset($resultData->kind) || $resultData->kind != self::KIND) { throw new Google_CustomSearch_ErrorException(sprintf('Invalid result kind. Expected "%s".', self::KIND), Google_CustomSearch_ErrorException::ITEM_KIND_INVALID); } $this->parseStandardProperties($resultData, array('displayLink', 'htmlSnippet', 'htmlTitle', 'link', 'snippet', 'title')); $pagemap = self::getPropertyFromResponseData('pagemap', $resultData); if ($pagemap instanceof stdClass) { $pagemap = new Google_CustomSearch_Response_Result_PageMap($pagemap); if ($pagemap->hasDataObjects()) { $this->pagemap = $pagemap; } } }
/** * @depends testConstruct */ public function testGenericGetters(Google_CustomSearch_Response_Result_PageMap $pageMap) { $this->assertTrue($pageMap->hasDataObjects()); $this->assertType('array', $pageMap->getDataObjects()); $this->assertEquals(2, count($pageMap->getDataObjects())); foreach ($pageMap->getDataObjects() as $dataObject) { $this->assertType('Google_CustomSearch_Response_Result_PageMap_DataObject', $dataObject); } $this->assertNull($pageMap->getDataObject('invalid_1')); $this->assertType('Google_CustomSearch_Response_Result_PageMap_DataObject', $pageMap->getDataObject('test2')); }