ea-Geiertest
[ class tree: ea-Geier ] [ index: ea-Geier ] [ all elements ]

Source for file date.inc.php

Documentation is available at date.inc.php

  1. <?php
  2. /**
  3.  * test case for date functions
  4.  *
  5.  * LICENSE:
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  * This program is distributed in the hope that it will be useful,
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
  13.  * GNU General Public License for more details.
  14.  * You should have received a copy of the GNU General Public License along
  15.  * with this program; if not, write to the Free Software Foundation, Inc.,
  16.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  17.  *
  18.  * @package       ea-Geier
  19.  * @subpackage test
  20.  * @author       m2mtech <tech@m2m.at>
  21.  * @copyright  2007 m2m server software gmbh
  22.  * @license       http://www.gnu.org/licenses/gpl.html GNU General Public License Version 2
  23.  * @version       $Id: date.inc.php 99 2007-07-29 14:10:07Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * functions to be tested
  29.  */
  30. require_once('code/date.inc.php');
  31.  
  32. /**
  33.  * test case for date functions
  34.  *
  35.  * @package       ea-Geier
  36.  */
  37. class TestDate extends UnitTestCase {
  38.     
  39.     /**
  40.      * constructor
  41.      */
  42.     function TestDate() {
  43.         $this->UnitTestCase('Test Date Functions');
  44.     }
  45.  
  46.     /**
  47.      * tests checking date format
  48.      *
  49.      * checks
  50.      * - empty date
  51.      * - wrong format
  52.      * - wrong date
  53.      * - leap year
  54.      * - strange but valid format
  55.      * - no year
  56.      */
  57.     function testCheckDateFormat() {
  58.         // empty date
  59.         $date = '';
  60.         $this->assertFalse(checkDateFormat($date));
  61.         
  62.         // wrong format date
  63.         $date = '2007-10-10';
  64.         $this->assertFalse(checkDateFormat($date));
  65.  
  66.         // not existing
  67.         $date = '30.2.2007';
  68.         $this->assertFalse(checkDateFormat($date));
  69.  
  70.         // leap year
  71.         $date = '29.2.2004';
  72.         $this->assertTrue($result = checkDateFormat($date));
  73.         $this->assertEqual($result, array('year' => '2004', 'month' => '02', 'day' => '29', 'date' => '29.02.2004'));
  74.         $this->assertEqual($date, '29.02.2004');
  75.         
  76.         // strange format but valid
  77.         $date = '   29  -  2   04';
  78.         $this->assertTrue($result = checkDateFormat($date));
  79.         $this->assertEqual($result, array('year' => '2004', 'month' => '02', 'day' => '29', 'date' => '29.02.2004'));
  80.         $this->assertEqual($date, '29.02.2004');
  81.         
  82.         // other format
  83.         $date = '07-03-01';
  84.         $this->assertTrue($result = checkDateFormat($date, 'YYYY-MM-DD'));
  85.         $this->assertEqual($result, array('year' => '2007', 'month' => '03', 'day' => '01', 'date' => '2007-03-01'));
  86.         $this->assertEqual($date, '2007-03-01');        
  87.         
  88.         // no year
  89.         $date = '01-03';
  90.         $this->assertTrue($result = checkDateFormat($date));
  91.         $year = date('Y');
  92.         $this->assertEqual($result, array('year' => $year, 'month' => '03', 'day' => '01', 'date' => '01.03.' . $year));
  93.         $this->assertEqual($date, '01.03.' . $year);        
  94.  
  95.         // no year
  96.         $date = '03-01';
  97.         $this->assertTrue($result = checkDateFormat($date, 'YYYY-MM-DD'));
  98.         $year = date('Y');
  99.         $this->assertEqual($result, array('year' => $year, 'month' => '03', 'day' => '01', 'date' => $year . '-03-01'));
  100.         $this->assertEqual($date, $year . '-03-01');        
  101.  
  102.         // smaller than unix & windows capabilities
  103.         $date = '1818-03-01';
  104.         $this->assertTrue($result = checkDateFormat($date, 'YYYY-MM-DD'));
  105.         $this->assertEqual($result, array('year' => '1818', 'month' => '03', 'day' => '01', 'date' => '1818-03-01'));
  106.         $this->assertEqual($date, '1818-03-01');        
  107.  
  108.         // higher than unix & windows capabilities
  109.         $date = '2218-03-01';
  110.         $this->assertTrue($result = checkDateFormat($date, 'YYYY-MM-DD'));
  111.         $this->assertEqual($result, array('year' => '2218', 'month' => '03', 'day' => '01', 'date' => '2218-03-01'));
  112.         $this->assertEqual($date, '2218-03-01');        
  113.  
  114.     }
  115.  
  116.     /**
  117.      * tests date formating
  118.      *
  119.      * checks
  120.      * - empty date
  121.      * - correct date
  122.      * - non existing date
  123.      * - leap year
  124.      */
  125.     function testDateFormat() {
  126.         // empty date
  127.         $date = '';
  128.         $this->assertEqual(dateFormat($date), '01.01.2001');
  129.         
  130.         // correct date
  131.         $date = array('year' => 2007, 'month' => 7, 'day' => 3);
  132.         $this->assertEqual(dateFormat($date), '03.07.2007');
  133.         $this->assertEqual(dateFormat($date, 'YYYY-MM-DD'), '2007-07-03');
  134.  
  135.         // not exsisting date
  136.         $date = array('year' => 2007, 'month' => 2, 'day' => 30);
  137.         $this->assertEqual(dateFormat($date), '02.03.2007');
  138.         $this->assertEqual(dateFormat($date, 'YYYY-MM-DD'), '2007-03-02');
  139.  
  140.         // leap year
  141.         $date = array('year' => 2004, 'month' => 2, 'day' => 29);
  142.         $this->assertEqual(dateFormat($date), '29.02.2004');
  143.         $this->assertEqual(dateFormat($date, 'YYYY-MM-DD'), '2004-02-29');
  144.         
  145.         // smaller than unix & windows capabilities
  146.         $date = array('year' => 1804, 'month' => 2, 'day' => 23);
  147.         $this->assertEqual(dateFormat($date), '23.02.1804');
  148.         $this->assertEqual(dateFormat($date, 'YYYY-MM-DD'), '1804-02-23');
  149.         
  150.         // higher than unix & windows capabilities
  151.         $date = array('year' => 2804, 'month' => 2, 'day' => 23);
  152.         $this->assertEqual(dateFormat($date), '23.02.2804');
  153.         $this->assertEqual(dateFormat($date, 'YYYY-MM-DD'), '2804-02-23');
  154.         
  155.     }
  156.  
  157. }
  158. ?>

Documentation generated on Sun, 09 Sep 2007 17:08:20 +0200 by phpDocumentor 1.3.1