update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -0,0 +1,23 @@
|
|||
<?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\Plugins\CoreUpdater\Test\Fixtures;
|
||||
|
||||
use Piwik\Tests\Fixtures\SqlDump;
|
||||
|
||||
class DbUpdaterTestFixture extends SqlDump
|
||||
{
|
||||
public function performSetUp($setupEnvironmentOnly = false)
|
||||
{
|
||||
$this->dumpUrl = PIWIK_INCLUDE_PATH . "/tests/UI/resources/piwik1.0.sql.gz";
|
||||
$this->dropDatabaseInSetUp = true;
|
||||
$this->resetPersistedFixture = true;
|
||||
|
||||
parent::performSetUp($setupEnvironmentOnly);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?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\Plugins\CoreUpdater\Test\Fixtures;
|
||||
|
||||
use Piwik\Tests\Framework\Fixture;
|
||||
|
||||
/**
|
||||
* Fixture that makes the update over HTTPS fail to be able to test that users can still update over HTTP.
|
||||
*/
|
||||
class FailUpdateHttpsFixture extends Fixture
|
||||
{
|
||||
public function provideContainerConfig()
|
||||
{
|
||||
return array(
|
||||
'Piwik\Plugins\CoreUpdater\Updater' => \DI\object('Piwik\Plugins\CoreUpdater\Test\Mock\UpdaterMock'),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,123 @@
|
|||
<?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\Plugins\CoreUpdater\Test\Integration\Commands;
|
||||
|
||||
use Piwik\Config;
|
||||
use Piwik\DataAccess\ArchiveTableCreator;
|
||||
use Piwik\Date;
|
||||
use Piwik\Db;
|
||||
use Piwik\DbHelper;
|
||||
use Piwik\Option;
|
||||
use Piwik\Tests\Framework\TestCase\ConsoleCommandTestCase;
|
||||
use Piwik\Updates\Updates_2_10_0_b5;
|
||||
use Piwik\Version;
|
||||
use Symfony\Component\Console\Helper\QuestionHelper;
|
||||
|
||||
require_once PIWIK_INCLUDE_PATH . '/core/Updates/2.10.0-b5.php';
|
||||
|
||||
/**
|
||||
* @group CoreUpdater
|
||||
*/
|
||||
class UpdateTest extends ConsoleCommandTestCase
|
||||
{
|
||||
const VERSION_TO_UPDATE_FROM = '2.9.0';
|
||||
const EXPECTED_SQL_FROM_2_10 = "UPDATE report SET reports = REPLACE(reports, 'UserSettings_getBrowserVersion', 'DevicesDetection_getBrowserVersions');";
|
||||
|
||||
private $oldScriptName = null;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
Option::set('version_core', self::VERSION_TO_UPDATE_FROM);
|
||||
|
||||
$this->oldScriptName = $_SERVER['SCRIPT_NAME'];
|
||||
$_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_NAME'] . " console"; // update won't execute w/o this, see Common::isRunningConsoleCommand()
|
||||
|
||||
ArchiveTableCreator::clear();
|
||||
DbHelper::getTablesInstalled($forceReload = true); // force reload so internal cache in Mysql.php is refreshed
|
||||
Updates_2_10_0_b5::$archiveBlobTables = null;
|
||||
}
|
||||
|
||||
public function tearDown()
|
||||
{
|
||||
$_SERVER['SCRIPT_NAME'] = $this->oldScriptName;
|
||||
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function test_UpdateCommand_SuccessfullyExecutesUpdate()
|
||||
{
|
||||
$result = $this->applicationTester->run(array(
|
||||
'command' => 'core:update',
|
||||
'--yes' => true
|
||||
));
|
||||
|
||||
$this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
|
||||
|
||||
$this->assertDryRunExecuted($this->applicationTester->getDisplay());
|
||||
|
||||
// make sure update went through
|
||||
$this->assertEquals(Version::VERSION, Option::get('version_core'));
|
||||
}
|
||||
|
||||
public function test_UpdateCommand_DoesntExecuteSql_WhenUserSaysNo()
|
||||
{
|
||||
/** @var QuestionHelper $dialog */
|
||||
$dialog = $this->application->getHelperSet()->get('question');
|
||||
$dialog->setInputStream($this->getInputStream("N\n"));
|
||||
|
||||
$result = $this->applicationTester->run(array(
|
||||
'command' => 'core:update'
|
||||
));
|
||||
|
||||
$this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
|
||||
|
||||
$this->assertDryRunExecuted($this->applicationTester->getDisplay());
|
||||
|
||||
// make sure update did not go through
|
||||
$this->assertEquals(self::VERSION_TO_UPDATE_FROM, Option::get('version_core'));
|
||||
}
|
||||
|
||||
public function test_UpdateCommand_DoesNotExecuteUpdate_IfPiwikUpToDate()
|
||||
{
|
||||
Option::set('version_core', Version::VERSION);
|
||||
|
||||
$result = $this->applicationTester->run(array(
|
||||
'command' => 'core:update',
|
||||
'--yes' => true
|
||||
));
|
||||
|
||||
$this->assertEquals(0, $result, $this->getCommandDisplayOutputErrorMessage());
|
||||
|
||||
// check no update occurred
|
||||
$this->assertContains("Everything is already up to date.", $this->applicationTester->getDisplay());
|
||||
$this->assertEquals(Version::VERSION, Option::get('version_core'));
|
||||
}
|
||||
|
||||
public function test_UpdateCommand_ReturnsCorrectExitCode_WhenErrorOccurs()
|
||||
{
|
||||
// create a blob table, then drop it manually so update 2.10.0-b10 will fail
|
||||
$tableName = ArchiveTableCreator::getBlobTable(Date::factory('2015-01-01'));
|
||||
Db::exec("DROP TABLE $tableName");
|
||||
|
||||
$result = $this->applicationTester->run(array(
|
||||
'command' => 'core:update',
|
||||
'--yes' => true
|
||||
));
|
||||
|
||||
$this->assertEquals(1, $result, $this->getCommandDisplayOutputErrorMessage());
|
||||
$this->assertContains("Piwik could not be updated! See above for more information.", $this->applicationTester->getDisplay());
|
||||
}
|
||||
|
||||
private function assertDryRunExecuted($output)
|
||||
{
|
||||
$this->assertContains("Note: this is a Dry Run", $output);
|
||||
$this->assertContains(self::EXPECTED_SQL_FROM_2_10, $output);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
<?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\Plugins\CoreUpdater\Test\ReleaseChannel;
|
||||
|
||||
use Piwik\Config;
|
||||
use Piwik\Plugins\CoreUpdater\ReleaseChannel;
|
||||
use Piwik\UpdateCheck;
|
||||
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
|
||||
use Piwik\Url;
|
||||
use Piwik\Version;
|
||||
|
||||
class MyReleaseChannel extends ReleaseChannel
|
||||
{
|
||||
public function getId()
|
||||
{
|
||||
return 'my_channel';
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'My Special Channel';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @group Plugins
|
||||
* @group ReleaseChannel
|
||||
* @group ReleaseChannelTest
|
||||
*/
|
||||
class ReleaseChannelTest extends IntegrationTestCase
|
||||
{
|
||||
/**
|
||||
* @var MyReleaseChannel
|
||||
*/
|
||||
private $channel;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->channel = new MyReleaseChannel();
|
||||
}
|
||||
|
||||
public function test_getDownloadUrlWithoutScheme_shouldReturnUrlWithVersionNumberButWithoutScheme()
|
||||
{
|
||||
$this->assertSame('://builds.piwik.org/piwik-2.15.0-b5.zip', $this->channel->getDownloadUrlWithoutScheme('2.15.0-b5'));
|
||||
}
|
||||
|
||||
public function test_getUrlToCheckForLatestAvailableVersion()
|
||||
{
|
||||
$version = Version::VERSION;
|
||||
$phpVersion = urlencode(PHP_VERSION);
|
||||
$url = urlencode(Url::getCurrentUrlWithoutQueryString());
|
||||
|
||||
$urlToCheck = $this->channel->getUrlToCheckForLatestAvailableVersion();
|
||||
|
||||
$this->assertStringStartsWith("http://api.piwik.org/1.0/getLatestVersion/?piwik_version=$version&php_version=$phpVersion&release_channel=my_channel&url=$url&trigger=&timezone=", $urlToCheck);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,146 @@
|
|||
<?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\Plugins\CoreUpdater\Test;
|
||||
|
||||
use Piwik\Config;
|
||||
use Piwik\Option;
|
||||
use Piwik\Plugins\CoreUpdater\UpdateCommunication;
|
||||
use Piwik\Tests\Framework\Fixture;
|
||||
use Piwik\UpdateCheck;
|
||||
use Piwik\Version;
|
||||
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
|
||||
|
||||
/**
|
||||
* @group Plugins
|
||||
*/
|
||||
class UpdateCommunicationTest extends IntegrationTestCase
|
||||
{
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function test_isEnabled()
|
||||
{
|
||||
$updateCommunication = new UpdateCommunication();
|
||||
|
||||
$this->assertTrue($updateCommunication->isEnabled());
|
||||
|
||||
Config::getInstance()->General['enable_update_communication'] = 0;
|
||||
$this->assertFalse($updateCommunication->isEnabled());
|
||||
|
||||
Config::getInstance()->General['enable_update_communication'] = 1;
|
||||
$this->assertTrue($updateCommunication->isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideSendNotificationData
|
||||
*/
|
||||
public function test_sendNotificationIfUpdateAvailable($latestVersion, $lastSentVersion, $expects, $expectedLastSentVersion)
|
||||
{
|
||||
$this->setLatestVersion($latestVersion);
|
||||
$this->setLastSentVersion($lastSentVersion);
|
||||
|
||||
$mock = $this->getCommunicationMock(array('sendNotifications'));
|
||||
$mock->expects($expects)->method('sendNotifications');
|
||||
$mock->sendNotificationIfUpdateAvailable();
|
||||
|
||||
$this->assertEquals($expectedLastSentVersion, $this->getLastSentVersion());
|
||||
}
|
||||
|
||||
public function provideSendNotificationData()
|
||||
{
|
||||
return array(
|
||||
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-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
|
||||
);
|
||||
}
|
||||
|
||||
public function test_sendNotifications_shouldSentCorrectEmail()
|
||||
{
|
||||
$rootUrl = Fixture::getTestRootUrl();
|
||||
$message = "ScheduledReports_EmailHello
|
||||
|
||||
CoreUpdater_ThereIsNewVersionAvailableForUpdate
|
||||
|
||||
CoreUpdater_YouCanUpgradeAutomaticallyOrDownloadPackage
|
||||
{$rootUrl}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()
|
||||
{
|
||||
$rootUrl = Fixture::getTestRootUrl();
|
||||
$message = "ScheduledReports_EmailHello
|
||||
|
||||
CoreUpdater_ThereIsNewVersionAvailableForUpdate
|
||||
|
||||
CoreUpdater_YouCanUpgradeAutomaticallyOrDownloadPackage
|
||||
{$rootUrl}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($expectedMessage));
|
||||
$mock->sendNotificationIfUpdateAvailable();
|
||||
}
|
||||
|
||||
private function setLastSentVersion($value)
|
||||
{
|
||||
Option::set('last_update_communication_sent_core', $value);
|
||||
}
|
||||
|
||||
private function getLastSentVersion()
|
||||
{
|
||||
return Option::get('last_update_communication_sent_core');
|
||||
}
|
||||
|
||||
private function setLatestVersion($value)
|
||||
{
|
||||
$this->preventVersionIsOverwrittenByActualVersionCheck();
|
||||
Option::set(UpdateCheck::LATEST_VERSION, $value);
|
||||
}
|
||||
|
||||
private function preventVersionIsOverwrittenByActualVersionCheck()
|
||||
{
|
||||
Config::getInstance()->General['enable_auto_update'] = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $methodsToOverwrite
|
||||
* @return UpdateCommunication
|
||||
*/
|
||||
private function getCommunicationMock($methodsToOverwrite)
|
||||
{
|
||||
return $this->getMock('\Piwik\Plugins\CoreUpdater\UpdateCommunication', $methodsToOverwrite);
|
||||
}
|
||||
}
|
||||
59
www/analytics/plugins/CoreUpdater/Test/Mock/UpdaterMock.php
Normal file
59
www/analytics/plugins/CoreUpdater/Test/Mock/UpdaterMock.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?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\Plugins\CoreUpdater\Test\Mock;
|
||||
|
||||
use Piwik\Plugins\CoreUpdater\ArchiveDownloadException;
|
||||
use Piwik\Plugins\CoreUpdater\Updater;
|
||||
use Piwik\Translation\Translator;
|
||||
|
||||
class UpdaterMock extends Updater
|
||||
{
|
||||
/**
|
||||
* @var Translator
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
public function __construct(Translator $translator)
|
||||
{
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function getLatestVersion()
|
||||
{
|
||||
return '4.0.0';
|
||||
}
|
||||
|
||||
public function isNewVersionAvailable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getArchiveUrl($version, $https = true)
|
||||
{
|
||||
return 'http://builds.piwik.org/piwik.zip';
|
||||
}
|
||||
|
||||
public function updatePiwik($https = true)
|
||||
{
|
||||
// Simulate that the update over HTTPS fails
|
||||
if ($https) {
|
||||
// The actual error message depends on the OS, the HTTP method etc.
|
||||
// This is what I get on my machine, but it doesn't really matter
|
||||
throw new ArchiveDownloadException(new \Exception('curl_exec: SSL certificate problem: Invalid certificate chain. Hostname requested was: piwik.org'), array());
|
||||
}
|
||||
|
||||
// Simulate that the update over HTTP succeeds
|
||||
return array(
|
||||
$this->translator->translate('CoreUpdater_DownloadingUpdateFromX', ''),
|
||||
$this->translator->translate('CoreUpdater_UnpackingTheUpdate'),
|
||||
$this->translator->translate('CoreUpdater_VerifyingUnpackedFiles'),
|
||||
$this->translator->translate('CoreUpdater_InstallingTheLatestVersion'),
|
||||
);
|
||||
}
|
||||
}
|
||||
61
www/analytics/plugins/CoreUpdater/Test/Unit/ModelTest.php
Normal file
61
www/analytics/plugins/CoreUpdater/Test/Unit/ModelTest.php
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
<?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\Plugins\CoreUpdater\Test\Unit;
|
||||
|
||||
use Piwik\Plugins\CoreUpdater\Model;
|
||||
|
||||
/**
|
||||
* @group CoreUpdater
|
||||
* @group ModelTest
|
||||
* @group Unit
|
||||
* @group Plugins
|
||||
*/
|
||||
class ModelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var Model
|
||||
*/
|
||||
private $model;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->model = new Model();
|
||||
}
|
||||
|
||||
public function test_getPluginsFromDirectoy_shouldReturnEmptyArray_IfNoPluginsExist()
|
||||
{
|
||||
$plugins = $this->model->getPluginsFromDirectoy(PIWIK_INCLUDE_PATH . '/config');
|
||||
|
||||
$this->assertEquals(array(), $plugins);
|
||||
}
|
||||
|
||||
public function test_getPluginsFromDirectoy_shouldReturnAllDirectoriesWithinPlugins()
|
||||
{
|
||||
$plugins = $this->model->getPluginsFromDirectoy(PIWIK_INCLUDE_PATH);
|
||||
|
||||
$this->assertGreaterThan(40, count($plugins));
|
||||
$this->assertContains('/plugins/API', $plugins);
|
||||
$this->assertContains('/plugins/Actions', $plugins);
|
||||
$this->assertContains('/plugins/Annotations', $plugins);
|
||||
|
||||
$this->assertNotContains('/plugins/.', $plugins);
|
||||
$this->assertNotContains('/plugins/..', $plugins);
|
||||
$this->assertNotContains('/plugins', $plugins);
|
||||
$this->assertNotContains('/plugins/', $plugins);
|
||||
|
||||
foreach ($plugins as $plugin) {
|
||||
$this->assertTrue(is_dir(PIWIK_INCLUDE_PATH . $plugin));
|
||||
$this->assertStringStartsWith('/plugins/', $plugin);
|
||||
$this->assertTrue(12 <= strlen($plugin)); // make sure it does not return something like '/plugins'.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue