diff options
author | Kate Butler <kate@innocraft.com> | 2019-06-18 07:45:33 +0300 |
---|---|---|
committer | Matthieu Aubry <mattab@users.noreply.github.com> | 2019-06-18 07:45:33 +0300 |
commit | 57f7184a0dc49df4eacbbd27ca0aef909668b410 (patch) | |
tree | 2e859a11c514d1d7e8ccd302d42703c4897cb2c1 /plugins/Feedback/tests | |
parent | 3cdce09b6b27fa8378b2b7eec55760f3aa04951d (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')
8 files changed, 311 insertions, 0 deletions
diff --git a/plugins/Feedback/tests/Fixtures/FeedbackPopupFixture.php b/plugins/Feedback/tests/Fixtures/FeedbackPopupFixture.php new file mode 100644 index 0000000000..e2ceaeb164 --- /dev/null +++ b/plugins/Feedback/tests/Fixtures/FeedbackPopupFixture.php @@ -0,0 +1,25 @@ +<?php + + +namespace Piwik\Plugins\Feedback\tests\Fixtures; + +use Piwik\Date; +use Piwik\Option; +use Piwik\Tests\Fixtures\UITestFixture; + +class FeedbackPopupFixture extends UITestFixture +{ + public function setUp() + { + parent::setUp(); + $yesterday = Date::yesterday(); + Option::set('Feedback.nextFeedbackReminder.superUserLogin', $yesterday->toString('Y-m-d')); + } + + public function tearDown() + { + parent::tearDown(); + Option::delete('Feedback.nextFeedbackReminder.superUserLogin'); + } + +}
\ No newline at end of file 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 diff --git a/plugins/Feedback/tests/UI/FeedbackForm_spec.js b/plugins/Feedback/tests/UI/FeedbackForm_spec.js new file mode 100644 index 0000000000..1b727bb0c7 --- /dev/null +++ b/plugins/Feedback/tests/UI/FeedbackForm_spec.js @@ -0,0 +1,26 @@ +/*! + * Matomo - free/libre analytics platform + * + * UsersManager screenshot tests. + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +describe("FeedbackForm", function () { + it('should load the feedback form when the feedback form link is clicked', async function() { + await page.goto("?idSite=1&period=year&date=2012-08-09&module=Feedback&action=index"); + + await page.evaluate(function () { + $('.enrichedHeadline .title').each(function () { + if ($(this).text().indexOf("Matomo") !== -1) { + var replace = $(this).text().replace(/Matomo\s*\d+\.\d+(\.\d+)?([\-a-z]*\d+)?/g, 'Matomo'); + $(this).text(replace); + } + }); + }); + + var pageWrap = await page.$('.pageWrap'); + expect(await pageWrap.screenshot()).to.matchImage('show'); + }); +});
\ No newline at end of file diff --git a/plugins/Feedback/tests/UI/FeedbackPopup_spec.js b/plugins/Feedback/tests/UI/FeedbackPopup_spec.js new file mode 100644 index 0000000000..cf1e05e9da --- /dev/null +++ b/plugins/Feedback/tests/UI/FeedbackPopup_spec.js @@ -0,0 +1,41 @@ +/*! + * Matomo - free/libre analytics platform + * + * UsersManager screenshot tests. + * + * @link https://matomo.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +describe("FeedbackPopup", function () { + this.timeout(0); + this.fixture = "Piwik\\Plugins\\Feedback\\tests\\Fixtures\\FeedbackPopupFixture "; + + var url = "?module=CoreHome&action=index&idSite=1&period=day&date=yesterday"; + + before(async function() { + await page.webpage.setViewport({ + width: 1250, + height: 768 + }); + }); + + it('should display popup when next reminder date is in past', async function () { + await page.goto(url); + await page.waitForNetworkIdle(); + + var modal = await page.waitFor('.modal.open', { visible: true }); + expect(await modal.screenshot()).to.matchImage('feedback_popup'); + + // Click on the "Remind me in 90 days" button = the popup shouldn't appear for the next test + var remindLaterBtn = await modal.$$('.modal-footer .btn-flat'); + await remindLaterBtn[0].click(); + }); + + it('should not display popup when next reminder date is in future', async function () { + await page.goto(url); + await page.waitForNetworkIdle(); + + expect(await page.screenshotSelector('#root')).to.matchImage('dashboard_no_popup'); + }); +});
\ No newline at end of file diff --git a/plugins/Feedback/tests/UI/expected-screenshots/FeedbackForm_show.png b/plugins/Feedback/tests/UI/expected-screenshots/FeedbackForm_show.png new file mode 100644 index 0000000000..da7f861dbb --- /dev/null +++ b/plugins/Feedback/tests/UI/expected-screenshots/FeedbackForm_show.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1c6815ca1419adec5cc2c57e24c9bf8dcf2f152d5aae178d31234145f02d64f +size 250999 diff --git a/plugins/Feedback/tests/UI/expected-screenshots/FeedbackPopup_dashboard_no_popup.png b/plugins/Feedback/tests/UI/expected-screenshots/FeedbackPopup_dashboard_no_popup.png new file mode 100644 index 0000000000..72f6971c7e --- /dev/null +++ b/plugins/Feedback/tests/UI/expected-screenshots/FeedbackPopup_dashboard_no_popup.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:205824232b6e593d41b1d4ba450a48c17737c61684e9ca9dc6f04641abe1b0aa +size 333574 diff --git a/plugins/Feedback/tests/UI/expected-screenshots/FeedbackPopup_feedback_popup.png b/plugins/Feedback/tests/UI/expected-screenshots/FeedbackPopup_feedback_popup.png new file mode 100644 index 0000000000..26eee22e3e --- /dev/null +++ b/plugins/Feedback/tests/UI/expected-screenshots/FeedbackPopup_feedback_popup.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:87e6b9b3dd27c8b8bf49f6ca2cb1ad104d31576758beeaeaeae130c29de22af6 +size 28202 |