Skip to content

Commit

Permalink
fixed unittest and transformed to phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
dom-mel committed Apr 7, 2012
1 parent 7d2189b commit d6b3716
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 3 deletions.
4 changes: 1 addition & 3 deletions _test/cases/inc/pageutils_resolve_pageid.test.php
Expand Up @@ -48,7 +48,6 @@ function test1(){
$tests[] = array('foo','.:','foo:start');
$tests[] = array('','foo:','foo:start');
$tests[] = array('foo','foo:','foo:start');
$tests[] = array('foo','playground:','playground:playground');

// empty $page
global $ID;
Expand All @@ -69,15 +68,14 @@ function test1(){
function test_resolve_pageid_empty_homepage() {
global $ID;
$ID = '';

global $conf;
$conf['start'] = 'someverystrangestartname';

$ns = '';
$page = '';
$exist = true;

resolve_pageid($ns, $page, $exist);
@resolve_pageid($ns, $page, $exist);
$this->assertEqual($page, $conf['start']);
}

Expand Down
83 changes: 83 additions & 0 deletions _testing/unittests/inc/pageutils_resolve_pageid.test.php
@@ -0,0 +1,83 @@
<?php
require_once DOKU_INC.'inc/utf8.php';
require_once DOKU_INC.'inc/pageutils.php';

global $conf;
if (!isset($conf['datadir'])) $conf['datadir'] = $conf['savedir'].'/pages';

class init_resolve_pageid_test extends PHPUnit_Framework_TestCase {


function test1(){
global $conf;

// we test multiple cases here
// format: $ns, $page, $output
$tests = array();

// relative current in root
$tests[] = array('','page','page');
$tests[] = array('','.page','page');
$tests[] = array('','.:page','page');

// relative current in namespace
$tests[] = array('lev1:lev2','page','lev1:lev2:page');
$tests[] = array('lev1:lev2','.page','lev1:lev2:page');
$tests[] = array('lev1:lev2','.:page','lev1:lev2:page');

// relative upper in root
$tests[] = array('','..page','page');
$tests[] = array('','..:page','page');

// relative upper in namespace
$tests[] = array('lev1:lev2','..page','lev1:page');
$tests[] = array('lev1:lev2','..:page','lev1:page');
$tests[] = array('lev1:lev2','..:..:page','page');
$tests[] = array('lev1:lev2','..:..:..:page','page');

// strange and broken ones
$tests[] = array('lev1:lev2','....:....:page','lev1:lev2:page');
$tests[] = array('lev1:lev2','..:..:lev3:page','lev3:page');
$tests[] = array('lev1:lev2','..:..:lev3:..:page','page');
$tests[] = array('lev1:lev2','..:..:lev3:..:page:....:...','page');

// now some tests with existing and none existing files
$conf['start'] = 'start';

$tests[] = array('','.:','start');
$tests[] = array('foo','.:','foo:start');
$tests[] = array('','foo:','foo:start');
$tests[] = array('foo','foo:','foo:start');

// empty $page
global $ID;
$ID = 'my:space';
$tests[] = array('my', '', 'my:space');

foreach($tests as $test){
$page = $test[1];
resolve_pageid($test[0],$page,$foo);

$this->assertEquals($page,$test[2]);
}
}

/**
* Empty page on homepage should resolve to start page
*/
function test_resolve_pageid_empty_homepage() {
global $ID;
$ID = '';
global $conf;
$conf['start'] = 'someverystrangestartname';

$ns = '';
$page = '';
$exist = true;

resolve_pageid($ns, $page, $exist);
$this->assertEquals($page, $conf['start']);
}

}
//Setup VIM: ex: et ts=4 :

0 comments on commit d6b3716

Please sign in to comment.