public testEditWithPostTaxRate ( $before, $after, $expected ) | ||
$before | 更新前の税率 | |
$after | POST値 | |
$expected | 期待値 |
public function testEditWithPostTaxRate($before, $after, $expected)
{
// Give
$BaseInfo = $this->app['eccube.repository.base_info']->get();
$BaseInfo->setOptionProductTaxRule(Constant::ENABLED);
$Product = $this->createProduct(null, 0);
$ProductClasses = $Product->getProductClasses();
$ProductClass = $ProductClasses[0];
$formData = $this->createFormData();
if (!is_null($after)) {
$formData['class']['tax_rate'] = $after;
}
if (!is_null($before)) {
$DefaultTaxRule = $this->app['eccube.repository.tax_rule']->find(\Eccube\Entity\TaxRule::DEFAULT_TAX_RULE_ID);
$TaxRule = new TaxRule();
$TaxRule->setProductClass($ProductClass)->setCreator($Product->getCreator())->setProduct($Product)->setCalcRule($DefaultTaxRule->getCalcRule())->setTaxRate($before)->setTaxAdjust(0)->setApplyDate(new \DateTime())->setDelFlg(Constant::DISABLED);
$ProductClass->setTaxRule($TaxRule);
$this->app['orm.em']->persist($TaxRule);
$this->app['orm.em']->flush();
}
// When
$this->client->request('POST', $this->app->url('admin_product_product_edit', array('id' => $Product->getId())), array('admin_product' => $formData));
// Then
$this->assertTrue($this->client->getResponse()->isRedirect($this->app->url('admin_product_product_edit', array('id' => $Product->getId()))));
$this->expected = $expected;
$TaxRule = $this->app['eccube.repository.tax_rule']->findOneBy(array('Product' => $Product, 'ProductClass' => $ProductClass));
if (is_null($TaxRule)) {
$this->actual = null;
} else {
$this->actual = $TaxRule->getTaxRate();
}
$this->assertTrue($this->actual === $this->expected);
}