* Refactor upgradeModel::getVersionsToUpdate, and add its unit test.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* The model file of upgrade module of ZenTaoPMS.
|
||||
*
|
||||
@@ -33,14 +34,15 @@ class upgradeModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* Get versions to update
|
||||
* 获取升级的版本。
|
||||
* Get versions to update.
|
||||
*
|
||||
* @param mixed $openVersion
|
||||
* @param string $fromEdition open|pro|biz|max
|
||||
* @param string $fromEdition open|pro|biz|max|ipd
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getVersionsToUpdate($openVersion, $fromEdition)
|
||||
public function getVersionsToUpdate(string $openVersion, string $fromEdition): array
|
||||
{
|
||||
$versions = array();
|
||||
|
||||
@@ -53,25 +55,26 @@ class upgradeModel extends model
|
||||
}
|
||||
if($fromEdition == 'open') return $versions;
|
||||
|
||||
/* Update pro sql from pro|biz|max. */
|
||||
/* Update pro sql from pro|biz|max|ipd. */
|
||||
foreach($this->config->upgrade->proVersion as $pro => $open)
|
||||
{
|
||||
if(isset($versions[$open])) $versions[$open]['pro'][] = $pro;
|
||||
}
|
||||
if($fromEdition == 'pro') return $versions;
|
||||
|
||||
/* Update biz sql from biz|max. */
|
||||
/* Update biz sql from biz|max|ipd. */
|
||||
foreach($this->config->upgrade->bizVersion as $biz => $open)
|
||||
{
|
||||
if(isset($versions[$open])) $versions[$open]['biz'][] = $biz;
|
||||
}
|
||||
if($fromEdition == 'biz') return $versions;
|
||||
|
||||
/* Update max sql only from max. */
|
||||
/* Update max sql from max|ipd. */
|
||||
foreach($this->config->upgrade->maxVersion as $max => $open)
|
||||
{
|
||||
if(isset($versions[$open])) $versions[$open]['max'][] = $max;
|
||||
}
|
||||
if($fromEdition == 'max') return $versions;
|
||||
|
||||
/* Update ipd sql only from ipd. */
|
||||
foreach($this->config->upgrade->ipdVersion as $ipd => $open)
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
|
||||
title=测试 upgradeModel->getVersionsToUpdate();
|
||||
cid=1
|
||||
|
||||
- 测试获取开源版版本 18_8 来源版本 open 的升级版本 @pro:0;biz:0;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 pro 的升级版本 @pro:pro8_7;biz:0;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 biz 的升级版本 @pro:pro8_7;biz:biz3_6;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 max 的升级版本 @pro:pro8_7;biz:biz3_6;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 ipd 的升级版本 @pro:pro8_7;biz:biz3_6;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 open 的升级版本 @pro:0;biz:0;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 pro 的升级版本 @pro:0;biz:0;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 biz 的升级版本 @pro:0;biz:biz8_9;max:0;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 max 的升级版本 @pro:0;biz:biz8_9;max:max4_9;ipd:0
|
||||
- 测试获取开源版版本 18_8 来源版本 ipd 的升级版本 @pro:0;biz:biz8_9;max:max4_9;ipd:ipd1_1_1
|
||||
|
||||
**/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/upgrade.class.php';
|
||||
|
||||
zdTable('user')->config('user')->gen(5);
|
||||
|
||||
su('admin');
|
||||
|
||||
$openVersion = array('12_0', '18_9');
|
||||
$fromEdition = array('open', 'pro', 'biz', 'max', 'ipd');
|
||||
|
||||
$upgrade = new upgradeTest();
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[0], $fromEdition[0])) && p() && e('pro:0;biz:0;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 open 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[0], $fromEdition[1])) && p() && e('pro:pro8_7;biz:0;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 pro 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[0], $fromEdition[2])) && p() && e('pro:pro8_7;biz:biz3_6;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 biz 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[0], $fromEdition[3])) && p() && e('pro:pro8_7;biz:biz3_6;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 max 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[0], $fromEdition[4])) && p() && e('pro:pro8_7;biz:biz3_6;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 ipd 的升级版本
|
||||
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[1], $fromEdition[0])) && p() && e('pro:0;biz:0;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 open 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[1], $fromEdition[1])) && p() && e('pro:0;biz:0;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 pro 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[1], $fromEdition[2])) && p() && e('pro:0;biz:biz8_9;max:0;ipd:0'); // 测试获取开源版版本 18_8 来源版本 biz 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[1], $fromEdition[3])) && p() && e('pro:0;biz:biz8_9;max:max4_9;ipd:0'); // 测试获取开源版版本 18_8 来源版本 max 的升级版本
|
||||
r($upgrade->getVersionsToUpdateTest($openVersion[1], $fromEdition[4])) && p() && e('pro:0;biz:biz8_9;max:max4_9;ipd:ipd1_1_1'); // 测试获取开源版版本 18_8 来源版本 ipd 的升级版本
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
class upgradeTest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $tester;
|
||||
$this->objectModel = $tester->loadModel('upgrade');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试获取升级版本。
|
||||
* Test get update version.
|
||||
*
|
||||
* @param string $openVersion
|
||||
* @param string $fromEdition
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function getVersionsToUpdateTest(string $openVersion, string $fromEdition): string
|
||||
{
|
||||
$versions = $this->objectModel->getVersionsToUpdate($openVersion, $fromEdition);
|
||||
$return = '';
|
||||
foreach($versions[$openVersion] as $edition => $version)
|
||||
{
|
||||
if(!isset($version[0])) $version[0] = '0';
|
||||
$return .="{$edition}:{$version[0]};";
|
||||
}
|
||||
return trim($return, ';');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user