[pLog-svn] r4096 - in plog/trunk/class/test: helpers tests/ui
oscar at devel.lifetype.net
oscar at devel.lifetype.net
Fri Oct 6 10:23:48 GMT 2006
Author: oscar
Date: 2006-10-06 10:23:48 +0000 (Fri, 06 Oct 2006)
New Revision: 4096
Added:
plog/trunk/class/test/tests/ui/permissionsui_test.class.php
Modified:
plog/trunk/class/test/helpers/testtools.class.php
Log:
added a UI test case for permissions
Modified: plog/trunk/class/test/helpers/testtools.class.php
===================================================================
--- plog/trunk/class/test/helpers/testtools.class.php 2006-10-06 09:28:14 UTC (rev 4095)
+++ plog/trunk/class/test/helpers/testtools.class.php 2006-10-06 10:23:48 UTC (rev 4096)
@@ -61,6 +61,29 @@
}
/**
+ * Creates a temporary admin user
+ *
+ * @return A UserInfo object if successful or false otherwise
+ */
+ function createAdminUser()
+ {
+ $user = new UserInfo(
+ TestTools::getRandomWord( 15 ),
+ "password",
+ "test at user.com",
+ "About test user",
+ "Test User"
+ );
+ $user->setSiteAdmin( true );
+
+ $users = new Users();
+ if( $users->addUser( $user ))
+ return( $user );
+ else
+ return( false );
+ }
+
+ /**
* Create a temporary article
*
* @param blogId Id of the blog to which this article belongs
Added: plog/trunk/class/test/tests/ui/permissionsui_test.class.php
===================================================================
--- plog/trunk/class/test/tests/ui/permissionsui_test.class.php 2006-10-06 09:28:14 UTC (rev 4095)
+++ plog/trunk/class/test/tests/ui/permissionsui_test.class.php 2006-10-06 10:23:48 UTC (rev 4096)
@@ -0,0 +1,188 @@
+<?php
+
+ include_once( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+ include_once( PLOG_CLASS_PATH."class/test/helpers/testtools.class.php" );
+ include_once( PLOG_CLASS_PATH."class/dao/permissions.class.php" );
+
+ /**
+ * \ingroup Test
+ */
+ class PermissionsUI_Test extends LifeTypeTestCase
+ {
+ var $user;
+ var $blog;
+
+ function setUp()
+ {
+ $this->user = TestTools::createAdminUser();
+ $this->blog = TestTools::createBlog( $this->user->getId());
+ }
+
+ function tearDown()
+ {
+ TestTools::deleteDaoTestData( Array( $this->user, $this->blog ));
+ }
+
+ /**
+ * Test that core permissions cannot be deleted via the user interface
+ */
+ function testCorePermissions()
+ {
+ $permName = "perm_".TestTools::getRandomWord( 20 );
+
+ // login
+ $this->assertUIScript(
+ Array(
+ "login" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "post",
+ "params" => Array(
+ "userName" => $this->user->getUserName(),
+ "userPassword" => "password",
+ "op" => "Login"
+ ),
+ "expected" => "Dashboard",
+ "message" => "The dashboard did not appear when logging in"
+ ),
+ "select_blog" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array(
+ "op" => "blogSelect",
+ "blogId" => $this->blog->getId()
+ ),
+ "expected" => "New Post",
+ "message" => "The blog could not be selected after the dashboard"
+ )
+ )
+ );
+
+ // go the "new permission" page and add a new one
+ $this->assertUIScript(
+ Array(
+ "new_permission" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array( "op" => "newPermission" ),
+ "expected" => "Unique name for the new permission",
+ "message" => "The form to input a new permission was not successfully displayed"
+ ),
+ "create_permission" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "post",
+ "params" => Array( "permissionName" => $permName, "permissionDescription" => "$permName description", "corePermission" => "1", "op" => "addPermission" ),
+ "expected" => "Permission added",
+ "message" => "The test permission was not successully added"
+ )
+ )
+ );
+
+ // find the category in the db...
+ $perms = new Permissions();
+ $perm = $perms->getPermissionByName( $permName );
+
+ if( !$perm ) {
+ die("FATAL: The permission was not successfully added and the test cannot continue" );
+ }
+
+ // ...and delete it via the UI
+ $this->assertUIScript(
+ Array(
+ "delete_permission" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array( "permId" => $perm->getId(), "op" => "deletePermission" ),
+ "expected" => "Permission \"".$perm->getName()."\" cannot be deleted",
+ "message" => "The user interface allowed to delete a core permission!"
+ )
+ )
+ );
+
+ // delete the permission via the API
+ $perms->deletePermission( $perm->getId());
+ }
+
+ /**
+ * Test permissions
+ */
+ function testPermissions()
+ {
+ $permName = "perm_".TestTools::getRandomWord( 20 );
+
+ // login
+ $this->assertUIScript(
+ Array(
+ "login" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "post",
+ "params" => Array(
+ "userName" => $this->user->getUserName(),
+ "userPassword" => "password",
+ "op" => "Login"
+ ),
+ "expected" => "Dashboard",
+ "message" => "The dashboard did not appear when logging in"
+ ),
+ "select_blog" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array(
+ "op" => "blogSelect",
+ "blogId" => $this->blog->getId()
+ ),
+ "expected" => "New Post",
+ "message" => "The blog could not be selected after the dashboard"
+ )
+ )
+ );
+
+ // go the "new permission" page and add a new one
+ $this->assertUIScript(
+ Array(
+ "new_permission" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array( "op" => "newPermission" ),
+ "expected" => "Unique name for the new permission",
+ "message" => "The form to input a new permission was not successfully displayed"
+ ),
+ "create_permission" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "post",
+ "params" => Array( "permissionName" => $permName, "permissionDescription" => "$permName description", "adminOnlyPermission" => "1", "op" => "addPermission" ),
+ "expected" => "Permission added",
+ "message" => "The test permission was not successully added"
+ )
+ )
+ );
+
+ // find the category in the db...
+ $perms = new Permissions();
+ $perm = $perms->getPermissionByName( $permName );
+
+ if( !$perm ) {
+ die("FATAL: The permission was not successfully added and the test cannot continue" );
+ }
+
+ // ...and delete it via the UI
+ $this->assertUIScript(
+ Array(
+ "delete_permission" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array( "permId" => $perm->getId(), "op" => "deletePermission" ),
+ "expected" => "Permission \"".$perm->getName()."\" was deleted",
+ "message" => "The permission was not deleted!"
+ ),
+ "delete_permission_again" => Array(
+ "url" => $this->getAdminUrl(),
+ "type" => "get",
+ "params" => Array( "permId" => $perm->getId(), "op" => "deletePermission" ),
+ "expected" => "There was an error deleting permission",
+ "message" => "The user interface allowed to delete the test permission twice"
+ )
+ )
+ );
+ }
+ }
+?>
\ No newline at end of file
More information about the pLog-svn
mailing list