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

FeedbackTest.php « Integration « tests « Feedback « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f86ea35098736976c6453020f5745669b556d52a (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
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link http://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\Feedback\tests\Unit;


use Piwik\Date;
use Piwik\Option;
use Piwik\Piwik;
use Piwik\Plugins\Feedback\API;
use Piwik\Plugins\Feedback\Feedback;
use Piwik\Plugins\UsersManager\Model;
use Piwik\Tests\Framework\Mock\FakeAccess;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;

class FeedbackTest extends IntegrationTestCase
{
    /** @var Feedback */
    private $feedback;

    /** @var Model */
    private $userModel;

    private $now;

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

        $this->feedback = $this->createPartialMock(Feedback::class, ['isDisabledInTestMode']);
        $this->feedback->method('isDisabledInTestMode')->willReturn(false);

        $this->userModel = new Model();
        $this->userModel->addUser(
          'user1',
          'a98732d98732',
          'user1@example.com',
          '2019-03-03'
        );

        $this->userModel->addUser(
          'user2',
          'a98732d98732',
          'user2@example.com',
          Date('Y-m-d')
        );
        FakeAccess::$identity = 'user1';
        FakeAccess::$superUser = false;
        FakeAccess::$idSitesView = [1];
        $this->now = Date::$now;
    }

    public function tearDown(): void
    {
        FakeAccess::$identity = 'user1';
        Option::deleteLike('Feedback.nextFeedbackReminder.%');
        $this->userModel->deleteUserOnly('user1');

        FakeAccess::$identity = 'user2';
        Option::deleteLike('Feedback.nextFeedbackReminder.%');
        $this->userModel->deleteUserOnly('user2');

        Date::$now = $this->now;
        parent::tearDown();
    }

    public function provideContainerConfig()
    {
        return array(
          'Piwik\Access' => new FakeAccess()
        );
    }


    public function test_shouldPromptForFeedback_AnonymousUser()
    {
        FakeAccess::$identity = '';

        $this->assertFalse($this->feedback->showQuestionBanner());
    }


    public function test_shouldPromptForFeedback_dontRemindUserAgain()
    {
        Option::set('Feedback.nextFeedbackReminder.user1', '-1');

        $this->assertFalse($this->feedback->showQuestionBanner());
    }

    public function test_shouldPromptForFeedback_nextReminderDateInPast()
    {
        FakeAccess::$identity = 'user1';
        Option::set('Feedback.nextFeedbackReminder.user1', '2019-05-31');
        $this->assertTrue($this->feedback->showQuestionBanner());
    }

    public function test_shouldPromptForFeedack_nextReminderDateToday()
    {
        Option::set('Feedback.nextFeedbackReminder.user1', '2018-10-31');
        $this->assertTrue($this->feedback->showQuestionBanner());
    }

    public function test_shouldPromptForFeedback_user_oldThanHalfYear()
    {
        FakeAccess::$identity = 'user1';
        Option::deleteLike('Feedback.nextFeedbackReminder.user1');
        $this->assertFalse($this->feedback->showQuestionBanner());
    }

    public function test_shouldNotPromptForFeedback_user_LessThanHalfYear()
    {
        FakeAccess::$identity = 'user2';
        $this->assertFalse($this->feedback->showQuestionBanner());
    }

    public function test_shouldSendFeedbackForFeature()
    {
        $api = API::getInstance();

        //test failed without message
        $result = $api->sendFeedbackForFeature('test');
        $this->assertEquals(Piwik::translate("Feedback_FormNotEnoughFeedbackText"), $result);

        //test pass with like is string 0
        $result = $api->sendFeedbackForFeature('test', "0", null, "dislike this test");
        $this->assertEquals("success", $result);

        //test pass with like is a string 1
        $result = $api->sendFeedbackForFeature('test', "1", null, "like this test");
        $this->assertEquals("success", $result);

        //test pass with like is null
        $result = $api->sendFeedbackForFeature('test', null, null, "dislike this test");
        $this->assertEquals("success", $result);

    }


}