Net_Sieve
[ class tree: Net_Sieve ] [ index: Net_Sieve ] [ all elements ]

Source for file SieveTest.php

Documentation is available at SieveTest.php

  1. <?php
  2.  
  3. // +-----------------------------------------------------------------------+
  4. // | Copyright (c) 2006, Anish Mistry                                      |
  5. // | All rights reserved.                                                  |
  6. // |                                                                       |
  7. // | Redistribution and use in source and binary forms, with or without    |
  8. // | modification, are permitted provided that the following conditions    |
  9. // | are met:                                                              |
  10. // |                                                                       |
  11. // | o Redistributions of source code must retain the above copyright      |
  12. // |   notice, this list of conditions and the following disclaimer.       |
  13. // | o Redistributions in binary form must reproduce the above copyright   |
  14. // |   notice, this list of conditions and the following disclaimer in the |
  15. // |   documentation and/or other materials provided with the distribution.|
  16. // |                                                                       |
  17. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   |
  18. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     |
  19. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
  20. // | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  |
  21. // | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
  22. // | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      |
  23. // | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
  24. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
  25. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   |
  26. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
  27. // | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  |
  28. // |                                                                       |
  29. // +-----------------------------------------------------------------------+
  30. // | Author: Anish Mistry <amistry@am-productions.biz>                     |
  31. // +-----------------------------------------------------------------------+
  32.  
  33. require_once("password.inc.php");
  34. require_once('./Sieve.php');
  35. require_once('PHPUnit2/Framework/TestCase.php');
  36.  
  37. class SieveTest extends PHPUnit2_Framework_TestCase
  38. {
  39.     // contains the object handle of the string class
  40.     protected $fixture;
  41.     
  42.     protected function setUp()
  43.     {
  44.         // create a new instance of Net_Sieve
  45.         $this->fixture = new Net_Sieve();
  46.         $this->scripts = array();
  47.         $this->scripts['test script1'"require \"fileinto\";\n\rif header :contains \"From\" \"@cnba.uba.ar\" \n\r{fileinto \"INBOX.Test1\";}\r\nelse \r\n{fileinto \"INBOX\";}";
  48.         $this->scripts['test script2'"require \"fileinto\";\n\rif header :contains \"From\" \"@cnba.uba.ar\" \n\r{fileinto \"INBOX.Test\";}\r\nelse \r\n{fileinto \"INBOX\";}";
  49.         $this->scripts['test script3'"require \"vacation\";\nvacation\n:days 7\n:addresses [\"matthew@de-construct.com\"]\n:subject \"This is a test\"\n\"I'm on my holiday!\nsadfafs\";";
  50.         $this->scripts['test script4'file_get_contents("largescript.siv");
  51.         // clear all the scripts in the account
  52.         $this->login();
  53.         $scripts $this->fixture->listScripts();
  54.         foreach($scripts as $script)
  55.         {
  56.             $this->fixture->removeScript($script);
  57.         }
  58.         $this->logout();
  59.     }
  60.     
  61.     protected function tearDown()
  62.     {
  63.         // delete your instance
  64.         unset($this->fixture);
  65.     }
  66.     
  67.     protected function login()
  68.     {
  69.         $result $this->fixture->connect(HOST PORT);
  70.         $this->assertTrue($result,"Can not connect");
  71.         $result $this->fixture->login(USERNAMEPASSWORD  null ''false );
  72.         $this->assertTrue($result,"Can not login");
  73.     }
  74.  
  75.     protected function logout()
  76.     {
  77.         $result $this->fixture->disconnect();
  78.         $this->assertTrue(!PEAR::isError($result),"Error on disconnect");
  79.     }
  80.  
  81.     public function testConnect()
  82.     {
  83.         $result $this->fixture->connect(HOST PORT);
  84.         $this->assertTrue($result,"Can not connect");
  85.     }
  86.     
  87.     public function testLogin()
  88.     {
  89.         $result $this->fixture->connect(HOST PORT);
  90.         $this->assertTrue($result,"Can not connect");
  91.         $result $this->fixture->login(USERNAMEPASSWORD  null ''false );
  92.         $this->assertTrue($result,"Can not login");
  93.     }
  94.  
  95.     public function testDisconnect()
  96.     {
  97.         $result $this->fixture->connect(HOST PORT);
  98.         $this->assertTrue(!PEAR::isError($result),"Can not connect");
  99.         $result $this->fixture->login(USERNAMEPASSWORD  null ''false );
  100.         $this->assertTrue(!PEAR::isError($result),"Can not login");
  101.         $result $this->fixture->disconnect();
  102.         $this->assertTrue(!PEAR::isError($result),"Error on disconnect");
  103.     }
  104.  
  105.     public function testListScripts()
  106.     {
  107.         $this->login();
  108.         $scripts $this->fixture->listScripts();
  109.         $this->logout();
  110.  
  111.         $this->assertTrue(!PEAR::isError($scripts),"Can not list scripts");
  112.     }
  113.  
  114.     public function testInstallScript()
  115.     {
  116.         $this->login();
  117.         // first script
  118.         $scriptname "test script1";
  119.         $before_scripts $this->fixture->listScripts();
  120.         $result $this->fixture->installScript$scriptname$this->scripts[$scriptname]);
  121.         $this->assertTrue(!PEAR::isError($result),"Can not install script ".$scriptname);
  122.         $after_scripts $this->fixture->listScripts();
  123.         $diff_scripts array_values(array_diff($after_scripts,$before_scripts));
  124.         $this->assertTrue(count($diff_scripts> 0,"Script not installed");
  125.         $this->assertEquals($scriptname,$diff_scripts[0],0,"Added script has a different name");
  126.         // second script (install and activate)
  127.         $scriptname "test script2";
  128.         $before_scripts $this->fixture->listScripts();
  129.         $result $this->fixture->installScript$scriptname$this->scripts[$scriptname]true);
  130.         $this->assertTrue(!PEAR::isError($result),"Can not install script ".$scriptname);
  131.         $after_scripts $this->fixture->listScripts();
  132.         $diff_scripts array_values(array_diff($after_scripts,$before_scripts));
  133.         $this->assertTrue(count($diff_scripts> 0,"Script not installed");
  134.         $this->assertEquals($scriptname,$diff_scripts[0],0,"Added script has a different name");
  135.         $active_script $this->fixture->getActive();
  136.         $this->assertEquals($scriptname,$active_script,0,"Added script has a different name");
  137.         $this->logout();
  138.     }
  139.  
  140.     public function testInstallScriptLarge()
  141.     /*
  142.     There is a good chance that this test will fail since most servers have a 32KB limit
  143.     on uploaded scripts.
  144.     */
  145.     {
  146.         $this->login();
  147.         // first script
  148.         $scriptname "test script4";
  149.         $before_scripts $this->fixture->listScripts();
  150.         $result $this->fixture->installScript$scriptname$this->scripts[$scriptname]);
  151.         $this->assertTrue(!PEAR::isError($result),"Unable to upload large script");
  152.         $after_scripts $this->fixture->listScripts();
  153.         $diff_scripts array_diff($before_scripts,$after_scripts);
  154.         $this->assertEquals($scriptname,$diff_scripts[0],0,"Added script has a different name");
  155.         $this->logout();
  156.     }
  157.  
  158.     public function testGetScript()
  159.     {
  160.         $this->login();
  161.         // first script
  162.         $scriptname "test script1";
  163.         $before_scripts $this->fixture->listScripts();
  164.         $result $this->fixture->installScript$scriptname$this->scripts[$scriptname]);
  165.         $this->assertTrue(!PEAR::isError($result),"Can not install script ".$scriptname);
  166.         $after_scripts $this->fixture->listScripts();
  167.         $diff_scripts array_values(array_diff($after_scripts,$before_scripts));
  168.         $this->assertTrue(count($diff_scripts> 0);
  169.         $this->assertEquals($scriptname,$diff_scripts[0],0,"Added script has a different name");
  170.         $script $this->fixture->getScript($scriptname);
  171.         $this->assertEquals(trim($this->scripts[$scriptname]),trim($script),0,"Script installed it not the same script retrieved");
  172.         $this->logout();
  173.     }
  174.  
  175.     public function testGetActive()
  176.     {
  177.         $this->login();
  178.         $active_script $this->fixture->getActive();
  179.         $this->assertTrue(!PEAR::isError($active_script),"Error getting the active script");
  180.         $this->logout();
  181.     }
  182.  
  183.     public function testSetActive()
  184.     {
  185.         $scriptname "test script1";
  186.         $this->login();
  187.         $result $this->fixture->installScript$scriptname$this->scripts[$scriptname]);
  188.         $result $this->fixture->setActive($scriptname);
  189.         $this->assertTrue(!PEAR::isError($result),"Can not set active script");
  190.         $active_script $this->fixture->getActive();
  191.         $this->assertEquals($scriptname,$active_script,0,"Active script does not match");
  192.  
  193.         // test for non-existant script
  194.         $result $this->fixture->setActive("non existant script");
  195.         $this->assertTrue(PEAR::isError($result));
  196.         $this->logout();
  197.     }
  198.  
  199.     public function testRemoveScript()
  200.     {
  201.         $scriptname "test script1";
  202.         $this->login();
  203.         $result $this->fixture->installScript$scriptname$this->scripts[$scriptname]);
  204.         $result $this->fixture->removeScript($scriptname);
  205.         $this->assertTrue(!PEAR::isError($result),"Error removing active script");
  206.         $this->logout();
  207.     }
  208. }
  209. ?>

Documentation generated on Mon, 11 Mar 2019 15:17:56 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.