<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a product to cart that has options'); // Make models // Create a product with some options $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); $options[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'radio', 1); $options[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'select', 1); $options[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'text', 1); $product->options()->saveMany($options); // Create another product so we can try and force it's option on to the 'correct' product $unrelatedProduct = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); $unrelatedOption = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'select', 1); $unrelatedProduct->options()->save($unrelatedOption); $I->amOnRoute('shop.product.show', $product->slug); // Randomly choose the option values $option_values = []; foreach ($options as $option) { if ($option->type == 'radio' || $option->type == 'select') { $option_values[$option->id] = $option->config[array_rand($option->config)]; $I->selectOption('option[' . $option->id . ']', $option_values[$option->id]); } else { $option_values[$option->id] = "Testing"; $I->fillField('option[' . $option->id . ']', "Testing"); } } // Submit the form $I->submitForm('#addToCart', ['option[' . $unrelatedOption->id . ']' => $unrelatedOption->config[0]]); $I->seeCurrentRouteIs('shop.cart.show'); // Check that we see the product
<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a product to cart that has bad extras'); // Create the models $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); // Extra 1 - This extra has a few options and will be selected $extra1 = $I->makeModel(DanPowell\Shop\Models\Extra::class, [], 'inStock', 1); $extra1 = $product->extras()->save($extra1); $option1 = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'text', 1); $option1 = $extra1->options()->save($option1); $I->amOnRoute('shop.product.show', $product->slug); // Select the extra 1, but DON'T fill out the option value $I->checkOption('extra[' . $extra1->id . ']'); $I->submitForm('#addToCart', []); $I->dontSee('Product added to cart', '.alert'); $I->seeCurrentRouteIs('shop.product.show'); $I->seeFormHasErrors();
<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a product to cart that has extras with options'); // Create the models $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); // Extra 1 - This extra has a few options and will be selected $extra1 = $I->makeModel(DanPowell\Shop\Models\Extra::class, [], 'inStock', 1); $extra1 = $product->extras()->save($extra1); $options1[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'radio', 1); $options1[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'select', 1); $options1[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'text', 1); $options1 = $extra1->options()->saveMany($options1); // Extra 2 - This extra will not be selected $extra2 = $I->makeModel(DanPowell\Shop\Models\Extra::class, [], 'inStock', 1); $extra2 = $product->extras()->save($extra2); $options2[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'radio', 1); $options2[] = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'select', 1); $options2 = $extra2->options()->saveMany($options2); $I->amOnRoute('shop.product.show', $product->slug); // Select the extra 1 $I->checkOption('extra[' . $extra1->id . ']'); // Select some options to make sure they appear in the cart $option_values = []; foreach (array_merge($options1, $options2) as $option) { if ($option->type == 'radio' || $option->type == 'select') { $option_values[$option->id] = $option->config[array_rand($option->config)]; $I->selectOption('option[' . $option->id . ']', $option_values[$option->id]); } else { $option_values[$option->id] = "Testing"; $I->fillField('option[' . $option->id . ']', "Testing");
<?php $I = new FunctionalTester($scenario); $I->wantTo('Create an order'); // Add a product to the cart $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'published', 1); $I->amOnRoute('shop.product.show', $product->slug); $I->click('Add to Cart'); // Checkout $I->click('Checkout'); $order = $I->makeModel(DanPowell\Shop\Models\Order::class, [], null, 1); $I->submitForm('#createOrder', $order->toArray()); $I->seeCurrentRouteIs('shop.order.confirm'); // Continue to confirmation //$I->click('Continue to confirmation'); // Check delivery option exists in config // Check delivery option matches cart total // Check billing & delivery country exists in config
<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a product to cart that has extras'); // Create a Product and add some Extras $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); for ($i = 0; $i < 2; $i++) { $extras[] = $I->makeModel(DanPowell\Shop\Models\Extra::class, [], 'inStock', 1); } $product->extras()->saveMany($extras); // Create another product so we can try and force it's option on to the 'correct' product $unrelatedProduct = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); $unrelatedExtra = $I->makeModel(DanPowell\Shop\Models\Extra::class, [], 'inStock', 1); $unrelatedProduct->extras()->save($unrelatedExtra); // Go to the product page $I->amOnRoute('shop.product.show', $product->slug); // Select only the first Extra $I->checkOption('extra[' . $extras[0]->id . ']'); $I->submitForm('#addToCart', ['extra[' . $unrelatedExtra->id . ']' => 'on']); $I->seeCurrentRouteIs('shop.cart.show'); $I->see('Product added to cart', '.alert'); $I->see($product->title, '.CartTable-product-title'); // Should see first Extra $I->see($extras[0]->title, '.CartTable-item-extras'); // Should *not* see any other Extras $I->dontSee($extras[1]->title, '.CartTable-item-extas'); $I->dontSee($unrelatedExtra->title, '.CartTable-item-extas');