PHP Classes

File: Test/Google/AdvancedQuery.php

Recommend this page to a friend!
  Classes of MARY Matthieu   Google_Query   Test/Google/AdvancedQuery.php   Download  
File: Test/Google/AdvancedQuery.php
Role: Unit test script
Content type: text/plain
Description: Unit test class for Google_AdvancedQuery
Class: Google_Query
Retrieve the count of results of Google query
Author: By
Last change:
Date: 16 years ago
Size: 2,838 bytes
 

Contents

Class file image Download
<?php
/**
 * $Id: AdvancedQuery.php 1631 2007-05-12 22:40:28Z matthieu $
 */
if (!class_exists('Test_Google_AdvancedQuery')) {
    if (!
defined('__CLASS_PATH__')) {
       
define('__CLASS_PATH__', realpath(dirname(__FILE__) . '/../../'));
    }
    require_once
__CLASS_PATH__ . '/Autoload.php';
   
/**
     * test class for google package
     * @package google
     * @subpackage unit_test_case
     */
   
class Test_Google_AdvancedQuery extends Test_Google_Query
   
{
       
/**
        * default constructor
        * @access public
        * @return void
        */
       
public function __construct()
        {
           
parent :: __construct();
           
$this->deleteLocalPatternFile();
        }
       
/**
         * prepare test
         * @access public
         * @return void
         */
       
public function setUp()
        {
           
$this->_analysedObject = new Google_AdvancedQuery();
           
$this->_analysedObject->setSentence(self :: __KEYWORDS__);
        }
       
/**
         * @access public
         * @return void
         */
       
public function tearDown()
        {
           
$this->deleteLocalPatternFile();
        }
       
/**
         * clean the local pattern file
         * @acess private
         * @return void
         * @throws Exception
         */
       
private function deleteLocalPatternFile()
        {
           
$patternFile = Google_AdvancedQuery :: getFilePattern();
            if (
file_exists($patternFile)) {
                if (!
unlink($patternFile)) {
                    throw new
Exception('Cannot clean the previous pattern file: ' . $patternFile);
                }
            }
        }
       
/**
         * check if configuration url is valid
         * @access public
         * @return void
         */
       
public function testUrlUsed()
        {
           
$content = file_get_contents(Google_AdvancedQuery :: __PATTERN_REMOTE_URL__);
           
$this->assertFalse(empty ($content), "Unable to retrieve the remote pattern at " . Google_AdvancedQuery :: __PATTERN_REMOTE_URL__ . ".If you have updated Google_AdvancedQuery class, make sure that your url is valid. Otherwise, " . "send me an email at matthieu@phplibrairies.com to notify me of the of the url");
        }
       
/**
         * test if local file already exists
         * @access public
         * @return void
         */
       
public function testLocalFileExists() {
           
$this->assertTrue(file_exists(Google_AdvancedQuery :: getFilePattern()),
            
"Unable to check ".Google_AdvancedQuery :: getFilePattern().". If testUrlUsed works fine, ensure that you have write acces in ".dirname(Google_AdvancedQuery :: getFilePattern()));
        }
    }
}