diff options
-rw-r--r-- | core/Version.php | 16 | ||||
-rw-r--r-- | plugins/CoreUpdater/UpdateCommunication.php | 31 | ||||
-rw-r--r-- | plugins/CoreUpdater/lang/en.json | 3 | ||||
-rw-r--r-- | plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php | 35 | ||||
-rw-r--r-- | tests/PHPUnit/Unit/VersionTest.php | 82 |
5 files changed, 155 insertions, 12 deletions
diff --git a/core/Version.php b/core/Version.php index 393f081a15..27be60d8ce 100644 --- a/core/Version.php +++ b/core/Version.php @@ -21,4 +21,20 @@ final class Version * @var string */ const VERSION = '2.11.0-b2'; + + public function isStableVersion($version) + { + return (bool) preg_match('/^(\d+)\.(\d+)\.(\d+)$/', $version); + } + + public function isVersionNumber($version) + { + return $this->isStableVersion($version) || $this->isNonStableVersion($version); + } + + private function isNonStableVersion($version) + { + return (bool) preg_match('/^(\d+)\.(\d+)\.(\d+)-.{1,4}(\d+)$/', $version); + } + } diff --git a/plugins/CoreUpdater/UpdateCommunication.php b/plugins/CoreUpdater/UpdateCommunication.php index cd52e80a3e..27f253eed4 100644 --- a/plugins/CoreUpdater/UpdateCommunication.php +++ b/plugins/CoreUpdater/UpdateCommunication.php @@ -15,6 +15,7 @@ use Piwik\Piwik; use Piwik\Plugins\UsersManager\API as UsersManagerApi; use Piwik\SettingsPiwik; use Piwik\UpdateCheck; +use Piwik\Version; /** * Class to check and notify users via email if there is a core update available. @@ -66,9 +67,18 @@ class UpdateCommunication $message .= Piwik::translate('CoreUpdater_ThereIsNewVersionAvailableForUpdate'); $message .= "\n\n"; $message .= Piwik::translate('CoreUpdater_YouCanUpgradeAutomaticallyOrDownloadPackage', $latestVersion); - $message .= "\n\n"; + $message .= "\n"; $message .= $host . 'index.php?module=CoreUpdater&action=newVersionAvailable'; $message .= "\n\n"; + + $version = new Version(); + if ($version->isStableVersion($latestVersion)) { + $message .= Piwik::translate('CoreUpdater_ViewVersionChangelog'); + $message .= "\n"; + $message .= $this->getLinkToChangeLog($latestVersion); + $message .= "\n\n"; + } + $message .= Piwik::translate('CoreUpdater_FeedbackRequest'); $message .= "\n"; $message .= 'http://piwik.org/contact/'; @@ -76,9 +86,13 @@ class UpdateCommunication $this->sendEmailNotification($subject, $message); } - protected function isVersionLike($latestVersion) + private function getLinkToChangeLog($version) { - return strlen($latestVersion) < 18; + $version = str_replace('.', '-', $version); + + $link = sprintf('http://piwik.org/changelog/piwik-%s/', $version); + + return $link; } /** @@ -112,7 +126,8 @@ class UpdateCommunication } $latestVersion = self::getLatestVersion(); - if (!$this->isVersionLike($latestVersion)) { + $version = new Version(); + if (!$version->isVersionNumber($latestVersion)) { return false; } @@ -135,7 +150,13 @@ class UpdateCommunication private function getLatestVersion() { - return UpdateCheck::getLatestVersion(); + $version = UpdateCheck::getLatestVersion(); + + if (!empty($version)) { + $version = trim($version); + } + + return $version; } private function getLatestVersionSent() diff --git a/plugins/CoreUpdater/lang/en.json b/plugins/CoreUpdater/lang/en.json index 1b94754223..8b07522489 100644 --- a/plugins/CoreUpdater/lang/en.json +++ b/plugins/CoreUpdater/lang/en.json @@ -56,6 +56,7 @@ "YouCanUpgradeAutomaticallyOrDownloadPackage": "You can update to version %s automatically or download the package and install it manually:", "YouCouldManuallyExecuteSqlQueries": "If you are not able to use the command line updater and if Piwik fails to upgrade (due to a timeout of the database, a browser timeout, or any other issue), you could manually execute the SQL queries to update Piwik.", "YouMustDownloadPackageOrFixPermissions": "Piwik is unable to overwrite your current installation. You can either fix the directory\/file permissions, or download the package and install version %s manually:", - "YourDatabaseIsOutOfDate": "Your Piwik database is out-of-date, and must be upgraded before you can continue." + "YourDatabaseIsOutOfDate": "Your Piwik database is out-of-date, and must be upgraded before you can continue.", + "ViewVersionChangelog": "View the changelog for this version:" } }
\ No newline at end of file diff --git a/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php b/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php index 8bda8a2699..91b6e2c2a1 100644 --- a/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php +++ b/plugins/CoreUpdater/tests/Integration/UpdateCommunicationTest.php @@ -61,7 +61,7 @@ class UpdateCommunicationTest extends IntegrationTestCase array(Version::VERSION, false, $this->never(), false), // shouldNotSend_IfNoUpdateAvailable array('33.0.0', '33.0.0', $this->never(), '33.0.0'), // shouldNotSend_IfAlreadyNotified array('31.0.0', '33.0.0', $this->never(), '33.0.0'), // shouldNotSend_IfAlreadyNotifiedAboutLaterRelease - array('3333.3333.3333-beta10', '31.0.0', $this->never(), '31.0.0'), // shouldNotSend_IfLatestVersionIsNotVersionLike, + array('3333.3333.3333-bbeta10', '31.0.0', $this->never(), '31.0.0'), // shouldNotSend_IfLatestVersionIsNotVersionLike, array('33.0.0', false, $this->once(), '33.0.0'), // shouldSend_IfUpdateAvailableAndNeverSentAnyBefore array('33.0.0', '31.0.0', $this->once(), '33.0.0'), // shouldSend_IfUpdateAvailable ); @@ -69,24 +69,47 @@ class UpdateCommunicationTest extends IntegrationTestCase public function test_sendNotifications_shouldSentCorrectEmail() { - $this->setLatestVersion('33.0.0'); - - $subject = 'CoreUpdater_NotificationSubjectAvailableCoreUpdate'; $message = 'ScheduledReports_EmailHello CoreUpdater_ThereIsNewVersionAvailableForUpdate CoreUpdater_YouCanUpgradeAutomaticallyOrDownloadPackage +index.php?module=CoreUpdater&action=newVersionAvailable +CoreUpdater_ViewVersionChangelog +http://piwik.org/changelog/piwik-33-0-0/ + +CoreUpdater_FeedbackRequest +http://piwik.org/contact/'; + + $this->assertEmailForVersion('33.0.0', $message); + } + + public function test_sendNotifications_shouldNotIncludeChangelogIfNotMajorVersionUpdate() + { + $message = 'ScheduledReports_EmailHello + +CoreUpdater_ThereIsNewVersionAvailableForUpdate + +CoreUpdater_YouCanUpgradeAutomaticallyOrDownloadPackage index.php?module=CoreUpdater&action=newVersionAvailable CoreUpdater_FeedbackRequest http://piwik.org/contact/'; + $this->assertEmailForVersion('33.0.0-b1', $message); + } + + private function assertEmailForVersion($version, $expectedMessage) + { + $this->setLatestVersion($version); + + $subject = 'CoreUpdater_NotificationSubjectAvailableCoreUpdate'; + $mock = $this->getCommunicationMock(array('sendEmailNotification')); $mock->expects($this->once()) - ->method('sendEmailNotification') - ->with($this->equalTo($subject), $this->equalTo($message)); + ->method('sendEmailNotification') + ->with($this->equalTo($subject), $this->equalTo($expectedMessage)); $mock->sendNotificationIfUpdateAvailable(); } diff --git a/tests/PHPUnit/Unit/VersionTest.php b/tests/PHPUnit/Unit/VersionTest.php new file mode 100644 index 0000000000..03e588d73d --- /dev/null +++ b/tests/PHPUnit/Unit/VersionTest.php @@ -0,0 +1,82 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Tests\Unit; + +use Piwik\Tests\Framework\TestCase\UnitTestCase; +use Piwik\Version; + +class VersionTest extends UnitTestCase +{ + /** + * @var Version + */ + private $version; + + public function setUp() + { + $this->version = new Version(); + } + + public function test_isStableVersion() + { + $this->assertIsStableVersion('3.3.3'); + $this->assertIsStableVersion('3.0.0'); + $this->assertIsStableVersion('100.999.9191'); + + $this->assertNotStableVersion('3.3'); + $this->assertNotStableVersion('3.3.'); + $this->assertNotStableVersion('3-3-3'); + $this->assertNotStableVersion('a3.3.3'); + $this->assertNotStableVersion('3.0.0b'); + $this->assertNotStableVersion('3.3.3-b1'); + $this->assertNotStableVersion('3.3.3-rc1'); + } + + public function test_isVersionNumber() + { + $this->assertIsVersionNumber('3.3.3'); + $this->assertIsVersionNumber('3.3.3-b1'); + $this->assertIsVersionNumber('100.999.9991-rc90'); + $this->assertIsVersionNumber('100.999.9991-b90'); + $this->assertIsVersionNumber('100.999.9991-beta90'); + + $this->assertNotVersionNumber('3.3'); + $this->assertNotVersionNumber('3.3.'); + $this->assertNotVersionNumber('3-3-3'); + $this->assertNotVersionNumber('a3.3.3'); + $this->assertNotVersionNumber('3.0.0b'); + $this->assertNotVersionNumber('3.0.0beta1'); // missing dash + $this->assertNotVersionNumber('3.3.3-bbeta1'); // max 4 allowed but bbeta is 5 + } + + private function assertIsStableVersion($versionNumber) + { + $isStable = $this->version->isStableVersion($versionNumber); + $this->assertTrue($isStable); + } + + private function assertNotStableVersion($versionNumber) + { + $isStable = $this->version->isStableVersion($versionNumber); + $this->assertFalse($isStable); + } + + private function assertIsVersionNumber($versionNumber) + { + $isStable = $this->version->isVersionNumber($versionNumber); + $this->assertTrue($isStable); + } + + private function assertNotVersionNumber($versionNumber) + { + $isStable = $this->version->isVersionNumber($versionNumber); + $this->assertFalse($isStable); + } + +} |