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

SiteTest.php « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a8b1a332461dd9ba1cd116efef7fe9dd9945e7b (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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Tests\Integration;

use Piwik\Piwik;
use Piwik\Plugins\SitesManager\API;
use Piwik\Site;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

/**
 * @group Core
 */
class SiteTest extends IntegrationTestCase
{
    private $idSite;

    public $siteAppendix = ' foo';

    public function setUp()
    {
        parent::setUp();

        $this->idSite = Fixture::createWebsite('2014-01-02 03:04:05');

        $self = $this;

        Piwik::addAction('Site.setSites', function (&$sites) use ($self) {
            foreach ($sites as &$site) {
                if (strpos($site['name'], $self->siteAppendix) !== 0) {
                    $site['name'] .= $self->siteAppendix;
                }
            }
        });
    }

    /**
     * @expectedException \Piwik\Exception\UnexpectedWebsiteFoundException
     * @expectedExceptionMessage An unexpected website was found in the request
     */
    public function test_constructor_throwsException_ifSiteDoesNotExist()
    {
        $this->makeSite(9999);
    }

    public function test_constructor_enrichesSite()
    {
        $site = $this->makeSite($this->idSite);
        $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName());
    }

    public function test_construct_enrichesSiteEvenIfSiteWasSetToCachePreviously()
    {
        $site = API::getInstance()->getSiteFromId($this->idSite);
        Site::setSiteFromArray($this->idSite, $site);

        $site = $this->makeSite($this->idSite);
        $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName());
    }

    public function test_construct_whenRemovingSiteFromGlobalSitesArray_TheObjectItselfStillworks()
    {
        $site = $this->makeSite($this->idSite);
        $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName());

        Site::clearCache();

        $this->assertSame('Piwik test' . $this->siteAppendix, $site->getName());
        $this->assertSame(array(), Site::getSites()); // make sure data was not fetched again
    }

    private function makeSite($idSite)
    {
        return new Site($idSite);
    }
}