<?php
/**
 * PhpMyObject extensions to Simpletest SimpleExpectation class.
 *
 * This file is part of the PhpMyObject project,
 * an Object-Relational Mapping (ORM) system.
 * 
 * For questions, help, comments, discussion, etc., please join our
 * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770} 
 * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
 *
 * PhpMyObject is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * @package    	PhpMyObject
 * @subpackage 	PMO_Tests
 * @author     	Louis Lapointe <laplix@gmail.com>
 * @link				http://pmo.developpez.com/
 * @since 			PhpMyObject v0.15
 * @version       $Revision$
 * @copyright  	Copyright (C) 2008 Louis Lapointe
 * @license    	GPLv3 {@link http://www.gnu.org/licenses/gpl}
 * @filesource
 */

/**
 * requires needed libraries from simpletest.
 */
require_once(SIMPLETEST . DS . 'expectation.php');

if (!class_exists('GreaterThanExpectation')) {

	/**
	 * Extends SimpleExpectation class with a GreaterThanExpctation
	 *
	 * @package 		PAL
	 * @subpackage 	PAL.Tests
	 */
   class GreaterThanExpectation extends SimpleExpectation
   {
      var $_value;

      /**
      *    Sets the value to compare against.
      *    @param mixed $value        Test value to match.
      *    @param string $message     Customised message on failure.
      *    @access public
      */
      function GreaterThanExpectation($value, $message = '%s') {
         $this->SimpleExpectation($message);
         $this->_value = $value;
      }

      /**
      *    Tests the expectation. True if it is greater than the
      *    held value.
      *    @param mixed $compare        Comparison value.
      *    @return boolean              True if correct.
      *    @access public
      */
      function test($compare) {
         return (($this->_value > $compare) && ($compare < $this->_value));
      }

      /**
      *    Returns a human readable test message.
      *    @param mixed $compare      Comparison value.
      *    @return string             Description of success
      *                               or failure.
      *    @access public
      */
      function testMessage($compare) {
         if ($this->test($compare)) {
             return "GreaterThan expectation [" . $this->_dumper->describeValue($this->_value) . "]";
         } else {
             return "GreaterThan expectation fails " .
                     $this->_dumper->describeDifference($this->_value, $compare);
         }
      }

   }
}

if (!class_exists('LowerThanExpectation')) {

	/**
	 * Extends SimpleExpectation class with a LowerThanExpctation
	 *
	 * @package 		PAL
	 * @subpackage 	PAL.Tests
	 */
   class LowerThanExpectation extends SimpleExpectation
   {
      var $_value;

      /**
      *    Sets the value to compare against.
      *    @param mixed $value        Test value to match.
      *    @param string $message     Customised message on failure.
      *    @access public
      */
      function LowerThanExpectation($value, $message = '%s') {
         $this->SimpleExpectation($message);
         $this->_value = $value;
      }

      /**
      *    Tests the expectation. True if it is lower than the
      *    held value.
      *    @param mixed $compare        Comparison value.
      *    @return boolean              True if correct.
      *    @access public
      */
      function test($compare) {
         return (($this->_value < $compare) && ($compare > $this->_value));
      }

      /**
      *    Returns a human readable test message.
      *    @param mixed $compare      Comparison value.
      *    @return string             Description of success
      *                               or failure.
      *    @access public
      */
      function testMessage($compare) {
         if ($this->test($compare)) {
             return "LowerThan expectation [" . $this->_dumper->describeValue($this->_value) . "]";
         } else {
             return "LowerThan expectation fails " .
                     $this->_dumper->describeDifference($this->_value, $compare);
         }
      }

   }
}

if (!class_exists('IsEmptyExpectation')) {

	/**
	 * Extends SimpleExpectation class with a IsEmptyExpctation
	 *
	 * @package 		PAL
	 * @subpackage 	PAL.Tests
	 */
   class IsEmptyExpectation extends SimpleExpectation
   {
      var $_value;

      /**
      *    Sets the value to compare against.
      *    @param mixed $value        Test value to match.
      *    @param string $message     Customised message on failure.
      *    @access public
      */
      function IsEmptyExpectation($value, $message = '%s') {
         $this->SimpleExpectation($message);
         $this->_value = $value;
      }

      /**
		 *    Tests the expectation. True if held value is empty.
		 *
      *    @param mixed $compare        Comparison value.
      *    @return boolean              True if correct.
      *    @access public
      */
      function test($compare) {
         return ((empty($this->_value)) ? true : false);
      }

      /**
      *    Returns a human readable test message.
      *    @param mixed $compare      Comparison value.
      *    @return string             Description of success
      *                               or failure.
      *    @access public
      */
      function testMessage($compare) {
         if ($this->test($compare)) {
             return "IsEmpty expectation [" . $this->_dumper->describeValue($this->_value) . "]";
         } else {
             return "IsEmpty expectation fails " .
                     $this->_dumper->describeDifference($this->_value, $compare);
         }
      }

   }
}

if (!class_exists('NotEmptyExpectation')) {

	/**
	 * Extends SimpleExpectation class with a NotEmptyExpctation
	 *
	 * @package 		PAL
	 * @subpackage 	PAL.Tests
	 */
   class NotEmptyExpectation extends SimpleExpectation
   {
      var $_value;

      /**
      *    Sets the value to compare against.
      *    @param mixed $value        Test value to match.
      *    @param string $message     Customised message on failure.
      *    @access public
      */
      function NotEmptyExpectation($value, $message = '%s') {
         $this->SimpleExpectation($message);
         $this->_value = $value;
      }

      /**
		 *    Tests the expectation. True if held value is not empty.
		 *
      *    @param mixed $compare        Comparison value.
      *    @return boolean              True if correct.
      *    @access public
      */
      function test($compare) {
         return ((!empty($this->_value)) ? true : false);
      }

      /**
      *    Returns a human readable test message.
      *    @param mixed $compare      Comparison value.
      *    @return string             Description of success
      *                               or failure.
      *    @access public
      */
      function testMessage($compare) {
         if ($this->test($compare)) {
             return "NotEmpty expectation [" . $this->_dumper->describeValue($this->_value) . "]";
         } else {
             return "NotEmpty expectation fails " .
                     $this->_dumper->describeDifference($this->_value, $compare);
         }
      }

   }
}


