Skip to content

Commit

Permalink
テストコードを修正・追加
Browse files Browse the repository at this point in the history
  • Loading branch information
takeuji committed Sep 29, 2023
1 parent 2e49418 commit 53f6618
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 17 deletions.
15 changes: 0 additions & 15 deletions tests/Eccube/Tests/Entity/OrderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,6 @@ public function testGetTotalByTaxRate()
{
$Order = $this->createTestOrder();

self::assertSame(790187, $this->getTaxableTotal(), '課税合計');
self::assertSame(65160.0, $Order->getTotalByTaxRate()[8], '8%対象値引き後合計');
self::assertSame(717868.0, $Order->getTotalByTaxRate()[10], '10%対象値引き後合計');
}
Expand Down Expand Up @@ -302,18 +301,4 @@ protected function getOrderItemData()

return $data;
}

protected function getTaxableTotal()
{
$data = $this->getOrderItemData();
$Taxation = $this->entityManager->find(TaxType::class, TaxType::TAXATION);
$TaxExcluded = $this->entityManager->find(TaxDisplayType::class, TaxDisplayType::EXCLUDED);
$taxableItem = array_filter($data, function ($item) use ($Taxation) {
return $item[0] === $Taxation;
});

return array_reduce($taxableItem, function ($sum, $item) use ($TaxExcluded) {
return $sum + ($item[2] + $item[6] !== $TaxExcluded ? $item[3] : 0) * $item[4];
});
}
}
15 changes: 14 additions & 1 deletion tests/Eccube/Tests/Fixture/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ public function createOrder(Customer $Customer, array $ProductClasses = [], Deli
$ItemDeliveryFee = $this->entityManager->find(OrderItemType::class, OrderItemType::DELIVERY_FEE);
$ItemCharge = $this->entityManager->find(OrderItemType::class, OrderItemType::CHARGE);
$ItemDiscount = $this->entityManager->find(OrderItemType::class, OrderItemType::DISCOUNT);
$ItemPoint = $this->entityManager->find(OrderItemType::class, OrderItemType::POINT);
$BaseInfo = $this->entityManager->getRepository(BaseInfo::class)->get();

/** @var ProductClass $ProductClass */
Expand Down Expand Up @@ -727,6 +728,19 @@ public function createOrder(Customer $Customer, array $ProductClasses = [], Deli
// $Shipping->addOrderItem($OrderItemDiscount); // Shipping には登録しない
$Order->addOrderItem($OrderItemDiscount);

if (($point = mt_rand(0, min($Customer->getPoint(), $Order->getPaymentTotal()))) > 0) {
$OrderItemPoint = new OrderItem();
$OrderItemPoint
->setOrder($Order)
->setProductName('ポイント')
->setPrice($point * -1)
->setQuantity(1)
->setTaxType($NonTaxable)
->setTaxDisplayType($TaxInclude)
->setOrderItemType($ItemPoint);
$Order->addOrderItem($OrderItemPoint);
}

$this->orderPurchaseFlow->validate($Order, new PurchaseContext($Order));

$this->entityManager->flush();
Expand Down Expand Up @@ -900,7 +914,6 @@ public function createLoginHistory($user_name, $client_ip = null, $status = null
* Faker を生成する.
*
* @return \Faker\Generator
*
*/
protected function getFaker()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,16 @@ public function testSort()
{
shuffle($this->Items);

$this->expected = [1 => '商品', 2 => '送料', 3 => '手数料', 4 => '割引'];
$this->expected = [1 => '商品', 2 => '送料', 3 => '手数料'];
$this->actual = [];
$Items = (new ItemCollection($this->Items))->sort();
foreach ($Items as $Item) {
$this->actual[$Item->getOrderItemType()->getId()] = $Item->getOrderItemType()->getName();
}
if (array_key_exists(6, $this->actual)) {
$this->expected[6] = 'ポイント';
}
$this->expected[4] = '割引';

$this->verify();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* This file is part of EC-CUBE
*
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
*
* http://www.ec-cube.co.jp/
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Eccube\Tests\Service\PurchaseFlow\Processor;

use Eccube\Entity\Cart;
use Eccube\Service\PurchaseFlow\Processor\PaymentTotalNegativeValidator;
use Eccube\Service\PurchaseFlow\PurchaseContext;
use Eccube\Tests\EccubeTestCase;

class PaymentTotalNegativeValidatorTest extends EccubeTestCase
{
public function testPositiveValidate()
{
$validator = $this->newValidator();

$cart = new Cart();
$cart->setTotal(100);

$result = $validator->execute($cart, new PurchaseContext());
self::assertTrue($result->isSuccess());
}

public function testNegativeValidate()
{
$validator = $this->newValidator();

$cart = new Cart();
$cart->setTotal(-100);

$result = $validator->execute($cart, new PurchaseContext());
self::assertTrue($result->isError());
}

/**
* @return PaymentTotalNegativeValidator
*/
private function newValidator()
{
return static::getContainer()->get(PaymentTotalNegativeValidator::class);
}
}

0 comments on commit 53f6618

Please sign in to comment.