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

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKate Butler <kate@innocraft.com>2019-06-18 07:45:33 +0300
committerMatthieu Aubry <mattab@users.noreply.github.com>2019-06-18 07:45:33 +0300
commit57f7184a0dc49df4eacbbd27ca0aef909668b410 (patch)
tree2e859a11c514d1d7e8ccd302d42703c4897cb2c1 /plugins/Feedback/tests/Integration
parent3cdce09b6b27fa8378b2b7eec55760f3aa04951d (diff)
Ask users to leave a review for Matomo (#14432)
* Ask users to leave a review for Matomo - WIP commit * Unit tests for feedback reminder popup * Tidying up * Add content to popup, also display on help page and after thumbs-up rating * Make UI tests; move logic out of API into Controller; tidying up * FIX UI tests * Use SVG icons * Fix test * New expected screenshot for test; tear down feedback reminder option so that other tests won't display it * New fixture for FeedbackPopup tests * Move feedback form UI spec out of UIIntegration, update screenshot * Check auth on updateFeedbackReminderDate() route * PR changes * Fix bug from typecasting
Diffstat (limited to 'plugins/Feedback/tests/Integration')
-rw-r--r--plugins/Feedback/tests/Integration/ControllerTest.php92
-rw-r--r--plugins/Feedback/tests/Integration/FeedbackTest.php118
2 files changed, 210 insertions, 0 deletions
diff --git a/plugins/Feedback/tests/Integration/ControllerTest.php b/plugins/Feedback/tests/Integration/ControllerTest.php
new file mode 100644
index 0000000000..fa39b28bfd
--- /dev/null
+++ b/plugins/Feedback/tests/Integration/ControllerTest.php
@@ -0,0 +1,92 @@
+<?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\NoAccessException;
+use Piwik\Option;
+use Piwik\Plugins\Feedback\Controller;
+use Piwik\Plugins\UsersManager\Model;
+use Piwik\Tests\Framework\Mock\FakeAccess;
+use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
+
+class ControllerTest extends IntegrationTestCase
+{
+ /** @var Controller */
+ private $controller;
+
+ /** @var Model */
+ private $userModel;
+
+ private $now;
+
+ public function setUp()
+ {
+ parent::setUp();
+ $this->controller = new Controller();
+
+ $this->userModel = new Model();
+ $this->userModel->addUser(
+ 'user1',
+ 'a98732d98732',
+ 'user1@example.com',
+ 'user1',
+ 'ab9879dc23876f19',
+ '2019-03-03'
+ );
+ FakeAccess::$identity = 'user1';
+ FakeAccess::$superUser = false;
+
+ $this->now = Date::$now;
+ Date::$now = Date::factory('2019-05-31')->getTimestamp();
+ }
+
+ public function tearDown()
+ {
+ Option::deleteLike('Feedback.nextFeedbackReminder.%');
+ $this->userModel->deleteUserOnly('user1');
+ Date::$now = $this->now;
+
+ parent::tearDown();
+ }
+
+ public function provideContainerConfig()
+ {
+ return array(
+ 'Piwik\Access' => new FakeAccess()
+ );
+ }
+
+
+ public function test_updateFeedbackReminder_addNinetyDays()
+ {
+ $_POST['nextReminder'] = '90';
+ $this->controller->updateFeedbackReminderDate();
+
+ $option = Option::get('Feedback.nextFeedbackReminder.user1');
+ $this->assertEquals($option, '2019-08-29');
+ }
+
+ public function test_updateFeedbackReminder_neverAgain()
+ {
+ $_POST['nextReminder'] = '-1';
+ $this->controller->updateFeedbackReminderDate();
+
+ $option = Option::get('Feedback.nextFeedbackReminder.user1');
+ $this->assertEquals($option, '-1');
+ }
+
+ public function test_updateFeedbackReminder_notLoggedIn()
+ {
+ FakeAccess::$identity = null;
+ FakeAccess::$superUser = false;
+ $this->setExpectedException(NoAccessException::class);
+ $this->controller->updateFeedbackReminderDate();
+ }
+} \ No newline at end of file
diff --git a/plugins/Feedback/tests/Integration/FeedbackTest.php b/plugins/Feedback/tests/Integration/FeedbackTest.php
new file mode 100644
index 0000000000..7878a0c9cf
--- /dev/null
+++ b/plugins/Feedback/tests/Integration/FeedbackTest.php
@@ -0,0 +1,118 @@
+<?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\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()
+ {
+ parent::setUp();
+
+ $this->feedback = new Feedback();
+
+ $this->userModel = new Model();
+ $this->userModel->addUser(
+ 'user1',
+ 'a98732d98732',
+ 'user1@example.com',
+ 'user1',
+ 'ab9879dc23876f19',
+ '2019-03-03'
+ );
+ FakeAccess::$identity = 'user1';
+ FakeAccess::$superUser = false;
+
+ $this->now = Date::$now;
+ }
+
+ public function tearDown()
+ {
+ Option::deleteLike('Feedback.nextFeedbackReminder.%');
+ $this->userModel->deleteUserOnly('user1');
+ 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->getShouldPromptForFeedback());
+ }
+
+ public function test_shouldPromptForFeedback_noFeedbackReminderOptionForUser()
+ {
+ Date::$now = Date::factory('2019-05-31')->getTimestamp(); // 89 days
+
+ $this->assertFalse($this->feedback->getShouldPromptForFeedback());
+ }
+
+ public function test_shouldPromptForFeedback_noFeedbackReminderOptionForUser_newUser()
+ {
+ Date::$now = Date::factory('2019-06-01')->getTimestamp(); // 90 days
+
+ $this->assertTrue($this->feedback->getShouldPromptForFeedback());
+ }
+
+ public function test_shouldPromptForFeedback_dontRemindUserAgain()
+ {
+ Option::set('Feedback.nextFeedbackReminder.user1', '-1');
+
+ $this->assertFalse($this->feedback->getShouldPromptForFeedback());
+ }
+
+ public function test_shouldPromptForFeedback_nextReminderDateInPast()
+ {
+ Option::set('Feedback.nextFeedbackReminder.user1', '2019-05-31');
+ Date::$now = Date::factory('2019-06-01')->getTimestamp();
+
+ $this->assertTrue($this->feedback->getShouldPromptForFeedback());
+ }
+
+ public function test_shouldPromptForFeedack_nextReminderDateToday()
+ {
+ Option::set('Feedback.nextFeedbackReminder.user1', '2019-05-31');
+ Date::$now = Date::factory('2019-05-31')->getTimestamp();
+
+ $this->assertTrue($this->feedback->getShouldPromptForFeedback());
+ }
+
+ public function test_shouldPromptForFeedack_nextReminderDateInFuture()
+ {
+ Option::set('Feedback.nextFeedbackReminder.user1', '2019-05-31');
+ Date::$now = Date::factory('2019-05-30')->getTimestamp();
+
+ $this->assertFalse($this->feedback->getShouldPromptForFeedback());
+ }
+} \ No newline at end of file