Skip to content

Commit

Permalink
OrderDetails と ShipmentItems の整合性を考慮するよう修正
Browse files Browse the repository at this point in the history
  • Loading branch information
nanasess committed Sep 5, 2016
1 parent 6a5f5db commit 658f8ac
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 58 deletions.
105 changes: 55 additions & 50 deletions tests/Eccube/Tests/Web/Admin/Order/AbstractEditControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,66 @@ abstract class AbstractEditControllerTestCase extends AbstractAdminWebTestCase
* @param Product $Product
* @return array
*/
public function createFormData(Customer $Customer, Product $Product)
public function createFormData(Customer $Customer, Product $Product = null)
{
$ProductClasses = $Product->getProductClasses();
$faker = $this->getFaker();
$tel = explode('-', $faker->phoneNumber);

$email = $faker->safeEmail;
$delivery_date = $faker->dateTimeBetween('now', '+ 5 days');

$OrderDetails = array();
if (is_object($Product)) {
$ProductClasses = $Product->getProductClasses();
$OrderDetails[] = array(
'Product' => $Product->getId(),
'ProductClass' => $ProductClasses[0]->getId(),
'price' => $ProductClasses[0]->getPrice02(),
'quantity' => $faker->randomNumber(2),
'tax_rate' => 8 // XXX ハードコーディング
);
}

$Shippings = array(
array(
'name' => array(
'name01' => $faker->lastName,
'name02' => $faker->firstName,
),
'kana' => array(
'kana01' => $faker->lastKanaName,
'kana02' => $faker->firstKanaName,
),
'company_name' => $faker->company,
'zip' => array(
'zip01' => $faker->postcode1(),
'zip02' => $faker->postcode2(),
),
'address' => array(
'pref' => $faker->numberBetween(1, 47),
'addr01' => $faker->city,
'addr02' => $faker->streetAddress,
),
'tel' => array(
'tel01' => $tel[0],
'tel02' => $tel[1],
'tel03' => $tel[2],
),
'fax' => array(
'fax01' => $tel[0],
'fax02' => $tel[1],
'fax03' => $tel[2],
),
'Delivery' => 1, // XXX ハードコーディング
'DeliveryTime' => 1, // XXX ハードコーディング
'shipping_delivery_date' => array(
'year' => $delivery_date->format('Y'),
'month' => $delivery_date->format('n'),
'day' => $delivery_date->format('j')
)
)
);

$order = array(
'_token' => 'dummy',
'Customer' => $Customer->getId(),
Expand Down Expand Up @@ -71,54 +122,8 @@ public function createFormData(Customer $Customer, Product $Product)
'delivery_fee_total' => 0,
'charge' => 0,
'note' => $faker->text,
'OrderDetails' => array(
array(
'Product' => $Product->getId(),
'ProductClass' => $ProductClasses[0]->getId(),
'price' => $ProductClasses[0]->getPrice02(),
'quantity' => 1,
'tax_rate' => 8 // XXX ハードコーディング
)
),
'Shippings' => array(
array(
'name' => array(
'name01' => $faker->lastName,
'name02' => $faker->firstName,
),
'kana' => array(
'kana01' => $faker->lastKanaName,
'kana02' => $faker->firstKanaName,
),
'company_name' => $faker->company,
'zip' => array(
'zip01' => $faker->postcode1(),
'zip02' => $faker->postcode2(),
),
'address' => array(
'pref' => $faker->numberBetween(1, 47),
'addr01' => $faker->city,
'addr02' => $faker->streetAddress,
),
'tel' => array(
'tel01' => $tel[0],
'tel02' => $tel[1],
'tel03' => $tel[2],
),
'fax' => array(
'fax01' => $tel[0],
'fax02' => $tel[1],
'fax03' => $tel[2],
),
'Delivery' => 1, // XXX ハードコーディング
'DeliveryTime' => 1, // XXX ハードコーディング
'shipping_delivery_date' => array(
'year' => $delivery_date->format('Y'),
'month' => $delivery_date->format('n'),
'day' => $delivery_date->format('j')
)
)
)
'OrderDetails' => $OrderDetails,
'Shippings' => $Shippings
);
return $order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
use Eccube\Entity\Customer;
use Eccube\Entity\Product;

/**
* 複数配送設定用 EditController のテストケース.
*
* @author Kentaro Ohkouchi
*/
class EditControllerWithMultipleTest extends AbstractEditControllerTestCase
{
protected $Customer;
Expand Down Expand Up @@ -60,7 +65,7 @@ public function testRoutingAdminOrderNewPost()
'POST',
$this->app->url('admin_order_new'),
array(
'order' => $this->createFormData($this->Customer, $this->Product, $Shippings),
'order' => $this->createFormDataForMultiple($this->Customer, $Shippings),
'mode' => 'register'
)
);
Expand All @@ -85,7 +90,7 @@ public function testRoutingAdminOrderEditPost()
$Shippings[] = $this->createShipping($this->Product->getProductClasses()->toArray());
$Customer = $this->createCustomer();
$Order = $this->createOrder($Customer);
$formData = $this->createFormData($Customer, $this->Product, $Shippings);
$formData = $this->createFormDataForMultiple($Customer, $Shippings);
$this->client->request(
'POST',
$this->app->url('admin_order_edit', array('id' => $Order->getId())),
Expand Down Expand Up @@ -172,7 +177,12 @@ public function testOrderProcessingToFrontConfirm()
{
$Customer = $this->createCustomer();
$Order = $this->createOrder($Customer);
$formData = $this->createFormData($Customer, $this->Product);

$Shippings = array();
$Shippings[] = $this->createShipping($this->Product->getProductClasses()->toArray());
$Shippings[] = $this->createShipping($this->Product->getProductClasses()->toArray());

$formData = $this->createFormDataForMultiple($Customer, $Shippings);
$formData['OrderStatus'] = 8; // 購入処理中で受注を登録する
// 管理画面から受注登録
$this->client->request(
Expand Down Expand Up @@ -265,9 +275,13 @@ public function testOrderProcessingToFrontConfirm()
public function testOrderProcessingWithTax()
{

$Shippings = array();
$Shippings[] = $this->createShipping($this->Product->getProductClasses()->toArray());
$Shippings[] = $this->createShipping($this->Product->getProductClasses()->toArray());

$Customer = $this->createCustomer();
$Order = $this->createOrder($Customer);
$formData = $this->createFormData($Customer, $this->Product);
$formData = $this->createFormDataForMultiple($Customer, $Shippings);
// 管理画面から受注登録
$this->client->request(
'POST', $this->app->url('admin_order_edit', array('id' => $Order->getId())), array(
Expand Down Expand Up @@ -308,17 +322,34 @@ public function testOrderProcessingWithTax()
/**
* 複数配送用受注編集用フォーム作成.
*
* FIXME Order と Shippings の整合性を合わせる必要がある
* createFormData() との違いは、 $Shipping[N]['ShipmentItems'] がフォームに追加されている.
* OrderDetails は、 $Shippings[N]['ShipmentItems] から生成される.
*
* @param Customer $Customer
* @param Product $Product
* @param array $Shippings お届け先情報の配列
* @return array
*/
public function createFormData(Customer $Customer, Product $Product, array $Shippings = array())
public function createFormDataForMultiple(Customer $Customer, array $Shippings)
{
$formData = parent::createFormData($Customer, $Product);
$formData = parent::createFormData($Customer, null);
$formData['Shippings'] = $Shippings;
$OrderDetails = array();
foreach ($Shippings as $Shipping) {
foreach ($Shipping['ShipmentItems'] as $Item) {
if (empty($OrderDetails[$Item['ProductClass']])) {
$OrderDetails[$Item['ProductClass']] = array(
'Product' => $Item['Product'],
'ProductClass' => $Item['ProductClass'],
'price' => $Item['price'],
'quantity' => $Item['quantity'],
'tax_rate' => 8 // XXX ハードコーディング
);
} else {
$OrderDetails[$Item['ProductClass']]['quantity'] += $Item['quantity'];
}
}
}
$formData['OrderDetails'] = array_values($OrderDetails);
return $formData;
}

Expand Down

0 comments on commit 658f8ac

Please sign in to comment.