/** * Ensures that webSearch() throws an exception when the type option is invalid * * @return void */ public function testWebSearchExceptionTypeInvalid() { try { $this->_yahoo->webSearch('php', array('type' => 'oops')); $this->fail('Expected Zend_Service_Exception not thrown'); } catch (Zend_Service_Exception $e) { $this->assertContains("option 'type'", $e->getMessage()); } }
/** * Ensures that webSearch() throws an exception when the similar_ok option is invalid * * @return void */ public function testWebSearchExceptionSimilarOkInvalid() { try { $this->_yahoo->webSearch('php', array('similar_ok' => 'oops')); $this->fail('Expected Zend_Service_Exception not thrown'); } catch (Zend_Service_Exception $e) { $this->assertContains('error occurred sending request', $e->getMessage()); } }
/** * Ensures that webSearch() works as expected when searching for 'php' * * @see ZF-2358 */ public function testWebSearchForSite() { $webResultSet = $this->_yahoo->webSearch('php', array('site' => 'www.php.net')); $this->assertTrue($webResultSet instanceof Zend_Service_Yahoo_WebResultSet); $this->assertTrue($webResultSet->totalResultsAvailable > 10); $this->assertEquals(10, $webResultSet->totalResultsReturned); $this->assertEquals(10, $webResultSet->totalResults()); $this->assertEquals(1, $webResultSet->firstResultPosition); foreach ($webResultSet as $webResult) { $this->assertTrue($webResult instanceof Zend_Service_Yahoo_WebResult); } }
<h1>Yahoo! Multi-Search</h1> <form action="<?php echo $_SERVER['SCRIPT_NAME']; ?> " method="post"> <p> <label>Search For: <input type="text" name="search_term" value="<?php echo htmlspecialchars($keywords, ENT_QUOTES); ?> "></label> <input type="submit" value="Search!"> </p> </form> <?php if (strtolower($_SERVER['REQUEST_METHOD']) == 'post') { $yahoo = new Zend_Service_Yahoo('zendtesting'); try { $results = $yahoo->imageSearch($keywords, array("results" => 5)); if ($results->totalResults() > 0) { echo '<div id="image">'; echo '<h2>Image Search Results</h2>'; foreach ($results as $result) { echo "<a href='{$result->ClickUrl}' title='{$result->Title}'><img src='{$result->Thumbnail->Url->getUri()}'></a>"; } echo '</div>'; } $results = $yahoo->webSearch($keywords); if ($results->totalResults() > 0) { echo '<div id="web">'; echo '<h2>Web Search Results</h2>'; foreach ($results as $result) {