1<?php 2 3/** 4 * @group integration 5 */ 6class EditAndSaveTest extends DokuWikiTest { 7 8 /** 9 * Execute the following requests: 10 * - Section edit a page (headline 2, first occurrence) 11 * - Save a page 12 * - Redirect 13 * Check if the header id is transmitted and if the final redirect 14 * points to the correct header. 15 */ 16 function testEditSaveRedirect_Headline2_A() { 17 $request = new TestRequest(); 18 19 $input = array( 20 'id' => 'wiki:editandsavetest' 21 ); 22 23 // Show page 24 $response = $request->post($input); 25 $content = $response->getContent(); 26 $this->assertTrue(!empty($content)); 27 28 // If the test page has got the right content for our test it should have 29 // two headlines with the title "Headline2" 30 preg_match_all('#<h1[^>]*>Headline2</h1[^>]*>#', $content, $matches, PREG_SET_ORDER); 31 $this->assertEquals(2, count($matches)); 32 33 // Get the header ids 34 $result = preg_match('/id="(.*)"/', $matches [0][0], $idA); 35 $this->assertEquals(1, $result); 36 $result = preg_match('/id="(.*)"/', $matches [1][0], $idB); 37 $this->assertEquals(1, $result); 38 $this->assertTrue($idA != $idB); 39 40 // Search the section edit form/button for the second id 41 $pattern = '/<form class="button btn_secedit".*>.*'; 42 $pattern .= '<input type="hidden" name="hid" value="'; 43 $pattern .= $idA[1]; 44 $pattern .= '" \/>.*<\/form>/'; 45 $result = preg_match($pattern, $content, $formA); 46 $this->assertEquals(1, $result); 47 48 // Extract all inputs from the form 49 $result = preg_match_all('/<input type="hidden" name="([^"]*)" value="([^"]*)" \/>/', $formA[0], $matches, PREG_SET_ORDER); 50 $input = array(); 51 foreach ($matches as $match) { 52 $input[$match[1]] = $match[2]; 53 } 54 $this->assertEquals($input['hid'], $idA[1]); 55 56 // Post the input fields (= do a section edit) 57 $response = $request->post($input, '/doku.php'); 58 $content = $response->getContent(); 59 60 // Our header id should have been sent back to us in the edit 61 // form as an hidden input field 62 $content = str_replace("\n", " ", $content); 63 $pattern = '/<form id="dw__editform"[^>]*>.*'; 64 $pattern .= '<input type="hidden" name="hid" value="'; 65 $pattern .= $idA[1]; 66 $pattern .= '" \/>.*<\/form>/'; 67 $result = preg_match($pattern, $content, $editForm); 68 $this->assertEquals(1, $result); 69 70 // Extract all inputs from the edit form 71 $result = preg_match_all('/<input type="hidden" name="([^"]*)" value="([^"]*)" \/>/', $editForm[0], $matches, PREG_SET_ORDER); 72 $input = array(); 73 foreach ($matches as $match) { 74 $input[$match[1]] = $match[2]; 75 } 76 $this->assertEquals($input['hid'], $idA[1]); 77 $input['do'] = 'save'; 78 79 // Post the input fields (= save page) 80 $response = $request->post($input, '/doku.php'); 81 82 // The response should carry a notification that a redirect 83 // was executed to our header ID 84 $found = null; 85 $notifications = $response->getNotifications(); 86 foreach ($notifications as $notification) { 87 if ($notification['name'] == 'send_redirect') { 88 $found = &$notification; 89 } 90 } 91 $this->assertTrue($found !== null); 92 $hash = strpos($found['url'], '#'); 93 $headerID = substr($found['url'], $hash); 94 $this->assertEquals($headerID, '#'.$idA[1]); 95 } 96 97 /** 98 * Execute the following requests: 99 * - Section edit a page (headline 2, second occurrence) 100 * - Save a page 101 * - Redirect 102 * Check if the header id is transmitted and if the final redirect 103 * points to the correct header. 104 */ 105 function testEditSaveRedirect_Headline2_B() { 106 $request = new TestRequest(); 107 108 $input = array( 109 'id' => 'wiki:editandsavetest' 110 ); 111 112 // Show page 113 $response = $request->post($input); 114 $content = $response->getContent(); 115 $this->assertTrue(!empty($content)); 116 117 // If the test page has got the right content for our test it should have 118 // two headlines with the title "Headline2" 119 preg_match_all('#<h1[^>]*>Headline2</h1[^>]*>#', $content, $matches, PREG_SET_ORDER); 120 $this->assertEquals(2, count($matches)); 121 122 // Get the header ids 123 $result = preg_match('/id="(.*)"/', $matches [0][0], $idA); 124 $this->assertEquals(1, $result); 125 $result = preg_match('/id="(.*)"/', $matches [1][0], $idB); 126 $this->assertEquals(1, $result); 127 $this->assertTrue($idA != $idB); 128 129 // Search the section edit form/button for the second id 130 $pattern = '/<form class="button btn_secedit".*>.*'; 131 $pattern .= '<input type="hidden" name="hid" value="'; 132 $pattern .= $idB[1]; 133 $pattern .= '" \/>.*<\/form>/'; 134 $result = preg_match($pattern, $content, $formB); 135 $this->assertEquals(1, $result); 136 137 // Extract all inputs from the form 138 $result = preg_match_all('/<input type="hidden" name="([^"]*)" value="([^"]*)" \/>/', $formB[0], $matches, PREG_SET_ORDER); 139 $input = array(); 140 foreach ($matches as $match) { 141 $input[$match[1]] = $match[2]; 142 } 143 $this->assertEquals($input['hid'], $idB[1]); 144 145 // Post the input fields (= do a section edit) 146 $response = $request->post($input, '/doku.php'); 147 $content = $response->getContent(); 148 149 // Our header id should have been sent back to us in the edit 150 // form as an hidden input field 151 $content = str_replace("\n", " ", $content); 152 $pattern = '/<form id="dw__editform"[^>]*>.*'; 153 $pattern .= '<input type="hidden" name="hid" value="'; 154 $pattern .= $idB[1]; 155 $pattern .= '" \/>.*<\/form>/'; 156 $result = preg_match($pattern, $content, $editForm); 157 $this->assertEquals(1, $result); 158 159 // Extract all inputs from the edit form 160 $result = preg_match_all('/<input type="hidden" name="([^"]*)" value="([^"]*)" \/>/', $editForm[0], $matches, PREG_SET_ORDER); 161 $input = array(); 162 foreach ($matches as $match) { 163 $input[$match[1]] = $match[2]; 164 } 165 $this->assertEquals($input['hid'], $idB[1]); 166 $input['do'] = 'save'; 167 168 // Post the input fields (= save page) 169 $response = $request->post($input, '/doku.php'); 170 171 // The response should carry a notification that a redirect 172 // was executed to our header ID 173 $found = null; 174 $notifications = $response->getNotifications(); 175 foreach ($notifications as $notification) { 176 if ($notification['name'] == 'send_redirect') { 177 $found = &$notification; 178 } 179 } 180 $this->assertTrue($found !== null); 181 $hash = strpos($found['url'], '#'); 182 $headerID = substr($found['url'], $hash); 183 $this->assertEquals($headerID, '#'.$idB[1]); 184 } 185} 186