Passed
Pull Request — master (#29)
by Mark
10:48
created

action_plugin_socialcards_test::testHeaders()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 62

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 62
rs 8.829
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
/**
19
 * Action tests for the socialcards plugin.
20
 *
21
 * @group plugin_socialcards
22
 * @group plugins
23
 */
24
class action_plugin_socialcards_test extends DokuWikiTest {
25
26
    protected $pluginsEnabled = array('socialcards');
27
28
    public function setUp() : void {
29
        global $conf;
30
31
        parent::setUp();
32
33
        $conf ['plugin']['socialcards']['twitterName']     = '@twitterName';
34
        $conf ['plugin']['socialcards']['twitterUserName'] = '@twitterUserName';
35
    }
36
37
    public function testHeaders() {
38
        $request  = new TestRequest();
39
        $params = array(
40
            'id' => 'wiki:dokuwiki'
41
        );
42
        $response = $request->get($params, '/doku.php');
43
44
        print_r($response);
45
46
        $this->assertTrue(
47
            strpos($response->getContent(), 'DokuWiki') !== false,
48
            'DokuWiki was not a word in the output'
49
        );
50
51
        // check twitter meta headers
52
        $this->assertEquals(
53
            'DokuWiki',
54
            $response->queryHTML('meta[name="twitter:title"]')->attr('content')
55
        );
56
        $this->assertEquals(
57
            '@twitterName',
58
            $response->queryHTML('meta[name="twitter:site"]')->attr('content')
59
        );
60
        $this->assertEquals(
61
            'summary',
62
            $response->queryHTML('meta[name="twitter:card"]')->attr('content')
63
        );
64
        $this->assertEquals(
65
            '@twitterUserName',
66
            $response->queryHTML('meta[name="twitter:creator"]')->attr('content')
67
        );
68
        $this->assertEquals(
69
            'http://wiki.example.com/./lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
70
            $response->queryHTML('meta[name="twitter:image"]')->attr('content')
71
        );
72
        $this->assertEquals(
73
            '',
74
            $response->queryHTML('meta[name="twitter:image:alt"]')->attr('content')
75
        );
76
77
        // check og meta headers
78
        $this->assertEquals(
79
            'My Test Wiki',
80
            $response->queryHTML('meta[property="og:site_name"]')->attr('content')
81
        );
82
        $this->assertEquals(
83
            'en_US',
84
            $response->queryHTML('meta[property="og:locale"]')->attr('content')
85
        );
86
        $this->assertEquals(
87
            'http://wiki.example.com/./lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
88
            $response->queryHTML('meta[property="og:image"]')->attr('content')
89
        );
90
        $this->assertEquals(
91
            'DokuWiki',
92
            $response->queryHTML('meta[property="og:title"]')->attr('content')
93
        );
94
        $this->assertEquals(
95
            'article',
96
            $response->queryHTML('meta[property="og:type"]')->attr('content')
97
        );
98
    }
99
}
100