قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 15:07:44 +00:00

* [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps * [Coding Style] Use camel case for method names in API plugin tests (#22145) * [Coding Style] Use camel case for method names in Core* plugin tests (#22147) * [Coding Style] Use camel case for method names in core Unit tests (#22149) * [Coding Style] Use camel case for method names in Actions and BulkTracking plugin tests (#22146) * [Coding Style] Use camel case for method names in CustomDimensions and CustomJSTracker plugin tests (#22148) * [Coding Style] Use camel case for method names in core Integration tests (#22151) * [Coding Style] Use camel case for method names in more core plugin tests (#22153) * [Coding Style] Use camel case for method names in more core plugin tests (#22157) * [Coding Style] Use camel case for method names in more core plugin tests * Update plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php Co-authored-by: Michal Kleiner <michal@innocraft.com> --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> * [Coding Style] Use camel case for method names in more core plugin tests (#22159) * [Coding Style] Use camel case for method names in remaining tests (#22160) * [Coding Style] Use camel case for method names in remaining tests * rename expected test files --------- Co-authored-by: Michal Kleiner <michal@innocraft.com>
142 خطوط
4.0 KiB
PHP
142 خطوط
4.0 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Matomo - free/libre analytics platform
|
|
*
|
|
* @link https://matomo.org
|
|
* @license https://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 testShouldPromptForFeedbackAnonymousUser()
|
|
{
|
|
FakeAccess::$identity = '';
|
|
|
|
$this->assertFalse($this->feedback->showQuestionBanner());
|
|
}
|
|
|
|
|
|
public function testShouldPromptForFeedbackDontRemindUserAgain()
|
|
{
|
|
Option::set('Feedback.nextFeedbackReminder.user1', '-1');
|
|
|
|
$this->assertFalse($this->feedback->showQuestionBanner());
|
|
}
|
|
|
|
public function testShouldPromptForFeedbackNextReminderDateInPast()
|
|
{
|
|
FakeAccess::$identity = 'user1';
|
|
Option::set('Feedback.nextFeedbackReminder.user1', '2019-05-31');
|
|
$this->assertTrue($this->feedback->showQuestionBanner());
|
|
}
|
|
|
|
public function testShouldPromptForFeedackNextReminderDateToday()
|
|
{
|
|
Option::set('Feedback.nextFeedbackReminder.user1', '2018-10-31');
|
|
$this->assertTrue($this->feedback->showQuestionBanner());
|
|
}
|
|
|
|
public function testShouldPromptForFeedbackUserOldThanHalfYear()
|
|
{
|
|
FakeAccess::$identity = 'user1';
|
|
Option::deleteLike('Feedback.nextFeedbackReminder.user1');
|
|
$this->assertFalse($this->feedback->showQuestionBanner());
|
|
}
|
|
|
|
public function testShouldNotPromptForFeedbackUserLessThanHalfYear()
|
|
{
|
|
FakeAccess::$identity = 'user2';
|
|
$this->assertFalse($this->feedback->showQuestionBanner());
|
|
}
|
|
|
|
public function testShouldSendFeedbackForFeature()
|
|
{
|
|
$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);
|
|
}
|
|
}
|