1<?php
2/*
3 * Copyright (c) 2016 Mark C. Prins <mprins@users.sf.net>
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 */
24class 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(): void {
38        $request = new TestRequest();
39        $params  = array(
40            'id' => 'wiki:dokuwiki'
41        );
42
43        $response = $request->get($params, '/doku.php');
44
45        // print_r($response);
46
47        $this->assertNotFalse(
48            strpos($response->getContent(), 'DokuWiki'), '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