1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ByTIC\GoogleAnalytics\Tests\Renderer\Script\AnalyticsJs; |
4
|
|
|
|
5
|
|
|
use ByTIC\GoogleAnalytics\Tests\AbstractTest; |
6
|
|
|
use ByTIC\GoogleAnalytics\Tracking\Data\Tracker; |
7
|
|
|
use ByTIC\GoogleAnalytics\Tracking\Renderer\Script\AnalyticsJs\CreateCommand; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class CreateMethodTest |
11
|
|
|
* @package ByTIC\GoogleAnalytics\Tests\Renderer\Script\AnalyticsJs |
12
|
|
|
*/ |
13
|
|
|
class CreateMethodTest extends AbstractTest |
14
|
|
|
{ |
15
|
|
|
public function testGenerateEmptyTracker() |
16
|
|
|
{ |
17
|
|
|
$tracker = new Tracker(); |
18
|
|
|
|
19
|
|
|
self::assertSame( |
20
|
|
|
"\n" . 'ga("create",null,"auto");', |
21
|
|
|
CreateCommand::generate($tracker) |
22
|
|
|
); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
View Code Duplication |
public function testGenerateAliasTracker() |
|
|
|
|
26
|
|
|
{ |
27
|
|
|
$tracker = new Tracker(); |
28
|
|
|
$tracker->setTrackingId('UA-XXXXX-Y'); |
29
|
|
|
$tracker->setAlias('myTracker'); |
30
|
|
|
|
31
|
|
|
self::assertSame( |
32
|
|
|
"\n" . 'ga("create","UA-XXXXX-Y","auto","myTracker");', |
33
|
|
|
CreateCommand::generate($tracker) |
34
|
|
|
); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function testGenerateAllowLinkerTracker() |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$tracker = new Tracker(); |
40
|
|
|
$tracker->setTrackingId('UA-XXXXX-Y'); |
41
|
|
|
$tracker->setAlias('myTracker'); |
42
|
|
|
$tracker->setAllowLinker(true); |
43
|
|
|
|
44
|
|
|
self::assertSame( |
45
|
|
|
"\n" . 'ga("create","UA-XXXXX-Y","auto","myTracker",{"allowLinker":true});', |
46
|
|
|
CreateCommand::generate($tracker) |
47
|
|
|
); |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.