Completed
Pull Request — master (#21)
by Mark
01:38
created

syntax_plugin_yalist_test::testExample()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 129

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 129
rs 8
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * Copyright (c) 2016 Mark C. Prins <[email protected]>
4
 *
5
 * Permission to use, copy, modify, and distribute this software for any
6
 * purpose with or without fee is hereby granted, provided that the above
7
 * copyright notice and this permission notice appear in all copies.
8
 *
9
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16
 */
17
/**
18
 * Syntax tests for the yalist plugin.
19
 *
20
 * @group plugin_yalist
21
 * @group plugins
22
 */
23
class syntax_plugin_yalist_test extends DokuWikiTest {
24
    protected $pluginsEnabled = array('yalist');
25
26
/**
27
 * copy data and add pages to the index.
28
 */
29
    public static function setUpBeforeClass(): void {
30
        parent::setUpBeforeClass();
31
        global $conf;
32
        $conf['allowdebug'] = 1;
33
        TestUtils::rcopy(TMP_DIR, dirname(__FILE__) . '/data/');
34
        dbglog("\nset up class syntax_plugin_yalist_test");
35
    }
36
    function setUp(): void {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
37
        parent::setUp();
38
        global $conf;
39
        $conf['allowdebug'] = 1;
40
        $conf['cachetime'] = -1;
41
        $data = array();
42
        search($data, $conf['datadir'], 'search_allpages', array('skipacl' => true));
43
        $verbose = false;
44
        $force = false;
45
        foreach ($data as $val) {
46
            idx_addPage($val['id'], $verbose, $force);
47
        }
48
        if ($conf['allowdebug']) {
49
            touch(DOKU_TMP_DATA . 'cache/debug.log');
50
        }
51
    }
52
    public function tearDown(): void {
53
        parent::tearDown();
54
        global $conf;
55
        // try to get the debug log after running the test, print and clear
56
        if ($conf['allowdebug']) {
57
            print "\n";
58
            readfile(DOKU_TMP_DATA . 'cache/debug.log');
59
            unlink(DOKU_TMP_DATA . 'cache/debug.log');
60
        }
61
    }
62
63
    public function testExample(): void {
64
        $request = new TestRequest();
65
        $response = $request->get(array('id'=>'example'), '/doku.php');
66
67
        print_r($response);
68
//file_get_contents("example.html");
69
70
//$handle=fopen('/tmp/data.html', 'w');
71
//fwrite($handle, $response->getContent());
72
//close($handle);
73
74
//print_r($response);\
75
        $this->assertTrue(strpos($response->getContent(),
76
'<h1 class="sectionedit1" id="yalist_example">yalist example</h1>
77
 <div class="level1">
78
 <ol>
79
 <li class="level1"><div class="li">
80
  Ordered list item 1
81
 </div></li>
82
 <li class="level1"><div class="li">
83
  Ordered list item 2
84
 </div></li>
85
 <li class="level1"><div class="li">
86
 <p>
87
  Ordered list item 3…
88
 </p><p>
89
  … in multiple paragraphs
90
 </p>
91
 </div></li>
92
 <li class="level1"><div class="li">
93
  Ordered list item 4
94
 </div></li>
95
 </ol>
96
97
 <ul>
98
 <li class="level1"><div class="li">
99
  Unordered list item
100
 </div></li>
101
 <li class="level1"><div class="li">
102
 <p>
103
  Unordered list item…
104
 </p><p>
105
  … in multiple paragraphs
106
 </p>
107
 </div></li>
108
 </ul>
109
110
 <ol>
111
 <li class="level1"><div class="li">
112
  Ordered list, first level
113
 </div><ol>
114
 <li class="level2"><div class="li">
115
  Second level
116
 </div><ol>
117
 <li class="level3"><div class="li">
118
  Third level
119
 </div><ol>
120
 <li class="level4"><div class="li">
121
  Fourth level
122
 </div></li>
123
 </ol>
124
 </li>
125
 </ol>
126
 </li>
127
 <li class="level2"><div class="li">
128
 <p>
129
  Back to second level
130
 </p>
131
 </div><ol>
132
 <li class="level3"><div class="li">
133
  <em>Second?! What happened to third?</em>
134
 </div></li>
135
 </ol>
136
 <div class="li">
137
 <p>
138
  <em>Quiet, you.</em>
139
 </p>
140
 </div></li>
141
 </ol>
142
 </li>
143
 <li class="level1"><div class="li">
144
  Back to first level
145
 </div></li>
146
 <li class="level1"><div class="li">
147
  Still at first level
148
 </div></li>
149
 </ol>
150
151
 <dl>
152
 <dt class="level1"><span class="dt"> Definition list</span></dt>
153
 <dd class="level1"><div class="dd">
154
  Definition lists vary only slightly from other types of lists in that list items consist of two parts: a term and a description. The term is given by the DT element and is restricted to inline content. The description is given with a DD element that contains block-level content. [Source: <abbr title="World Wide Web Consortium">W3C</abbr>]
155
 </div></dd>
156
 <dt class="level1"><span class="dt"> Definition list w/ multiple paragraphs</span></dt>
157
 <dd class="level1"><div class="dd">
158
 <p>
159
  The style sheet provided with this plugin will render these paragraphs…
160
 </p><p>
161
  … to the left of the term being defined.
162
 </p>
163
 </div><dl>
164
 <dt class="level2"><span class="dt"> Definition list w/ multiple “paragraphs”</span></dt>
165
 <dd class="level2"><div class="dd">
166
  Another way to separate blocks of text in a definition…
167
 </div></dd>
168
 <dd class="level2"><div class="dd">
169
  … is to simply have multiple definitions for a term (or group of terms).
170
 </div></dd>
171
 </dl>
172
 </dd>
173
 </dl>
174
175
 <dl>
176
 <dd class="level1"><div class="dd">
177
  This definition list has DD tags without any preceding DT tags.
178
 </div></dd>
179
 <dd class="level1"><div class="dd">
180
  Hey, it&#039;s legal XHTML.
181
 </div></dd>
182
 <dt class="level1"><span class="dt"> Just like DT tags without following DD tags.</span></dt>
183
 <dt class="level1"><span class="dt">? But DT tags can&#039;t contain paragraphs. That would <em class="u">not</em> be legal XHTML.</span></dt>
184
 </dl>
185
186
 <pre class="code">.. If you try, the result will be rendered oddly.</pre>
187
188
 </div>') !== false,
189
            'expected html snippet was not in the output'
190
        );
191
    }
192
}
193