Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SocialTest.php « Unit « tests « Referrers « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b292503287af6770fd742509e39176b1629e6b37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\Referrers\tests;

use Piwik\Plugins\Referrers\Social;
use Spyc;

/**
 * @group Social
 * @group Plugins
 */
class SocialTest extends \PHPUnit\Framework\TestCase
{
    public static function setUpBeforeClass(): void
    {
        // inject definitions to avoid database usage
        $yml = file_get_contents(PIWIK_PATH_TEST_TO_ROOT . Social::DEFINITION_FILE);
        Social::getInstance()->loadYmlData($yml);
        parent::setUpBeforeClass();
    }

    public function isSocialUrlTestData()
    {
        return array(
            array('http://www.facebook.com', 'Facebook', true),
            array('http://www.facebook.com', 'Twitter', false),
            array('http://m.facebook.com', false, true),
            array('http://lastfm.com.tr', 'Last.fm', true),
            array('http://asdfasdf.org/test', false, false),
            array('http://asdfasdf.com/test', 'Facebook', false),
        );
    }

    /**
     * @dataProvider isSocialUrlTestData
     */
    public function testIsSocialUrl($url, $assumedSocial, $expected)
    {
        $this->assertEquals($expected, Social::getInstance()->isSocialUrl($url, $assumedSocial));
    }


    /**
     * Dataprovider for getSocialNetworkFromDomainTestData
     */
    public function getSocialNetworkFromDomainTestData()
    {
        return array(
            array('http://www.facebook.com', 'Facebook'),
            array('http://www.facebook.com/piwik', 'Facebook'),
            array('http://m.facebook.com', 'Facebook'),
            array('https://m.facebook.com', 'Facebook'),
            array('m.facebook.com', 'Facebook'),
            array('http://lastfm.com.tr', 'Last.fm'),
            array('http://t.co/test', 'Twitter'),
            array('http://xxt.co/test', \Piwik\Piwik::translate('General_Unknown')),
            array('asdfasdfadsf.com', \Piwik\Piwik::translate('General_Unknown')),
            array('http://xwayn.com', \Piwik\Piwik::translate('General_Unknown')),
            array('http://live.com/test', \Piwik\Piwik::translate('General_Unknown')),
        );
    }

    /**
     * @dataProvider getSocialNetworkFromDomainTestData
     */
    public function testGetSocialNetworkFromDomain($url, $expected)
    {
        $this->assertEquals($expected, Social::getInstance()->getSocialNetworkFromDomain($url));
    }

    public function getLogoFromUrlTestData()
    {
        return array(
            array('http://www.facebook.com', 'facebook.com.png'),
            array('www.facebook.com', 'facebook.com.png',),
            array('http://lastfm.com.tr', 'last.fm.png'),
            array('http://asdfasdf.org/test', 'xx.png'),
            array('http://www.google.com', 'xx.png'),
        );
    }

    /**
     * @group Plugins
     *
     * @dataProvider getLogoFromUrlTestData
     */
    public function testGetLogoFromUrl($url, $expected)
    {
        self::assertStringContainsString($expected, Social::getInstance()->getLogoFromUrl($url));
    }
}