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

Source for file sendpw.inc.php

Documentation is available at sendpw.inc.php

  1. <?php
  2. /**
  3.  * test case for send-password 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: sendpw.inc.php 106 2007-08-01 20:19:37Z m2mtech $
  24.  * @link       http://www.ea-geier.at/
  25.  */
  26.  
  27. /**
  28.  * functions to be tested
  29.  */
  30. require_once('code/base/sendpw.inc.php');
  31.  
  32. /**
  33.  * helper class - input validator
  34.  */
  35. require_once('code/base/input.class.php');
  36. Mock::generate('eaInput');
  37.  
  38. /**
  39.  * helper class - database
  40.  */
  41. require_once('code/base/db.class.php');
  42. Mock::generate('eaDB');
  43.  
  44. /**
  45.  * test case for send-password functions
  46.  *
  47.  * @package       ea-Geier
  48.  */
  49. class TestSendPW extends UnitTestCase {
  50.     
  51.     /**
  52.      * constructor
  53.      */
  54.     function TestSendPW({
  55.         $this->UnitTestCase('Test Send-Password Functions');
  56.     }
  57.  
  58.     /**
  59.      * start FakeMail server & remove old mails
  60.      */
  61.     function setUp({
  62.         if (eaFAKEMAIL_DIR == 'none'return false// no test
  63.         $output false;
  64.         if (exec('ps ax | grep fakemail'$output)) {
  65.             foreach ($output as $line{
  66.                 if (preg_match('/grep/'$line)) continue;
  67.                 $match false;
  68.                 if (preg_match('/[0-9]+/'$line$match)) {
  69.                     $command 'kill ' $match[0];
  70.                     `$command`;
  71.                     echo 'fake-mail server stopped';
  72.                 }                    
  73.             }
  74.         }
  75.         $command eaFAKEMAIL_DIR 'fakemail --path=' eaFAKEMAIL_TMP ' --host=' eaFAKEMAIL_SERVER ' --port=' eaFAKEMAIL_PORT ' --background';
  76.         $this->pid = `$command`;
  77.         @unlink(eaFAKEMAIL_TMP 'test@ea-geier.at.1');
  78.     }
  79.     
  80.     /**
  81.      * stop FakeMail server & remove mails
  82.      */
  83.     function tearDown({
  84.         if (eaFAKEMAIL_DIR == 'none'return false// no test
  85.         $command 'kill ' $this->pid;
  86.         `$command`;
  87.     }
  88.  
  89.     /**
  90.      * tests option generation
  91.      *
  92.      * - no real functionality at the moment
  93.      */
  94.     function testGenOpt({
  95.         $in false;
  96.     
  97.         genOptSendPW($in);
  98.     }
  99.  
  100.     /**
  101.      * tests password generation
  102.      *
  103.      * checks:
  104.      * - generating password
  105.      * - generating of different passwords
  106.      */
  107.     function testGenPW({
  108.         // generating password
  109.         $this->assertTrue($pw genPW());
  110.  
  111.         // generating different passwords
  112.         $this->assertTrue($pw != genPW());
  113.     }
  114.  
  115.     /**
  116.      * tests password sinding
  117.      *
  118.      * checks:
  119.      * - input errors
  120.      * - missing variables
  121.      * - not exisitng users
  122.      * - database problems
  123.      * - sending
  124.      */
  125.     function testSendPWFunction({
  126.         $in new MockeaInput();
  127.  
  128.         $db new MockeaDB();
  129.         
  130.         $conf $GLOBALS['conf'];
  131.         $db->conf =$conf;
  132.  
  133.         // no post data
  134.         $this->assertFalse(sendPW($db$in));
  135.         
  136.         $_POST['buttonSendPW'true// button pressed
  137.         
  138.         // input error
  139.         $in->error array('testinputerror' => true)
  140.         $this->assertFalse(sendPW($db$in));
  141.         $in->error array();
  142.  
  143.         // missing variable
  144.         $this->assertFalse(sendPW($db$in));
  145.         $in->error array();
  146.  
  147.         // not existing user
  148.         $in->post array('mail' => 'test@ea-geier.at');
  149.         $db->setReturnValueAt(0'isUser'false);    
  150.         $this->assertFalse(sendPW($db$in));
  151.         $in->error array();
  152.  
  153.         // password not written
  154.         $db->setReturnValueAt(1'isUser'true);    
  155.         $db->setReturnValueAt(0'setPW'false);
  156.         $this->assertFalse(sendPW($db$in));
  157.         $in->error array();
  158.  
  159.         // password sent
  160.         if (eaFAKEMAIL_DIR == 'none'return false// no test
  161.         
  162.         $conf['txtMailServer'eaFAKEMAIL_SERVER;
  163.         $conf['numMailPort'eaFAKEMAIL_PORT;
  164.         $conf['mailFrom''server@ea-geier.at';
  165.         $db->setReturnValueAt(2'isUser'true);    
  166.         $db->setReturnValueAt(1'setPW'true);
  167.         $this->assertTrue(sendPW($db$in));
  168.         $this->assertTrue(is_file(eaFAKEMAIL_TMP 'test@ea-geier.at.1'));
  169.  
  170.         @unlink(eaFAKEMAIL_TMP 'test@ea-geier.at.1');
  171.  
  172.         unset($_POST['buttonSendPW']);
  173.     }
  174.  
  175. }
  176. ?>

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