-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Plus Module Sources management to current process and add tests
- Loading branch information
1 parent
84eea40
commit 49f3ea9
Showing
10 changed files
with
172 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
tests/unit/UpgradeTools/Module/ModuleDownloaderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
/** | ||
* Copyright since 2007 PrestaShop SA and Contributors | ||
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This source file is subject to the Academic Free License 3.0 (AFL-3.0) | ||
* that is bundled with this package in the file LICENSE.md. | ||
* It is also available through the world-wide-web at this URL: | ||
* https://opensource.org/licenses/AFL-3.0 | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer | ||
* versions in the future. If you wish to customize PrestaShop for your | ||
* needs please refer to https://devdocs.prestashop.com/ for more information. | ||
* | ||
* @author PrestaShop SA and Contributors <[email protected]> | ||
* @copyright Since 2007 PrestaShop SA and Contributors | ||
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0) | ||
*/ | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use PrestaShop\Module\AutoUpgrade\Log\Logger; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\ModuleDownloader; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\ModuleDownloaderContext; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSource; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Module\Source\ModuleSourceAggregate; | ||
use PrestaShop\Module\AutoUpgrade\UpgradeTools\Translator; | ||
|
||
class ModuleDownloaderTest extends TestCase | ||
{ | ||
/** @var ModuleDownloader */ | ||
private $moduleDownloader; | ||
|
||
/** @var PHPUnit_Framework_MockObject_MockObject|Logger|(Logger&PHPUnit_Framework_MockObject_MockObject) */ | ||
private $logger; | ||
|
||
public static function setUpBeforeClass() | ||
{ | ||
require_once __DIR__ . '/Source/Provider/ModuleSourceProviderMock.php'; | ||
@mkdir(sys_get_temp_dir() . '/fakeDownloaderDestination'); | ||
} | ||
|
||
protected function setUp() | ||
{ | ||
$translator = $this->createMock(Translator::class); | ||
$translator->method('trans') | ||
->willReturnCallback(function ($message, $parameters = []) { | ||
return vsprintf($message, $parameters); | ||
}); | ||
|
||
$this->logger = $this->createMock(Logger::class); | ||
$this->moduleDownloader = new ModuleDownloader($translator, $this->logger); | ||
} | ||
|
||
public function testModuleDownloaderSucceedsOnFirstTryWithLocalFile() | ||
{ | ||
$moduleContext = new ModuleDownloaderContext(sys_get_temp_dir() . '/fakeDownloaderDestination', ['name' => 'mymodule', 'currentVersion' => '1.0.0']); | ||
|
||
$dummyProvider1 = (new ModuleSourceProviderMock())->setSources([ | ||
new ModuleSource('mymodule', '2.0.0', realpath(__DIR__ . '/../../../fixtures/mymodule'), false), | ||
]); | ||
$moduleSourceList = new ModuleSourceAggregate([$dummyProvider1]); | ||
|
||
$moduleSourceList->setSourcesIn($moduleContext); | ||
|
||
$this->logger->expects($this->once()) | ||
->method('notice') | ||
->with('Module mymodule has been successfully downloaded.'); | ||
|
||
$this->moduleDownloader->downloadModule($moduleContext); | ||
} | ||
|
||
public function testModuleDownloaderSucceedsOnFirstTryWithRemoteFile() | ||
{ | ||
} | ||
|
||
public function testModuleDownloaderFails() | ||
{ | ||
$moduleContext = new ModuleDownloaderContext(sys_get_temp_dir() . '/fakeDownloaderDestination', ['name' => 'mymodule', 'currentVersion' => '1.0.0']); | ||
|
||
$dummyProvider1 = (new ModuleSourceProviderMock())->setSources([ | ||
new ModuleSource('mymodule', '2.0.0', realpath(__DIR__ . '/../../../fixtures/mymodule'), false), | ||
]); | ||
$moduleSourceList = new ModuleSourceAggregate([$dummyProvider1]); | ||
|
||
$moduleSourceList->setSourcesIn($moduleContext); | ||
|
||
$this->logger->expects($this->once()) | ||
->method('debug') | ||
->with('Download of source #1 has failed. %s'); | ||
$this->logger->expects($this->once()) | ||
->method('warning') | ||
->with('All download attempts have failed. Check your environment and try again.'); | ||
|
||
$this->moduleDownloader->downloadModule($moduleContext); | ||
} | ||
|
||
public function testModuleDownloaderHandlesFallbacks() | ||
{ | ||
} | ||
|
||
public function testDetectionOfXmlFileInDownloadedContents() | ||
{ | ||
} | ||
} |
Oops, something went wrong.