Esempio n. 1
0
 /**
  * Setups test data.
  */
 public function setUp()
 {
     parent::setUp();
     $this->user = factory('App\\User')->create(['password' => Hash::make('laravel-shop')]);
     Auth::attempt(['email' => $this->user->email, 'password' => 'laravel-shop']);
     $this->product = App\TestProduct::create(['price' => 9.99, 'sku' => str_random(15), 'name' => str_random(64), 'description' => str_random(500)]);
     $this->cart = App\Cart::current()->add($this->product);
 }
Esempio n. 2
0
 /**
  * Tests cart additional methods, such as item find and calculations.
  */
 public function testCartMethods()
 {
     $product = App\TestProduct::create(['price' => 1.29, 'sku' => str_random(15), 'name' => str_random(64), 'description' => str_random(500)]);
     $cart = App\Cart::current()->add($product)->add(['sku' => 'TEST001', 'price' => 6.99]);
     $this->assertTrue($cart->hasItem('TEST001'));
     $this->assertFalse($cart->hasItem('XXX'));
     $this->assertEquals($cart->totalPrice, 8.279999999999999);
     $this->assertEquals($cart->totalTax, 0);
     $this->assertEquals($cart->totalShipping, 0);
     $this->assertEquals($cart->total, 8.279999999999999);
     $product->delete();
 }
Esempio n. 3
0
 /**
  * Tests item in cart functionality.
  */
 public function testPurchasedItemAttribute()
 {
     $user = factory('App\\User')->create(['password' => Hash::make('laravel-shop')]);
     Auth::attempt(['email' => $user->email, 'password' => 'laravel-shop']);
     $product = App\TestProduct::create(['price' => 9.99, 'sku' => str_random(15), 'name' => str_random(64), 'description' => str_random(500)]);
     $cart = App\Cart::current()->add($product);
     Shop::setGateway('testPass');
     $order = Shop::placeOrder();
     $this->assertTrue($order->isCompleted);
     $this->assertTrue($product->wasPurchased);
     $user->delete();
     $product->delete();
 }
Esempio n. 4
0
 /**
  * Tests item in cart functionality.
  */
 public function testItemInCart()
 {
     $product = App\TestProduct::create(['price' => 9.99, 'sku' => str_random(15), 'name' => str_random(64), 'description' => str_random(500)]);
     $user = factory('App\\User')->create();
     $cart = App\Cart::findByUser($user->id)->add($product)->add(['sku' => 'TEST0001', 'price' => 1.99]);
     foreach ($cart->items as $item) {
         if ($item->sku == 'TEST0001') {
             $this->assertFalse($item->hasObject);
             $this->assertNull($item->object);
             $this->assertEquals($item->shopUrl, '#');
         } else {
             $this->assertTrue($item->hasObject);
             $this->assertNotEmpty($item->object);
             $this->assertNotEquals($item->shopUrl, '#');
         }
     }
     $user->delete();
     $product->delete();
 }
 /**
  * Tests a fail purchase.
  */
 public function testFailPurchase()
 {
     // Prepare
     $user = factory('App\\User')->create(['password' => Hash::make('laravel-shop')]);
     Auth::attempt(['email' => $user->email, 'password' => 'laravel-shop']);
     $cart = App\Cart::current();
     $product = $product = App\TestProduct::create(['price' => 0.99, 'sku' => str_random(15), 'name' => str_random(64), 'description' => str_random(500)]);
     $cart->add($product);
     Shop::setGateway('paypal');
     Shop::gateway()->setCreditCard(Config::get('testing.paypal.creditcard.type'), '4111111111111111', Config::get('testing.paypal.creditcard.month'), Config::get('testing.paypal.creditcard.year'), Config::get('testing.paypal.creditcard.cvv'), Config::get('testing.paypal.creditcard.firstname'), Config::get('testing.paypal.creditcard.lastname'));
     $this->assertTrue(Shop::checkout());
     $order = Shop::placeOrder();
     $this->assertTrue($order->hasFailed);
     $this->assertEquals(Shop::exception()->getMessage(), 'CREDIT_CARD_REFUSED: Credit card was refused');
     $user->delete();
     $product->delete();
 }