| 1 | <?php |
||||||
| 2 | |||||||
| 3 | namespace Dynamic\Foxy\Discounts\Tests\Extension; |
||||||
| 4 | |||||||
| 5 | use Dynamic\Foxy\API\Client\APIClient; |
||||||
|
0 ignored issues
–
show
|
|||||||
| 6 | use Dynamic\Foxy\Discounts\DiscountHelper; |
||||||
| 7 | use Dynamic\Foxy\Discounts\Extension\PageControllerExtension; |
||||||
| 8 | use Dynamic\Foxy\Discounts\Extension\ProductDataExtension; |
||||||
| 9 | use Dynamic\Foxy\Discounts\Model\Discount; |
||||||
| 10 | use Dynamic\Foxy\Discounts\Tests\TestOnly\Extension\TestDiscountExtension; |
||||||
| 11 | use Dynamic\Foxy\Discounts\Tests\TestOnly\Extension\VariationDataExtension; |
||||||
| 12 | use Dynamic\Foxy\Discounts\Tests\TestOnly\Page\ProductPage; |
||||||
| 13 | use Dynamic\Foxy\Discounts\Tests\TestOnly\Page\ProductPageController; |
||||||
| 14 | use Dynamic\Foxy\Extension\Purchasable; |
||||||
| 15 | use Dynamic\Foxy\Extension\PurchasableExtension; |
||||||
| 16 | use Dynamic\Foxy\Form\AddToCartForm; |
||||||
| 17 | use Dynamic\Foxy\Model\Variation; |
||||||
| 18 | use SilverStripe\Core\Config\Config; |
||||||
| 19 | use SilverStripe\Dev\FunctionalTest; |
||||||
| 20 | use SilverStripe\Forms\HiddenField; |
||||||
| 21 | use SilverStripe\Versioned\Versioned; |
||||||
| 22 | |||||||
| 23 | /** |
||||||
| 24 | * Class AddToCartFormTest |
||||||
| 25 | * @package Dynamic\Foxy\Discounts\Tests\Extension |
||||||
| 26 | */ |
||||||
| 27 | class AddToCartFormTest extends FunctionalTest |
||||||
| 28 | { |
||||||
| 29 | /** |
||||||
| 30 | * @var string[] |
||||||
| 31 | */ |
||||||
| 32 | protected static $fixture_file = [ |
||||||
| 33 | '../products.yml', |
||||||
| 34 | '../discounts.yml', |
||||||
| 35 | ]; |
||||||
| 36 | |||||||
| 37 | /** |
||||||
| 38 | * @var string[] |
||||||
| 39 | */ |
||||||
| 40 | protected static $extra_dataobjects = [ |
||||||
| 41 | ProductPage::class, |
||||||
| 42 | ]; |
||||||
| 43 | |||||||
| 44 | /** |
||||||
| 45 | * @var \string[][] |
||||||
| 46 | */ |
||||||
| 47 | protected static $required_extensions = [ |
||||||
| 48 | ProductPage::class => [ |
||||||
| 49 | Purchasable::class, |
||||||
| 50 | ProductDataExtension::class, |
||||||
| 51 | ], |
||||||
| 52 | Discount::class => [ |
||||||
| 53 | TestDiscountExtension::class, |
||||||
| 54 | ], |
||||||
| 55 | Variation::class => [ |
||||||
| 56 | VariationDataExtension::class, |
||||||
| 57 | ], |
||||||
| 58 | ProductPageController::class => [ |
||||||
| 59 | PageControllerExtension::class, |
||||||
| 60 | PurchasableExtension::class, |
||||||
| 61 | ], |
||||||
| 62 | ]; |
||||||
| 63 | |||||||
| 64 | /** |
||||||
| 65 | * @var string[] |
||||||
| 66 | */ |
||||||
| 67 | protected static $illegal_extensions = [ |
||||||
| 68 | /*Discount::class => [ |
||||||
| 69 | 'Dynamic\\FoxyRecipe\\Extension\\DiscountDataExtension', |
||||||
| 70 | ],//*/ |
||||||
| 71 | ]; |
||||||
| 72 | |||||||
| 73 | /** |
||||||
| 74 | * |
||||||
| 75 | */ |
||||||
| 76 | protected function setUp() |
||||||
| 77 | { |
||||||
| 78 | if (class_exists('Dynamic\\Foxy\\API\\Client\\APIClient')) { |
||||||
| 79 | Config::modify()->set('Dynamic\\Foxy\\API\\Client\\APIClient', 'enable_api', false); |
||||||
| 80 | } |
||||||
| 81 | if (class_exists('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient')) { |
||||||
| 82 | Config::modify()->set('Dynamic\\Foxy\\SingleSignOn\\Client\\CustomerClient', 'foxy_sso_enabled', false); |
||||||
| 83 | } |
||||||
| 84 | |||||||
| 85 | parent::setUp(); |
||||||
| 86 | |||||||
| 87 | $product = $this->objFromFixture(ProductPage::class, 'productone'); |
||||||
| 88 | $product->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
||||||
| 89 | $discountOne = $this->objFromFixture(Discount::class, 'simplediscountpercentage'); |
||||||
| 90 | $discountOne->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
||||||
| 91 | $discountTwo = $this->objFromFixture(Discount::class, 'tierdiscountpercentage'); |
||||||
| 92 | $discountTwo->copyVersionToStage(Versioned::DRAFT, Versioned::LIVE); |
||||||
| 93 | |||||||
| 94 | Versioned::set_stage(Versioned::LIVE); |
||||||
| 95 | } |
||||||
| 96 | |||||||
| 97 | /** |
||||||
| 98 | * |
||||||
| 99 | */ |
||||||
| 100 | public function testUpdateAddToCartFormDiscountField() |
||||||
| 101 | { |
||||||
| 102 | $product = $this->objFromFixture(ProductPage::class, 'productone'); |
||||||
| 103 | $helper = DiscountHelper::create($product); |
||||||
| 104 | $controller = ProductPageController::create($product); |
||||||
| 105 | |||||||
| 106 | $key = AddToCartForm::getGeneratedValue( |
||||||
| 107 | $product->Code, |
||||||
| 108 | $helper->getFoxyDiscountType(), |
||||||
| 109 | $helper->getDiscountFieldValue() |
||||||
| 110 | ); |
||||||
| 111 | |||||||
| 112 | /** @var AddToCartForm $form */ |
||||||
| 113 | $form = $controller->AddToCartForm(); |
||||||
| 114 | $field = $form->Fields()->dataFieldByName($key); |
||||||
| 115 | |||||||
| 116 | $this->assertInstanceOf(HiddenField::class, $field); |
||||||
| 117 | $this->assertEquals($helper->getDiscountFieldValue(), $field->Value()); |
||||||
| 118 | } |
||||||
| 119 | |||||||
| 120 | public function testUpdateAddToCartFormExpirationField() |
||||||
| 121 | { |
||||||
| 122 | $timeString = strtotime('tomorrow 5pm'); |
||||||
| 123 | $endTime = date('Y-m-d H:i:s', $timeString); |
||||||
| 124 | |||||||
| 125 | /** @var Discount $discount */ |
||||||
| 126 | $discount = $this->objFromFixture(Discount::class, 'simplediscountpercentage'); |
||||||
| 127 | $discount->EndTime = $endTime; |
||||||
| 128 | $discount->writeToStage(Versioned::DRAFT); |
||||||
|
0 ignored issues
–
show
The method
writeToStage() does not exist on Dynamic\Foxy\Discounts\Model\Discount. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 129 | $discount->publishSingle(); |
||||||
|
0 ignored issues
–
show
The method
publishSingle() does not exist on Dynamic\Foxy\Discounts\Model\Discount. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 130 | |||||||
| 131 | $product = $this->objFromFixture(ProductPage::class, 'productone'); |
||||||
| 132 | $controller = ProductPageController::create($product); |
||||||
| 133 | |||||||
| 134 | $key = AddToCartForm::getGeneratedValue( |
||||||
| 135 | $product->Code, |
||||||
| 136 | 'expires', |
||||||
| 137 | strtotime($endTime) |
||||||
| 138 | ); |
||||||
| 139 | |||||||
| 140 | /** @var AddToCartForm $form */ |
||||||
| 141 | $form = $controller->AddToCartForm(); |
||||||
| 142 | $field = $form->Fields()->dataFieldByName($key); |
||||||
| 143 | |||||||
| 144 | $this->assertInstanceOf(HiddenField::class, $field); |
||||||
| 145 | $this->assertEquals($timeString, $field->Value()); |
||||||
| 146 | } |
||||||
| 147 | } |
||||||
| 148 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths