[geeklog-cvs] geeklog-2/lib/A_and_A/client/testscripts AAServiceInterfaceTest.class.php,NONE,1.1 AAUserTest.class.php,NONE,1.1 index.php,NONE,1.1 mockserver.php,NONE,1.1

tony at geeklog.net tony at geeklog.net
Sat Jan 11 01:07:07 EST 2003


Update of /usr/cvs/geeklog/geeklog-2/lib/A_and_A/client/testscripts
In directory internal.geeklog.net:/tmp/cvs-serv32627/client/testscripts

Added Files:
	AAServiceInterfaceTest.class.php AAUserTest.class.php 
	index.php mockserver.php 
Log Message:
Initial import into Geeklog


--- NEW FILE: AAServiceInterfaceTest.class.php ---
<?php


/**
* PEAR unit testing library
*/
require_once('PHPUnit.php');

/**
* A&A Service Interface
*/
require_once(dirname(__FILE__) . '/../AAServiceInterface.class.php');

/**
* This tests the AAService Interface
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.client.testscripts
*
*/
class AAServiceInterfaceTest extends PHPUnit_TestCase {
    /**
    * @access private
    */
    var $_aaServer = '';
    /**
    * @access private
    */
    var $_aaPort;
    /**
    * @access private
    */
    var $_appId = '';
    /**
    * @access private
    */
    var $_userId = '';
    /**
    * @access private
    */
    var $_password = '';

    /**
    * Constructor
    *
    * @param	string		$name	Name of class we are testing
    *
    */
    function AAServiceInterfaceTest($name)
    {
        $this->PHPUnit_TestCase($name);
    }

    /**
    * Prepares for tests
    *
    */
    function setUp()
    {
        $this->_aaServer = 'localhost';
        $this->_aaPort = 80;
        $this->_appId = 'A_AND_A';
        $this->_userId = 'root at localhost';
        $this->_password = 'foo';
    }

    /**
    * Handles post-test processing
    *
    */
    function tearDown()
    {
    }

    /**
    * Test script for AAServiceInterface::authenticate()
    *
    */
    function testAuthenticate()
    {
        $user = &AAServiceInterface::authenticate($this->_aaServer, $this->_appId, $this->_userId, $this->_password, $this->_aaPort);
        $this->assertEquals(get_class($user), 'aauser', 'Authenticate method failed');
        $this->assertNotNull($user->_privileges, 'Authenticate method failed to return any privileges for user');
        $this->assertNotNull($user->_groups, 'Authenticate method failed to return any groups for user');
        $this->assertEquals($this->_aaServer, $user->_aaServer,'aaServer descrepancy');
        $this->assertEquals($this->_aaPort, $user->_aaPort,'aaPort descrepancy');
        $this->assertEquals($this->_appId, $user->getAppId(),'appId descrepancy');
        $this->assertEquals($this->_userId, $user->getUserName(),'userName descrepancy');
        $this->assertEquals($this->_password, $user->getPassword(),'password descrepancy');
    }
    
}

?>
--- NEW FILE: AAUserTest.class.php ---
<?php

// PEAR packages
require_once('PHPUnit.php');

// A&A classes
require_once(dirname(__FILE__) . '/../AAUser.class.php');
require_once(dirname(__FILE__) . '/../../common/AAException.class.php');

/**
* Tests the AAUser object
*
* This class is a unit test for the AAUser object
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.client.testscripts
*
*/
class AAUserTest extends PHPUnit_TestCase {
    var $testUser;
    var $_aaServer = '';
    var $_aaPort;
    var $_appId = '';
    var $_userId = '';
    var $_userName = '';
    var $_password = '';

    /**
    * Constructor
    *
    * @access public
    * @param string $name Name of class we are testing
    *
    */
    function AAUserTest($name)
    {
        $this->PHPUnit_TestCase($name);
    }

    /**
    * Sets up the necessary variables for the tests
    *
    * Sets all the A&A Server parameters
    *
    */
    function setUp()
    {
        $this->testUser = new AAUser('localhost');
        $this->testUser->_aaPort = 80;
        $this->testUser->_appId = 'A_AND_A';
        $this->testUser->_userId = '1';
        $this->testUser->_userName = 'root at localhost';
        $this->testUser->_password = 'foo';
        $privilege = new AAPrivilege();
        $privilege->setPrivilegeCode('TEST.PRIVILEGE');
        $privilege->setPrivilegeDesc('Test Privilege');
        $this->testUser->_privileges = array();
        $this->testUser->_privileges[] = $privilege;
        $group = new AAGroup();
        $group->setGroupID(1);
        $group->setGroupDisplayName('Test Display Name');
        $group->setGroupLogicalName('TEST_LOGICAL_NAME');
        $group->getGroupDesc('This is a test group');
        $this->testUser->_groups = array();
        $this->testUser->_groups[] = $group;
    }

    function tearDown()
    {
    }

    function testAuthorize()
    {
        $retval = $this->testUser->authorize('TEST.PRIVILEGE');
        $this->assertTrue($retval,'User does not have access to TEST.PRIVILEGE privilege');
    }
    
    function testInGroup()
    {
        $retval = $this->testUser->inGroup('TEST_LOGICAL_NAME');
        $this->assertTrue($retval,'User is not in group TEST_LOGICAL_NAME');
    }

    /**
    * Test change password functionality
    *
    * @access public
    *
    */
    function testChangePassword()
    {
        $newPassword = 'foo2';
        $oldPassword = $this->testUser->_password;
        $retval = $this->testUser->changePassword($newPassword);
        $this->assertTrue($retval, 'Change Password method failed');
        $this->testUser->changePassword($oldPassword);
    }

    function testChangePasswordByAdmin()
    {
        $newPassword = time(); // This will make the password unique each time
        $retval = $this->testUser->changePasswordByAdmin('webmaster at localhost', $newPassword);
        // No good way to validate success now except by checking the return code
        $this->assertTrue($retval, 'changePasswordByAdmin method failed'); 
    }
    
    function testResetPassword()
    {
        $retval = $this->testUser->resetPassword('webmaster at localhost');

        $this->assertTrue($retval, 'Reset Password method failed');
    }

    function testGetUserPrivileges()
    {
        $privArray = $this->testUser->getUserPrivileges($this->testUser->_userName);
        $priv = current($privArray);
        $privCode = $priv->getPrivilegeCode();
        $this->assertEquals('AA_ADMIN_PRIV',$privCode);
    }
    
    function testListAppPrivileges()
    {
        $privArray = $this->testUser->listAppPrivileges();
        $priv = current($privArray);
        $privCode = $priv->getPrivilegeCode();
        $this->assertEquals('AA_ADMIN_PRIV',$privCode);
    }
/*
    function testListAppGroups()
    {
        $groupArray = $this->testUser->listAppGroups();
        $curGroup = current($groupArray);
        $this->assertEquals('AA_ADMIN',$curGroup->getGroupLogicalName());
    }
*/
#    function testSetUserPrivileges()
#    {
#        $origPrivArray = $this->testUser->_privileges;
#        $myPriv = new AAPrivilege();
#        $myPriv2 = new AAPrivilege();
#        $myPriv->_privilegeCode = 'test';
#        $myPriv->_privilegeDesc = 'Testing';
#        $myPriv2->_privilegeCode = 'test2';
#        $myPriv2->_privilegeDesc = 'Testing2';
#        $privArray = array($myPriv);
#        //$privArray = array();
#        $retval = $this->testUser->setUserPrivileges($this->testUser->_userId, $privArray);
#        $this->assertTrue($retval, 'setUserPrivileges method failed');
#        $this->testUser->setUserPrivileges($this->testUser->_userId, $origPrivArray);
#    }
}

?>
--- NEW FILE: index.php ---
<?php


/**
* PEAR's testing library
*/
require_once('PHPUnit.php');
/**
* A&A Service Interface Test Script 
*/
require_once('AAServiceInterfaceTest.class.php');
/**
* A&A User Test Script
*/
require_once('AAUserTest.class.php');

/**
* Runs all the test scripts for the A&A Client
*
* @access public
* @author Tony Bibbs <tony at tonybibbs.com>
* @package net.geeklog.enterprise.aa.client.testscripts
*
*/

// Test authenticate method only
$suite = new PHPUnit_TestSuite('AAServiceInterfaceTest');
$result = PHPUnit::run($suite);
echo nl2br($result->toString());

// Test all other user actions
$suite = new PHPUnit_TestSuite('AAUserTest');
$result = PHPUnit::run($suite);
echo nl2br($result->toString());

?>
--- NEW FILE: mockserver.php ---
<?php

$requestXML = $_POST['xmlInParam'];
$requestXML = stripslashes($_POST['xmlInParam']);

$xmlParser = xml_parser_create();
xml_parse_into_struct($xmlParser,$requestXML,$vals,$index) or trigger_error(xml_error_string(xml_get_error_code($xmlParser)));
xml_parser_free($xmlParser);
$XMLKeys = array_keys($index);
$cmdName = $vals[$index[$XMLKeys[1]][0]]['tag'];

switch (strtolower($cmdName)) {
    case 'authenticate':
        $responseXML = '<AAService><Result value="0" method="Authenticate" appId="MockServer"></Result><EmpId>1010</EmpId><PrivilegeList appId="MockServer"><Privilege code="TEST_PRIV">Test Privilege</Privilege></PrivilegeList></AAService>';
        break;
    case 'changepassword':
        $responseXML = '<AAService><Result value="0" method="ChangePassword" appId="MockServer"></Result></AAService>';
        break;
    case 'changepasswordbyadmin':
        $responseXML = '<AAService><Result value="0" method="ChangePasswordByAdmin" appId="MockServer"></Result></AAService>';
        break;
    case 'resetpassword':
        $responseXML = '<AAService><Result value="0" method="ResetPassword" appId="MockServer"></Result><NewPassword value="MyNewPass"></NewPassword></AAService>';
        break;
    case 'getuserprivileges':
        $responseXML = '<AAService><Result value="0" method="GetUserPrivileges" appId="MockServer"></Result><PrivilegeList appId="MockServer"><Privilege code="TEST_PRIV">Test Privilege</Privilege></PrivilegeList></AAService>';
        break;
    case 'setuserprivileges':
        $responseXML = '<AAService><Result value="0" method="SetUserPrivileges" appId="MockServer"></Result></AAService>';
        break;
    case 'listappprivileges':
        $responseXML = '<AAService><Result value="0" method="ListAppPrivileges" appId="MockServer"></Result><PrivilegeList appId="MockServer"><Privilege code="TEST_PRIV">Test Privilege</Privilege></PrivilegeList></AAService>';
        break;
    default:
        $responseXML = '<AAService><Result value="100" method="Unknown" appId="MockServer">Unknown Command: ' . $cmdName . '</Result></AAService>';
}

echo $responseXML;

?>




More information about the geeklog-cvs mailing list