[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> auth_admincheck.test.php (source)

   1  <?php
   2  
   3  use dokuwiki\test\mock\AuthCaseInsensitivePlugin;
   4  use dokuwiki\test\mock\AuthPlugin;
   5  
   6  class auth_admin_test extends DokuWikiTest
   7  {
   8  
   9      private $oldauth;
  10  
  11      function setUp()
  12      {
  13          parent::setUp();
  14          global $auth;
  15          $this->oldauth = $auth;
  16      }
  17  
  18      function setSensitive()
  19      {
  20          global $auth;
  21          $auth = new AuthPlugin();
  22      }
  23  
  24      function setInSensitive()
  25      {
  26          global $auth;
  27          $auth = new AuthCaseInsensitivePlugin();
  28      }
  29  
  30      function teardown()
  31      {
  32          global $auth;
  33          global $AUTH_ACL;
  34          unset($AUTH_ACL);
  35          $auth = $this->oldauth;
  36      }
  37  
  38      function test_ismanager_insensitive()
  39      {
  40          $this->setInSensitive();
  41          global $conf;
  42          $conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte';
  43          $conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny';
  44  
  45          // anonymous user
  46          $this->assertFalse(auth_ismanager('jill', null, false, true));
  47  
  48          // admin or manager users
  49          $this->assertTrue(auth_ismanager('john', null, false, true));
  50          $this->assertTrue(auth_ismanager('doe', null, false, true));
  51  
  52          $this->assertTrue(auth_ismanager('dörte', null, false, true));
  53          $this->assertTrue(auth_ismanager('dänny', null, false, true));
  54  
  55          // admin or manager groups
  56          $this->assertTrue(auth_ismanager('jill', array('admin'), false, true));
  57          $this->assertTrue(auth_ismanager('jill', array('managers'), false, true));
  58  
  59          $this->assertTrue(auth_ismanager('jill', array('mötly görls'), false, true));
  60          $this->assertTrue(auth_ismanager('jill', array('mötly böys'), false, true));
  61      }
  62  
  63      function test_isadmin_insensitive()
  64      {
  65          $this->setInSensitive();
  66          global $conf;
  67          $conf['superuser'] = 'john,@admin,doe,@roots';
  68  
  69          // anonymous user
  70          $this->assertFalse(auth_ismanager('jill', null, true, true));
  71  
  72          // admin user
  73          $this->assertTrue(auth_ismanager('john', null, true, true));
  74          $this->assertTrue(auth_ismanager('doe', null, true, true));
  75  
  76          // admin groups
  77          $this->assertTrue(auth_ismanager('jill', array('admin'), true, true));
  78          $this->assertTrue(auth_ismanager('jill', array('roots'), true, true));
  79          $this->assertTrue(auth_ismanager('john', array('admin'), true, true));
  80          $this->assertTrue(auth_ismanager('doe', array('admin'), true, true));
  81      }
  82  
  83      function test_ismanager_sensitive()
  84      {
  85          $this->setSensitive();
  86          global $conf;
  87          $conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte';
  88          $conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny';
  89  
  90          // anonymous user
  91          $this->assertFalse(auth_ismanager('jill', null, false, true));
  92  
  93          // admin or manager users
  94          $this->assertTrue(auth_ismanager('john', null, false, true));
  95          $this->assertTrue(auth_ismanager('doe', null, false, true));
  96  
  97          $this->assertFalse(auth_ismanager('dörte', null, false, true));
  98          $this->assertFalse(auth_ismanager('dänny', null, false, true));
  99  
 100          // admin or manager groups
 101          $this->assertTrue(auth_ismanager('jill', array('admin'), false, true));
 102          $this->assertTrue(auth_ismanager('jill', array('managers'), false, true));
 103  
 104          $this->assertFalse(auth_ismanager('jill', array('mötly görls'), false, true));
 105          $this->assertFalse(auth_ismanager('jill', array('mötly böys'), false, true));
 106      }
 107  
 108      function test_isadmin_sensitive()
 109      {
 110          $this->setSensitive();
 111          global $conf;
 112          $conf['superuser'] = 'john,@admin,doe,@roots';
 113  
 114          // anonymous user
 115          $this->assertFalse(auth_ismanager('jill', null, true, true));
 116  
 117          // admin user
 118          $this->assertTrue(auth_ismanager('john', null, true, true));
 119          $this->assertFalse(auth_ismanager('Doe', null, true, true));
 120  
 121          // admin groups
 122          $this->assertTrue(auth_ismanager('jill', array('admin'), true, true));
 123          $this->assertTrue(auth_ismanager('jill', array('roots'), true, true));
 124          $this->assertTrue(auth_ismanager('john', array('admin'), true, true));
 125          $this->assertTrue(auth_ismanager('doe', array('admin'), true, true));
 126          $this->assertTrue(auth_ismanager('Doe', array('admin'), true, true));
 127      }
 128  
 129  }