[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/class/test/tests/dao/ -> permissions_test.class.php (source)

   1  <?php
   2  
   3      lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
   4      lt_include( PLOG_CLASS_PATH."class/dao/permission.class.php" );
   5      lt_include( PLOG_CLASS_PATH."class/dao/permissions.class.php" );
   6  
   7      /**

   8       * \ingroup Test

   9       *

  10       * Test cases for the Permissions class

  11       */
  12      class Permissions_Test extends LifeTypeTestCase
  13      {
  14  		function testAddPermission()
  15          {
  16              $perm = new Permission( "test_perm", "test_perm_desc" );
  17              $perm->setAdminOnlyPermission( false );
  18              $perm->setCorePermission( true );
  19              $perms = new Permissions();
  20              
  21              // check that it was correctly added

  22              $this->assertTrue( $perms->addPermission( $perm ), "Error adding new permission" );
  23              
  24              // check that the object got its id set correctly

  25              $this->assertTrue( ($perm->getId() != -1 ), "New permission still has id = -1" );
  26              
  27              // check that it can be loaded from the database

  28              $newPerm = $perms->getPermission( $perm->getId());
  29              $this->assertTrue( $newPerm, "Error loading the new category from the database" );
  30              
  31              // and that the object contains the same values

  32              $this->assertEquals( $perm->getName(), $newPerm->getName(), "new permission is not the same as original" );
  33              $this->assertEquals( $perm->getDescription(), $newPerm->getDescription(), "new permission is not the same as original" );
  34              $this->assertEquals( $perm->isAdminOnlyPermission(), $newPerm->isAdminOnlyPermission(), "new permission is not the same as original" );
  35              $this->assertEquals( $perm->isCorePermission(), $newPerm->isCorePermission(), "new permission is not the same as original" );
  36          }
  37          
  38  		function testGetPermission()
  39          {
  40              // first part of the test is the same as testAddPermission

  41              $this->testAddPermission();
  42              
  43              // while in the second half we test for errors

  44              $perms = new Permissions();
  45              $this->assertFalse( $perms->getPermission( 12312312311 ), "Permission should not have been found" );    
  46              $this->assertFalse( $perms->getPermission( "blah" ), "Permission should not have been found" );                
  47          }
  48          
  49  		function testGetPermissions()
  50          {
  51              // load all permissions and check at least that it's an array

  52              // :TODO: We could probably improve this test

  53              $perm = new Permission( "to_be_deleted", "this will be deleted" );
  54              $perms = new Permissions();
  55              
  56              // check that it was correctly added

  57              $this->assertTrue( $perms->addPermission( $perm ), "Error adding new permission" );
  58              
  59              // try to load all permissions, there should at least be one member in the array

  60              $allPerms = $perms->getAllPermissions();
  61              $this->assertTrue( (count($allPerms) > 0 ), "getAllPermissions did not return all permissions" );
  62              // make sure that the one we just got is one of them

  63              $found = false;
  64              $i = 0;
  65              while( !$found && $i < count($allPerms)) {
  66                  $found = ($allPerms[$i]->getId() == $perm->getId());
  67                  $i++;
  68              }
  69              $this->assertTrue( $found, "Could not locate new permission after calling getAllPermissions" );
  70              
  71              // we don't need it anymore, let's delete it

  72              $this->assertTrue( $perms->deletePermission( $perm->getId()), "There was an error deleting the permission" );            
  73          }
  74          
  75  		function testDeletePermission()
  76          {
  77              $perm = new Permission( "to_be_deleted", "this will be deleted" );
  78              $perms = new Permissions();
  79              
  80              // check that it was correctly added

  81              $this->assertTrue( $perms->addPermission( $perm ), "Error adding new permission" );            
  82              
  83              // now try to delete it

  84              $this->assertTrue( $perms->deletePermission( $perm->getId()), "There was an error deleting the permission" );
  85              
  86              // and finally check that it isn't there anymore

  87              $this->assertFalse( $perms->getPermission( $perm->getId(), "Deleted permission was still loaded again" ));    
  88          }
  89          
  90  		function testGetPermissionByName()
  91          {
  92              // test that a non-existant permission returns false

  93              $perms = new Permissions();
  94              $this->assertFalse( $perms->getPermissionByName( "afadsfasdfasfasdfasfs" ), "This permission should not exist" );    
  95              
  96              // add a test permission and see that it can be retrieved later on by name

  97              $perm = new Permission( "to_be_retrieved", "this will be deleted" );
  98              $perms = new Permissions();
  99              
 100              // check that it was correctly added

 101              $this->assertTrue( $perms->addPermission( $perm ), "Error adding new permission" );            
 102              
 103              // retrieve it by name

 104              $newPerm = $perms->getPermissionByName( "to_be_retrieved" );
 105              $this->assertTrue( $newPerm, "It was not possible to retrieve the permission by name" );
 106              
 107              // check that it is the same

 108              $this->assertEquals( $perm->getId(), $newPerm->getId(), "Permission retrieved by name did not match" );
 109              
 110              // and delete it

 111              $this->assertTrue( $perms->deletePermission( $perm->getId()), "There was an error deleting the permission" );            
 112          }
 113      }
 114  ?>


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics