Completed
Pull Request — master (#19)
by Mark
02:21
created

action_plugin_socialcards_test::testHeaders()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 37
rs 8.8571
cc 1
eloc 29
nc 1
nop 0
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
   function setUp(){
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...
29
        global $conf;
30
31
        parent::setUp();
32
33
        $conf ['plugin']['socialcards']['twitterName'] = '@twitterName';
34
        $conf ['plugin']['socialcards']['twitterUserName'] = '@twitterUserName';
35
        // $conf ['plugin']['socialcards']['fallbackImage'] = 'wiki:dokuwiki-128.png';
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
36
        // $conf ['plugin']['socialcards']['languageTerritory'] = 'en_US';
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
37
        // $conf ['plugin']['socialcards']['fbAppId'] = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
71% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
38
    }
39
40
    public function testHeaders() {
41
        $request = new TestRequest();
42
        $response = $request->get(array('id'=>'wiki:dokuwiki'),'/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('DokuWiki',
53
                        $response->queryHTML('meta[name="twitter:title"]')->attr('content'));
54
        $this->assertEquals('@twitterName',
55
                        $response->queryHTML('meta[name="twitter:site"]')->attr('content'));
56
        $this->assertEquals('summary',
57
                        $response->queryHTML('meta[name="twitter:card"]')->attr('content'));
58
        $this->assertEquals('@twitterUserName',
59
                        $response->queryHTML('meta[name="twitter:creator"]')->attr('content'));
60
        $this->assertEquals('http://wiki.example.com/./lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
61
                        $response->queryHTML('meta[name="twitter:image"]')->attr('content'));
62
        $this->assertEquals('',
63
                        $response->queryHTML('meta[name="twitter:image:alt"]')->attr('content'));
64
65
        // check og meta headers
66
        $this->assertEquals('My Test Wiki',
67
                        $response->queryHTML('meta[property="og:site_name"]')->attr('content'));
68
        $this->assertEquals('en_US',
69
                        $response->queryHTML('meta[property="og:locale"]')->attr('content'));
70
        $this->assertEquals('http://wiki.example.com/./lib/exe/fetch.php?media=wiki:dokuwiki-128.png',
71
                        $response->queryHTML('meta[property="og:image"]')->attr('content'));
72
        $this->assertEquals('DokuWiki',
73
                        $response->queryHTML('meta[property="og:title"]')->attr('content'));
74
        $this->assertEquals('article',
75
                        $response->queryHTML('meta[property="og:type"]')->attr('content'));
76
    }
77
}
78