1<?php 2 3if (!defined('DW_LF')) { 4 define('DW_LF', "\n"); 5} 6 7/** 8 * Test the component plugin 9 * 10 * @group plugin_webcode 11 * @group plugins 12 */ 13class dokuwiki_plugin_webcode_basis_test extends DokuWikiTest 14{ 15 16 const PLUGIN_NAME = 'webcode'; 17 protected $pluginsEnabled = array(self::PLUGIN_NAME); 18 19 function setUp(){ 20 global $conf; 21 22 parent::setUp(); 23 24 // No login to not have the edit button in the output 25 $conf['useacl'] = 0; 26 } 27 28 29 30 /** 31 * With no code block, we should get noiframe 32 * even if there is webcode 33 */ 34 public function test_no_code_webcode() { 35 36 37 $content='Teaser content'; 38 $id = 'test:webcode:nowebcode'; 39 saveWikiText($id,'<'.self::PLUGIN_NAME.'>' 40 .DW_LF 41 .'==== Header ====' 42 .DW_LF 43 .$content 44 .DW_LF 45 .'</'.self::PLUGIN_NAME.'>','First'); 46 47 $testRequest = new TestRequest(); 48 $testResponse = $testRequest->get(array('id' => $id)); 49 print($testResponse->getContent()); 50 $iframe = $testResponse->queryHTML('iframe' ); 51 $this->assertEquals(0, $iframe->length); 52 53 } 54 55 /** 56 * With one code block we should get an iframe 57 */ 58 public function test_one_code_block_webcode() { 59 60 61 $content='Teaser content'; 62 $id = 'test:webcode:oncodeblock'; 63 saveWikiText($id,'<'.self::PLUGIN_NAME.'>' 64 .DW_LF 65 .'==== Header ====' 66 .DW_LF 67 .$content 68 .'<code><p>Hello World</p></code>' 69 .DW_LF 70 .'</'.self::PLUGIN_NAME.'>','First'); 71 72 $testRequest = new TestRequest(); 73 $testResponse = $testRequest->get(array('id' => $id)); 74 print($testResponse->getContent()); 75 $iframe = $testResponse->queryHTML('iframe' ); 76 $this->assertEquals(1, $iframe->length); 77 78 } 79 80 /** 81 * With two webcode, we should get two iframes 82 */ 83 public function test_two_webcode() { 84 85 $id = 'test:webcode:twowebcode'; 86 $webcode = '<' . self::PLUGIN_NAME . '>' 87 . DW_LF 88 . '==== Header ====' 89 . DW_LF 90 . '<code><p>Hello World</p></code>' 91 . DW_LF 92 . '</' . self::PLUGIN_NAME . '>'; 93 saveWikiText($id, $webcode.$webcode,'First'); 94 95 $testRequest = new TestRequest(); 96 $testResponse = $testRequest->get(array('id' => $id)); 97 $iframe = $testResponse->queryHTML('iframe' ); 98 $this->assertEquals(2, $iframe->length); 99 // code is render with a pre 100 $pre = $testResponse->queryHTML('pre' ); 101 $this->assertEquals(2, $iframe->length); 102 103 } 104 105 /** 106 * With a code block that should not been display 107 */ 108 public function test_no_display_webcode() { 109 110 111 $id = 'test:webcode:nodisplay'; 112 $webcode = '<' . self::PLUGIN_NAME . '>' 113 . DW_LF 114 . '==== Header ====' 115 . DW_LF 116 . '<code html [display="none"]><p>Hello World</p></code>' 117 . DW_LF 118 . '</' . self::PLUGIN_NAME . '>'; 119 saveWikiText($id, $webcode,'First'); 120 121 $testRequest = new TestRequest(); 122 $testResponse = $testRequest->get(array('id' => $id)); 123 // code is render with a pre 124 $iframe = $testResponse->queryHTML('pre' ); 125 $this->assertEquals(0, $iframe->length); 126 127 } 128 129 130 131} 132