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

FixDuplicateActionsTest.php « Integration « tests « CoreAdminHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a17b709f03e1ed79bb15b8cb40cad429c7b4d15b (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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<?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\Plugins\CoreAdminHome\tests\Integration;

use Piwik\Common;
use Piwik\Console;
use Piwik\Db;
use Piwik\Plugins\CoreAdminHome\tests\Fixture\DuplicateActions;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Symfony\Component\Console\Tester\ApplicationTester;

/**
 * @group Core
 */
class FixDuplicateActionsTest extends IntegrationTestCase
{
    /**
     * @var DuplicateActions
     */
    public static $fixture = null;

    /**
     * @var ApplicationTester
     */
    protected $applicationTester = null;

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

        $application = new Console();
        $application->setAutoExit(false);

        $this->applicationTester = new ApplicationTester($application);
    }

    public function test_FixDuplicateLogActions_CorrectlyRemovesDuplicates_AndFixesReferencesInOtherTables()
    {
        $result = $this->applicationTester->run(array(
            'command' => 'core:fix-duplicate-log-actions',
            '--invalidate-archives' => 0,
            '-vvv' => false
        ));

        $this->assertEquals(0, $result, "Command failed: " . $this->applicationTester->getDisplay());

        $this->assertDuplicateActionsRemovedFromLogActionTable();
        $this->assertDuplicatesFixedInLogLinkVisitActionTable();
        $this->assertDuplicatesFixedInLogConversionTable();
        $this->assertDuplicatesFixedInLogConversionItemTable();

        $this->assertContains("Found and deleted 7 duplicate action entries", $this->applicationTester->getDisplay());

        $expectedAffectedArchives = array(
            array('idsite' => '1', 'server_time' => '2012-01-01'),
            array('idsite' => '2', 'server_time' => '2013-01-01'),
            array('idsite' => '1', 'server_time' => '2012-02-01'),
            array('idsite' => '2', 'server_time' => '2012-01-09'),
            array('idsite' => '2', 'server_time' => '2012-03-01'),
        );
        foreach ($expectedAffectedArchives as $archive) {
            $this->assertContains("[ idSite = {$archive['idsite']}, date = {$archive['server_time']} ]", $this->applicationTester->getDisplay());
        }
    }

    private function assertDuplicateActionsRemovedFromLogActionTable()
    {
        $actions = Db::fetchAll("SELECT idaction, name FROM " . Common::prefixTable('log_action'));
        $expectedActions = array(
            array('idaction' => 1, 'name' => 'action1'),
            array('idaction' => 4, 'name' => 'action2'),
            array('idaction' => 5, 'name' => 'ACTION2'),
            array('idaction' => 6, 'name' => 'action4'),
            array('idaction' => 8, 'name' => 'action5'),
        );
        $this->assertEquals($expectedActions, $actions);
    }

    private function assertDuplicatesFixedInLogLinkVisitActionTable()
    {
        $columns = array(
            'idaction_url_ref',
            'idaction_name_ref',
            'idaction_name',
            'idaction_url',
            'idaction_event_action',
            'idaction_event_category',
            'idaction_content_interaction',
            'idaction_content_name',
            'idaction_content_piece',
            'idaction_content_target'
        );
        $rows = Db::fetchAll("SELECT " . implode(',', $columns) . " FROM " . Common::prefixTable('log_link_visit_action'));
        $expectedRows = array(
            array(
                'idaction_url_ref' => '1',
                'idaction_name_ref' => '1',
                'idaction_name' => '1',
                'idaction_url' => '4',
                'idaction_event_action' => '5',
                'idaction_event_category' => '6',
                'idaction_content_interaction' => '5',
                'idaction_content_name' => '8',
                'idaction_content_piece' => '4',
                'idaction_content_target' => '6'
            ),
            array(
                'idaction_url_ref' => '1',
                'idaction_name_ref' => '1',
                'idaction_name' => '5',
                'idaction_url' => '5',
                'idaction_event_action' => '4',
                'idaction_event_category' => '6',
                'idaction_content_interaction' => '5',
                'idaction_content_name' => '5',
                'idaction_content_piece' => '6',
                'idaction_content_target' => '6'
            )
        );
        $this->assertEquals($expectedRows, $rows);
    }

    private function assertDuplicatesFixedInLogConversionTable()
    {
        $rows = Db::fetchAll("SELECT idaction_url FROM " . Common::prefixTable('log_conversion'));
        $expectedRows = array(
            array('idaction_url' => 4),
            array('idaction_url' => 5)
        );
        $this->assertEquals($expectedRows, $rows);
    }

    private function assertDuplicatesFixedInLogConversionItemTable()
    {
        $columns = array(
            'idaction_sku',
            'idaction_name',
            'idaction_category',
            'idaction_category2',
            'idaction_category3',
            'idaction_category4',
            'idaction_category5'
        );
        $rows = Db::fetchAll("SELECT " . implode(',', $columns) . " FROM " . Common::prefixTable('log_conversion_item'));
        $expectedRows = array(
            array(
                'idaction_sku' => '1',
                'idaction_name' => '1',
                'idaction_category' => '1',
                'idaction_category2' => '4',
                'idaction_category3' => '5',
                'idaction_category4' => '6',
                'idaction_category5' => '5'
            ),
            array(
                'idaction_sku' => '1',
                'idaction_name' => '1',
                'idaction_category' => '5',
                'idaction_category2' => '5',
                'idaction_category3' => '8',
                'idaction_category4' => '4',
                'idaction_category5' => '6'
            )
        );
        $this->assertEquals($expectedRows, $rows);
    }
}

FixDuplicateActionsTest::$fixture = new DuplicateActions();