[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/_test/tests/inc/ -> template_tpl_get_action.php (source)

   1  <?php
   2  
   3  class template_tpl_get_action_test extends DokuWikiTest {
   4  
   5      public function setUp() : void {
   6          parent::setUp();
   7          global $ID;
   8          $ID = 'start'; // run all tests on the start page
   9  
  10      }
  11  
  12      public function test_edit_edit() {
  13          global $ACT;
  14          global $INFO;
  15          global $REV;
  16  
  17          $ACT = 'show';
  18          $REV = '';
  19          $INFO['writable'] = true;
  20          $INFO['exists'] = true;
  21          $INFO['draft'] = '';
  22  
  23          $expect = array(
  24              'accesskey' => 'e',
  25              'type' => 'edit',
  26              'id' => 'start',
  27              'method' => 'post',
  28              'params' => array(
  29                  'do' => 'edit',
  30                  'rev' => '',
  31              ),
  32              'nofollow' => true,
  33              'replacement' => '',
  34          );
  35          $this->assertEquals($expect, tpl_get_action('edit'));
  36      }
  37  
  38      public function test_edit_edit_rev() {
  39          global $ACT;
  40          global $INFO;
  41          global $REV;
  42  
  43          $ACT = 'show';
  44          $REV = '1234';
  45          $INFO['writable'] = true;
  46          $INFO['exists'] = true;
  47          $INFO['draft'] = '';
  48  
  49          $expect = array(
  50              'accesskey' => 'e',
  51              'type' => 'edit',
  52              'id' => 'start',
  53              'method' => 'post',
  54              'params' => array(
  55                  'do' => 'edit',
  56                  'rev' => '1234',
  57              ),
  58              'nofollow' => true,
  59              'replacement' => '',
  60          );
  61          $this->assertEquals($expect, tpl_get_action('edit'));
  62      }
  63  
  64      public function test_edit_create() {
  65          global $ACT;
  66          global $INFO;
  67          global $REV;
  68  
  69          $ACT = 'show';
  70          $REV = '';
  71          $INFO['writable'] = true;
  72          $INFO['exists'] = false;
  73          $INFO['draft'] = '';
  74  
  75          $expect = array(
  76              'accesskey' => 'e',
  77              'type' => 'create',
  78              'id' => 'start',
  79              'method' => 'post',
  80              'params' => array(
  81                  'do' => 'edit',
  82                  'rev' => '',
  83              ),
  84              'nofollow' => true,
  85              'replacement' => '',
  86          );
  87          $this->assertEquals($expect, tpl_get_action('edit'));
  88      }
  89  
  90      public function test_edit_draft() {
  91          global $ACT;
  92          global $INFO;
  93          global $REV;
  94  
  95          $ACT = 'show';
  96          $REV = '';
  97          $INFO['writable'] = true;
  98          $INFO['exists'] = true;
  99          $INFO['draft'] = 'foobar';
 100  
 101          $expect = array(
 102              'accesskey' => 'e',
 103              'type' => 'draft',
 104              'id' => 'start',
 105              'method' => 'post',
 106              'params' => array(
 107                  'do' => 'draft',
 108              ),
 109              'nofollow' => true,
 110              'replacement' => '',
 111          );
 112          $this->assertEquals($expect, tpl_get_action('edit'));
 113      }
 114  
 115      public function test_edit_show() {
 116          global $ACT;
 117          global $INFO;
 118          global $REV;
 119  
 120          $ACT = 'edit';
 121          $REV = '';
 122          $INFO['writable'] = true;
 123          $INFO['exists'] = true;
 124          $INFO['draft'] = '';
 125  
 126          $expect = array(
 127              'accesskey' => 'v',
 128              'type' => 'show',
 129              'id' => 'start',
 130              'method' => 'get',
 131              'params' => array(
 132                  'do' => '',
 133              ),
 134              'nofollow' => true,
 135              'replacement' => '',
 136          );
 137          $this->assertEquals($expect, tpl_get_action('edit'));
 138      }
 139  
 140      public function test_revisions() {
 141          $expect = array(
 142              'accesskey' => 'o',
 143              'type' => 'revs',
 144              'id' => 'start',
 145              'method' => 'get',
 146              'params' => array(
 147                  'do' => 'revisions',
 148              ),
 149              'nofollow' => true,
 150              'replacement' => '',
 151          );
 152  
 153          $this->assertEquals($expect, tpl_get_action('history'));
 154          $this->assertEquals($expect, tpl_get_action('revisions'));
 155      }
 156  
 157      public function test_recent() {
 158          $expect = array(
 159              'accesskey' => 'r',
 160              'type' => 'recent',
 161              'id' => 'start',
 162              'method' => 'get',
 163              'params' => array(
 164                  'do' => 'recent',
 165              ),
 166              'nofollow' => true,
 167              'replacement' => '',
 168  
 169          );
 170          $this->assertEquals($expect, tpl_get_action('recent'));
 171      }
 172  
 173      public function test_login() {
 174          $expect = array(
 175              'accesskey' => null,
 176              'type' => 'login',
 177              'id' => 'start',
 178              'method' => 'get',
 179              'params' => array(
 180                  'do' => 'login',
 181                  'sectok' => '',
 182              ),
 183              'nofollow' => true,
 184              'replacement' => '',
 185          );
 186          $this->assertEquals($expect, tpl_get_action('login'));
 187  
 188          $_SERVER['REMOTE_USER'] = 'someone'; // logged in user
 189  
 190          $expect = array(
 191              'accesskey' => null,
 192              'type' => 'logout',
 193              'id' => 'start',
 194              'method' => 'get',
 195              'params' => array(
 196                  'do' => 'logout',
 197                  'sectok' => getSecurityToken(),
 198              ),
 199              'nofollow' => true,
 200              'replacement' => '',
 201          );
 202          $this->assertEquals($expect, tpl_get_action('login'));
 203      }
 204  
 205      public function test_profile() {
 206          $expect = false;
 207          $this->assertEquals($expect, tpl_get_action('profile'));
 208  
 209          $_SERVER['REMOTE_USER'] = 'someone'; // logged in user
 210  
 211          $expect = array(
 212              'accesskey' => null,
 213              'type' => 'profile',
 214              'id' => 'start',
 215              'method' => 'get',
 216              'params' => array(
 217                  'do' => 'profile',
 218              ),
 219              'nofollow' => true,
 220              'replacement' => '',
 221          );
 222          $this->assertEquals($expect, tpl_get_action('profile'));
 223      }
 224  
 225      public function test_index() {
 226          $expect = array(
 227              'accesskey' => 'x',
 228              'type' => 'index',
 229              'id' => 'start',
 230              'method' => 'get',
 231              'params' => array(
 232                  'do' => 'index',
 233              ),
 234              'nofollow' => false,
 235              'replacement' => '',
 236          );
 237          $this->assertEquals($expect, tpl_get_action('index'));
 238  
 239          global $ID;
 240          $ID = 'wiki:syntax';  // change to different page
 241  
 242          $expect = array(
 243              'accesskey' => 'x',
 244              'type' => 'index',
 245              'id' => 'wiki:syntax',
 246              'method' => 'get',
 247              'params' => array(
 248                  'do' => 'index',
 249              ),
 250              'nofollow' => true,
 251              'replacement' => '',
 252          );
 253          $this->assertEquals($expect, tpl_get_action('index'));
 254      }
 255  
 256      public function test_admin() {
 257          $expect = false;
 258          $this->assertEquals($expect, tpl_get_action('admin'));
 259  
 260          // logged in super user
 261          global $INFO;
 262          $_SERVER['REMOTE_USER'] = 'testuser';
 263          $INFO['ismanager'] = true;
 264  
 265          $expect = array(
 266              'accesskey' => null,
 267              'type' => 'admin',
 268              'id' => 'start',
 269              'method' => 'get',
 270              'params' => array(
 271                  'do' => 'admin',
 272              ),
 273              'nofollow' => true,
 274              'replacement' => '',
 275          );
 276          $this->assertEquals($expect, tpl_get_action('admin'));
 277      }
 278  
 279      public function test_top() {
 280          $expect = array(
 281              'accesskey' => 't',
 282              'type' => 'top',
 283              'id' => '#dokuwiki__top',
 284              'method' => 'get',
 285              'params' => array(
 286                  'do' => '',
 287              ),
 288              'nofollow' => true,
 289              'replacement' => '',
 290          );
 291          $this->assertEquals($expect, tpl_get_action('top'));
 292      }
 293  
 294      public function test_back() {
 295          $expect = false;
 296          $this->assertEquals($expect, tpl_get_action('back'));
 297  
 298          global $ID;
 299          $ID = 'wiki:syntax';
 300  
 301          $expect = array(
 302              'accesskey' => 'b',
 303              'type' => 'back',
 304              'id' => 'wiki:start',
 305              'method' => 'get',
 306              'params' => array(
 307                  'do' => '',
 308              ),
 309              'nofollow' => true,
 310              'replacement' => '',
 311          );
 312          $this->assertEquals($expect, tpl_get_action('back'));
 313      }
 314  
 315      public function test_backlink() {
 316          $expect = array(
 317              'accesskey' => null,
 318              'type' => 'backlink',
 319              'id' => 'start',
 320              'method' => 'get',
 321              'params' => array(
 322                  'do' => 'backlink',
 323              ),
 324              'nofollow' => true,
 325              'replacement' => '',
 326          );
 327          $this->assertEquals($expect, tpl_get_action('backlink'));
 328      }
 329  
 330      public function test_subscribe() {
 331          $expect = false;
 332          $this->assertEquals($expect, tpl_get_action('subscribe'));
 333          $this->assertEquals($expect, tpl_get_action('subscription'));
 334  
 335          $_SERVER['REMOTE_USER'] = 'someone'; // logged in user
 336  
 337          $expect = false;
 338          $this->assertEquals($expect, tpl_get_action('subscribe'));
 339          $this->assertEquals($expect, tpl_get_action('subscription'));
 340  
 341          // enable subscriptions
 342          global $conf;
 343          $conf['subscribers'] = true;
 344  
 345          $expect = array(
 346              'accesskey' => null,
 347              'type' => 'subscribe',
 348              'id' => 'start',
 349              'method' => 'get',
 350              'params' => array(
 351                  'do' => 'subscribe',
 352              ),
 353              'nofollow' => true,
 354              'replacement' => '',
 355          );
 356          $this->assertEquals($expect, tpl_get_action('subscribe'));
 357          $this->assertEquals($expect, tpl_get_action('subscription'));
 358      }
 359  
 360      public function test_register() {
 361          $expect = array(
 362              'accesskey' => null,
 363              'type' => 'register',
 364              'id' => 'start',
 365              'method' => 'get',
 366              'params' => array(
 367                  'do' => 'register',
 368              ),
 369              'nofollow' => true,
 370              'replacement' => '',
 371          );
 372          $this->assertEquals($expect, tpl_get_action('register'));
 373  
 374          $_SERVER['REMOTE_USER'] = 'somebody'; // logged in user
 375  
 376          $expect = false;
 377          $this->assertEquals($expect, tpl_get_action('register'));
 378      }
 379  
 380      public function test_resendpwd() {
 381          $expect = array(
 382              'accesskey' => null,
 383              'type' => 'resendpwd',
 384              'id' => 'start',
 385              'method' => 'get',
 386              'params' => array(
 387                  'do' => 'resendpwd',
 388              ),
 389              'nofollow' => true,
 390              'replacement' => '',
 391          );
 392          $this->assertEquals($expect, tpl_get_action('resendpwd'));
 393  
 394          $_SERVER['REMOTE_USER'] = 'somebody'; // logged in user
 395  
 396          $expect = false;
 397          $this->assertEquals($expect, tpl_get_action('resendpwd'));
 398      }
 399  
 400      public function test_revert() {
 401          $expect = false;
 402          $this->assertEquals($expect, tpl_get_action('revert'));
 403  
 404          global $REV;
 405          global $INFO;
 406          $REV = '1234';
 407          $INFO['writable'] = true;
 408          $INFO['ismanager'] = true;
 409  
 410          $expect = array(
 411              'accesskey' => null,
 412              'type' => 'revert',
 413              'id' => 'start',
 414              'method' => 'get', // FIXME should this be post?
 415              'params' => array(
 416                  'do' => 'revert',
 417                  'rev' => '1234',
 418                  'sectok' => '' // FIXME is this correct?
 419              ),
 420              'nofollow' => true,
 421              'replacement' => '',
 422          );
 423          $this->assertEquals($expect, tpl_get_action('revert'));
 424      }
 425  
 426      public function test_media() {
 427          global $ID;
 428          $ID = 'wiki:syntax';
 429  
 430          $expect = array(
 431              'accesskey' => null,
 432              'type' => 'media',
 433              'id' => 'wiki:syntax',
 434              'method' => 'get',
 435              'params' => array(
 436                  'do' => 'media',
 437                  'ns' => 'wiki'
 438              ),
 439              'nofollow' => true,
 440              'replacement' => '',
 441          );
 442          $this->assertEquals($expect, tpl_get_action('media'));
 443      }
 444  
 445      public function test_mediaManager() {
 446          global $IMG;
 447          $IMG = 'wiki:dokuwiki.png';
 448  
 449          $expect = array(
 450              'accesskey' => null,
 451              'type' => 'mediaManager',
 452              'id' => 'start',
 453              'method' => 'get',
 454              'params' => array(
 455                  'do' => 'media',
 456                  'ns' => 'wiki',
 457                  'image' => 'wiki:dokuwiki.png'
 458              ),
 459              'nofollow' => true,
 460              'replacement' => '',
 461          );
 462          $this->assertEquals($expect, tpl_get_action('mediaManager'));
 463      }
 464  
 465      public function test_img_backto() {
 466          $expect = array(
 467              'accesskey' => 'b',
 468              'type' => 'img_backto',
 469              'id' => 'start',
 470              'method' => 'get',
 471              'params' => array(),
 472              'nofollow' => true,
 473              'replacement' => 'start',
 474          );
 475          $this->assertEquals($expect, tpl_get_action('img_backto'));
 476      }
 477  
 478      public function test_unknown() {
 479          $expect = '[unknown %s type]';
 480          $this->assertEquals($expect, tpl_get_action('unknown'));
 481      }
 482  
 483  }