|
@@ 22-70 (lines=49) @@
|
| 19 |
|
class ProductTest extends TestBase |
| 20 |
|
{ |
| 21 |
|
|
| 22 |
|
public function testCreate() |
| 23 |
|
{ |
| 24 |
|
|
| 25 |
|
$image = new Image($this->config->appId,$this->config->appSecret); |
| 26 |
|
$images = $image->upload(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Image'.DIRECTORY_SEPARATOR.'aa.jpg'); |
| 27 |
|
|
| 28 |
|
$product = new Product($this->http); |
| 29 |
|
$response = $product->create(function(ProductData $product) use ($images) { |
| 30 |
|
|
| 31 |
|
|
| 32 |
|
$product->setBaseAttr($images,array($images,$images),null,'商品名',536891949) |
| 33 |
|
->setDetail('text','text') |
| 34 |
|
->setDetail('img',$images); |
| 35 |
|
|
| 36 |
|
$testData = Yaml::parse(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'Data.yml')); |
| 37 |
|
|
| 38 |
|
foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetProperty'] as $value) { |
| 39 |
|
$product->setProperty($value['id'],$value['property_value'][0]['id']); |
| 40 |
|
} |
| 41 |
|
|
| 42 |
|
foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetSku'] as $value) { |
| 43 |
|
foreach ($value['value_list'] as $key => $valueList) { |
| 44 |
|
//此判断仅是为了 让子序列少点,实际程序按照自身的逻辑来 |
| 45 |
|
if ($key % 5 == 0 && $key % 2 == 0) { |
| 46 |
|
$skuList[] = $valueList['id']; |
| 47 |
|
} |
| 48 |
|
|
| 49 |
|
} |
| 50 |
|
$skuInfo[] = array('id'=>$value['id'],'vid'=>$skuList); |
| 51 |
|
$product->setSkuInfo($value['id'],$skuList); |
| 52 |
|
} |
| 53 |
|
|
| 54 |
|
foreach ($skuInfo[0]['vid'] as $vid) { |
| 55 |
|
foreach ($skuInfo[1]['vid'] as $vid1) { |
| 56 |
|
$product->setSkuList(100, 20, $images, 100, array(array($skuInfo[0]['id'], $vid), array($skuInfo[1]['id'], $vid1))); |
| 57 |
|
} |
| 58 |
|
} |
| 59 |
|
|
| 60 |
|
$product->setAttrext(0,1,1,1) |
| 61 |
|
->setLocation('浙江省','杭州市','滨江区阿里园') |
| 62 |
|
->setDeliveryInfo(1,'400184224'); |
| 63 |
|
|
| 64 |
|
return $product; |
| 65 |
|
}); |
| 66 |
|
|
| 67 |
|
$this->assertTrue(is_string($response)); |
| 68 |
|
|
| 69 |
|
return $response; |
| 70 |
|
} |
| 71 |
|
|
| 72 |
|
/** |
| 73 |
|
* @depends testCreate |
|
@@ 75-122 (lines=48) @@
|
| 72 |
|
/** |
| 73 |
|
* @depends testCreate |
| 74 |
|
*/ |
| 75 |
|
public function testUpdate($productId) |
| 76 |
|
{ |
| 77 |
|
$image = new Image($this->config->appId,$this->config->appSecret); |
| 78 |
|
$images = $image->upload(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Image'.DIRECTORY_SEPARATOR.'aa.jpg'); |
| 79 |
|
|
| 80 |
|
//未上架的 |
| 81 |
|
$product = new Product($this->http); |
| 82 |
|
$response = $product->update(function(ProductData $product) use ($images) { |
| 83 |
|
|
| 84 |
|
$product->setBaseAttr($images,array($images,$images),null,'商品名',536891949) |
| 85 |
|
->setDetail('text','text') |
| 86 |
|
->setDetail('img',$images); |
| 87 |
|
|
| 88 |
|
$testData = Yaml::parse(file_get_contents(__DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Config'.DIRECTORY_SEPARATOR.'Data.yml')); |
| 89 |
|
|
| 90 |
|
foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetProperty'] as $value) { |
| 91 |
|
$product->setProperty($value['id'],$value['property_value'][0]['id']); |
| 92 |
|
} |
| 93 |
|
|
| 94 |
|
foreach ($testData['Overtrue\Wechat\Test\Shop\ProductTest']['testGetSku'] as $value) { |
| 95 |
|
foreach ($value['value_list'] as $key => $valueList) { |
| 96 |
|
//此判断仅是为了 让子序列少点,实际程序按照自身的逻辑来 |
| 97 |
|
if ($key % 5 == 0 && $key % 2 == 0) { |
| 98 |
|
$skuList[] = $valueList['id']; |
| 99 |
|
} |
| 100 |
|
|
| 101 |
|
} |
| 102 |
|
$skuInfo[] = array('id'=>$value['id'],'vid'=>$skuList); |
| 103 |
|
$product->setSkuInfo($value['id'],$skuList); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
foreach ($skuInfo[0]['vid'] as $vid) { |
| 107 |
|
foreach ($skuInfo[1]['vid'] as $vid1) { |
| 108 |
|
$product->setSkuList(100, 20, $images, 100, array(array($skuInfo[0]['id'], $vid), array($skuInfo[1]['id'], $vid1))); |
| 109 |
|
} |
| 110 |
|
} |
| 111 |
|
|
| 112 |
|
$product->setAttrext(0,1,1,1) |
| 113 |
|
->setLocation('浙江省','杭州市','滨江区阿里园') |
| 114 |
|
->setDeliveryInfo(1,'400184224'); |
| 115 |
|
|
| 116 |
|
return $product; |
| 117 |
|
|
| 118 |
|
},$productId); |
| 119 |
|
|
| 120 |
|
$this->assertTrue(is_string($response)); |
| 121 |
|
|
| 122 |
|
} |
| 123 |
|
|
| 124 |
|
/** |
| 125 |
|
* @depends testCreate |