From 3be13f059d556ebc65089fd3a84c74a3affefc89 Mon Sep 17 00:00:00 2001 From: David Goodwin Date: Thu, 17 Mar 2011 22:38:03 +0000 Subject: [PATCH] this will probably migrate us to phpunit; stupid dev env is misbehaving though so it is hard to test git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1017 a1433add-5e2c-0410-b055-b7f2511e0802 --- tests/RemoteTest.php | 70 ++++++++------------------------------------ tests/run.php | 19 ------------ 2 files changed, 12 insertions(+), 77 deletions(-) delete mode 100644 tests/run.php diff --git a/tests/RemoteTest.php b/tests/RemoteTest.php index d88bbb1a..5d41372a 100644 --- a/tests/RemoteTest.php +++ b/tests/RemoteTest.php @@ -2,14 +2,15 @@ require_once('common.php'); -require_once('simpletest/unit_tester.php'); +require_once('PHPUnit/Autoload.php'); + require_once('Zend/XmlRpc/Client.php'); require_once('Zend/Http/Client.php'); require_once('Zend/Registry.php'); -class RemoteTest extends UnitTestCase { +abstract class RemoteTest extends PHPUnit_Framework_TestCase { - protected $server_url = 'http://orange/david/postfixadmin/trunk/xmlrpc.php'; + protected $server_url = 'http://orange/david/postfixadmin/xmlrpc.php'; protected $username = 'roger@example.com'; protected $password = 'patchthedog'; @@ -18,65 +19,18 @@ class RemoteTest extends UnitTestCase { protected $vacation; protected $alias; - public function __construct() { - parent::__construct(); - - } - public function setUp() { parent::setUp(); + $this->xmlrpc_client = new Zend_XmlRpc_Client($this->server_url); + $http_client = $this->xmlrpc_client->getHttpClient(); + $http_client->setCookieJar(); - // ensure a user exists as per the above... - - $table_vacation = table_by_key('vacation'); - $table_alias = table_by_key('alias'); - $table_mailbox = table_by_key('mailbox'); - $table_domain = table_by_key('domain'); - $username = escape_string($this->username); - $password = escape_string(pacrypt($this->password)); - - db_query("DELETE FROM $table_vacation WHERE email = '$username'"); - db_query("DELETE FROM $table_alias WHERE domain = 'example.com'"); - db_query("DELETE FROM $table_mailbox WHERE domain = 'example.com'"); - db_query("DELETE FROM $table_domain WHERE domain = 'example.com'"); + $login_object = $this->xmlrpc_client->getProxy('login'); + $success = $login_object->login($this->username, $this->password); - // create new db records.. - $result = db_query("INSERT INTO $table_domain (domain, aliases, mailboxes) VALUES ('example.com', 100, 100)"); - if($result['rows'] != 1) { - die("Failed to add domain to db...."); - } - - $result = db_query("INSERT INTO $table_mailbox (username, password, name, local_part, domain) VALUES ('$username', '$password', 'test user', 'roger', 'example.com')"); - if($result['rows'] != 1) { - die("Failed to add user to db...."); - } - - $result = db_query("INSERT INTO $table_alias (address, goto, domain) VALUES ('$username', '$username', 'example.com')"); - if($result['rows'] != 1) { - die("Failed to add alias to db...."); - } - - try { - $this->xmlrpc_client = new Zend_XmlRpc_Client($this->server_url); - $http_client = $this->xmlrpc_client->getHttpClient(); - $http_client->setCookieJar(); - - $login_object = $this->xmlrpc_client->getProxy('login'); - $success = $login_object->login($this->username, $this->password); - - if(!$success) { - var_dump($success); - die("Failed to login to xmlrpc interface"); - } - - $this->user = $this->xmlrpc_client->getProxy('user'); - $this->alias = $this->xmlrpc_client->getProxy('alias'); - $this->vacation = $this->xmlrpc_client->getProxy('vacation'); - } - catch(Exception $e) { - var_dump($e); - var_dump($this->xmlrpc_client->getHttpClient()->getLastResponse()->getBody()); - die("Error setting up.."); + if(!$success) { + var_dump($success); + die("Failed to login to xmlrpc interface"); } } } diff --git a/tests/run.php b/tests/run.php deleted file mode 100644 index 1f88b7aa..00000000 --- a/tests/run.php +++ /dev/null @@ -1,19 +0,0 @@ -addTestFile('./RemoteVacationTest.php'); -$test->addTestFile('./RemoteUserTest.php'); -$test->addTestFile('./RemoteAliasTest.php'); - -exit($test->run(new TextReporter()) ? 0 : 1); - -/* vim: set expandtab softtabstop=4 tabstop=4 shiftwidth=4: */