[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

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

   1  <?php
   2  
   3  use dokuwiki\test\mock\AuthPlugin;
   4  
   5  class pageutils_findnearest_test extends DokuWikiTest {
   6  
   7      protected $oldAuthAcl;
   8  
   9      function setUp() {
  10          parent::setUp();
  11          global $AUTH_ACL;
  12          global $auth;
  13          global $conf;
  14          $conf['superuser'] = 'john';
  15          $conf['useacl']    = 1;
  16  
  17          $this->oldAuthAcl = $AUTH_ACL;
  18          $auth = new AuthPlugin();
  19  
  20          $AUTH_ACL = array(
  21              '*           @ALL           1',
  22              'internal:*    @ALL           0',
  23              'internal:*    max            1',
  24              '*           @user          8',
  25          );
  26      }
  27  
  28      function tearDown() {
  29          global $AUTH_ACL;
  30          $AUTH_ACL = $this->oldAuthAcl;
  31      }
  32  
  33      function testNoSidebar() {
  34          global $ID;
  35  
  36          $ID = 'foo:bar:baz:test';
  37          $sidebar = page_findnearest('sidebar');
  38          $this->assertEquals(false, $sidebar);
  39      }
  40  
  41      function testZeroID() {
  42          global $ID;
  43  
  44          saveWikiText('sidebar', 'topsidebar-test', '');
  45          saveWikiText('0', 'zero-test', '');
  46          saveWikiText('0:0:0', 'zero-test', '');
  47  
  48          $ID = '0:0:0';
  49          $sidebar = page_findnearest('sidebar');
  50          $this->assertEquals('sidebar', $sidebar);
  51  
  52          $sidebar = page_findnearest('0');
  53          $this->assertEquals('0:0:0', $sidebar);
  54  
  55          $ID = '0';
  56          $sidebar = page_findnearest('0');
  57          $this->assertEquals('0', $sidebar);
  58      }
  59  
  60      function testExistingSidebars() {
  61          global $ID;
  62  
  63          saveWikiText('sidebar', 'topsidebar-test', '');
  64  
  65          $ID = 'foo:bar:baz:test';
  66          $sidebar = page_findnearest('sidebar');
  67          $this->assertEquals('sidebar', $sidebar);
  68  
  69          $ID = 'foo';
  70          $sidebar = page_findnearest('sidebar');
  71          $this->assertEquals('sidebar', $sidebar);
  72  
  73          saveWikiText('foo:bar:sidebar', 'bottomsidebar-test', '');
  74  
  75          $ID = 'foo:bar:baz:test';
  76          $sidebar = page_findnearest('sidebar');
  77          $this->assertEquals('foo:bar:sidebar', $sidebar);
  78  
  79          $ID = 'foo:bar:test';
  80          $sidebar = page_findnearest('sidebar');
  81          $this->assertEquals('foo:bar:sidebar', $sidebar);
  82  
  83          $ID = 'foo';
  84          $sidebar = page_findnearest('sidebar');
  85          $this->assertEquals('sidebar', $sidebar);
  86      }
  87  
  88      function testACLWithSidebar() {
  89          global $ID;
  90          global $INPUT;
  91  
  92          $INPUT->server->set('REMOTE_USER', 'foo');
  93  
  94          saveWikiText('sidebar', 'top sidebar', '');
  95          saveWikiText('internal:sidebar', 'internal sidebar', '');
  96  
  97          $ID = 'internal:foo:bar';
  98  
  99          $sidebar = page_findnearest('sidebar');
 100          $this->assertEquals('sidebar', $sidebar);
 101  
 102          $sidebar = page_findnearest('sidebar', false);
 103          $this->assertEquals('internal:sidebar', $sidebar);
 104  
 105          $INPUT->server->set('REMOTE_USER', 'max');
 106  
 107          $sidebar = page_findnearest('sidebar');
 108          $this->assertEquals('internal:sidebar', $sidebar);
 109      }
 110  }