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