1*1987d368SPhy<?php 2*1987d368SPhy/** 3*1987d368SPhy * Unit Test for inc/common.php - pageinfo() 4*1987d368SPhy * 5*1987d368SPhy * @author Christopher Smith <chris@jalakai.co.uk> 6*1987d368SPhy */ 7*1987d368SPhyclass parserutils_set_metadata_test extends DokuWikiTest { 8*1987d368SPhy // the id used for this test case 9*1987d368SPhy private $id; 10*1987d368SPhy 11*1987d368SPhy function helper_prepare_users($id = 1){ 12*1987d368SPhy global $INFO, $USERINFO; 13*1987d368SPhy $_SERVER['REMOTE_ADDR'] = '1.2.3.4'; 14*1987d368SPhy if($id == 2){ 15*1987d368SPhy $USERINFO = array( 16*1987d368SPhy 'pass' => '179ad45c6ce2cb97cf1029e212046e81', 17*1987d368SPhy 'name' => 'Tester2', 18*1987d368SPhy 'mail' => 'tester2@example.com', 19*1987d368SPhy 'grps' => array ('user'), 20*1987d368SPhy ); 21*1987d368SPhy $INFO['userinfo'] = $USERINFO; 22*1987d368SPhy $_SERVER['REMOTE_USER'] = 'tester2'; 23*1987d368SPhy }else{ 24*1987d368SPhy global $USERINFO, $INFO; 25*1987d368SPhy $USERINFO = array( 26*1987d368SPhy 'pass' => '179ad45c6ce2cb97cf1029e212046e81', 27*1987d368SPhy 'name' => 'Tester1', 28*1987d368SPhy 'mail' => 'tester1@example.com', 29*1987d368SPhy 'grps' => array ('admin','user'), 30*1987d368SPhy ); 31*1987d368SPhy $INFO['userinfo'] = $USERINFO; 32*1987d368SPhy $_SERVER['REMOTE_USER'] = '1'; 33*1987d368SPhy } 34*1987d368SPhy } 35*1987d368SPhy /** 36*1987d368SPhy * test array merge, including contributors with numeric keys and array data overwritting 37*1987d368SPhy */ 38*1987d368SPhy function test_array_replace(){ 39*1987d368SPhy // prepare user 40*1987d368SPhy $this->helper_prepare_users(1); 41*1987d368SPhy 42*1987d368SPhy // prepare page 43*1987d368SPhy $this->id = 'test:set_metadata_array_replace'; 44*1987d368SPhy saveWikiText($this->id, 'Test', 'Test data setup'); 45*1987d368SPhy $meta = p_get_metadata($this->id); 46*1987d368SPhy 47*1987d368SPhy $this->assertEquals('1', $meta['user'], 'Initial page has wrong user ID'); 48*1987d368SPhy // $this->assertEquals(empty($meta['contributor']), true, 'Initial page should have no contributors'); 49*1987d368SPhy 50*1987d368SPhy // first revision with numeric user 51*1987d368SPhy saveWikiText($this->id, 'Test1', 'Test first edit'); 52*1987d368SPhy $meta = p_get_metadata($this->id); 53*1987d368SPhy 54*1987d368SPhy $last_edit_date = $meta['date']['modified']; 55*1987d368SPhy $this->assertEquals(array('1'=>'Tester1'), $meta['contributor'], 'First edit contributors error'); 56*1987d368SPhy 57*1987d368SPhy // second revision with alphabetic user 58*1987d368SPhy sleep(1); // To generate a different timestamp 59*1987d368SPhy $this->helper_prepare_users(2); 60*1987d368SPhy saveWikiText($this->id, 'Test2', 'Test second edit'); 61*1987d368SPhy $meta = p_get_metadata($this->id); 62*1987d368SPhy 63*1987d368SPhy $this->assertNotEquals($last_edit_date, $meta['date']['modified'], 'First edit date merge error'); 64*1987d368SPhy $this->assertEquals(array('tester2'=>'Tester2', '1'=>'Tester1'), $meta['contributor'], 'Second edit contributors error'); 65*1987d368SPhy 66*1987d368SPhy // third revision with the first user 67*1987d368SPhy $this->helper_prepare_users(1); 68*1987d368SPhy saveWikiText($this->id, 'Test3', 'Test third edit'); 69*1987d368SPhy $meta = p_get_metadata($this->id); 70*1987d368SPhy 71*1987d368SPhy $this->assertEquals(array('tester2'=>'Tester2', '1'=>'Tester1'), $meta['contributor'], 'Third edit contributors error'); 72*1987d368SPhy } 73*1987d368SPhy} 74*1987d368SPhy 75*1987d368SPhy//Setup VIM: ex: et ts=4 : 76