-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoogleAnalyticsTest.php
70 lines (56 loc) · 2 KB
/
GoogleAnalyticsTest.php
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
<?php
declare(strict_types=1);
// SPDX-FileCopyrightText: Mikhailo Matiyenko-Kupriyanov <[email protected]>
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace OCA\NCGoogleAnalytics\Tests\Integration\Controller;
use Exception;
use OCA\NCGoogleAnalytics\Controller\JavaScriptController;
use OCP\AppFramework\App;
use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\AppFramework\Http\TextPlainResponse;
use OCP\HintException;
use OCP\IConfig;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
class GoogleAnalyticsTest extends TestCase
{
private JavaScriptController $controller;
private IConfig $config;
/**
* @throws ContainerExceptionInterface
* @throws HintException
* @throws NotFoundExceptionInterface
*/
public function setUp(): void
{
$this->config = \OC::$server->getConfig();
$this->config->setSystemValue('googleanalytics_tracking_key', null);
$app = new App('googleanalytics');
$container = $app->getContainer();
$this->controller = $container->get(JavaScriptController::class);
}
public function tearDown(): void
{
$this->config->setSystemValue('googleanalytics_tracking_key', null);
}
/**
* @throws Exception
*/
public function testTrackingReturnsDisabledResponseWhenNoKey(): void
{
$response = $this->controller->tracking();
$this->assertInstanceOf(TextPlainResponse::class, $response);
$this->assertEquals('// tracking disabled', $response->render());
}
/**
* @throws Exception
*/
public function testTrackingReturnsScriptResponseWhenKeyExists(): void
{
$this->config->setSystemValue('googleanalytics_tracking_key', 'UA-123456-1');
$response = $this->controller->tracking();
$this->assertInstanceOf(DataDownloadResponse::class, $response);
$this->assertStringContainsString('UA-123456-1', $response->render());
}
}