예제 #1
0
 public function test_aliases_point_to_correct_related_properties()
 {
     $product = Factory::create(new Product());
     $inventory = Factory::create(new Inventory(), ['product_id' => $product->id]);
     $item = Factory::create(new CartItem());
     $this->assertEquals($product->name, $item->name);
 }
예제 #2
0
 public function test_deleting_an_option_deletes_associated_selections()
 {
     $option = Factory::create(new Option());
     $selection = Factory::create(new Selection(), ['option_id' => $option->id]);
     $option->delete();
     $this->assertFalse(Selection::whereId($selection->id)->exists());
 }
예제 #3
0
 public function test_deleting_a_selection_deletes_associated_inventories()
 {
     $selection = Factory::create(new Selection());
     $inventory = Factory::create(new Inventory());
     $selection->inventories()->attach($inventory);
     $selection->delete();
     $this->assertFalse(Inventory::whereId($inventory->id)->exists());
 }
 public function test_finding_a_product_by_slug()
 {
     $repo = new ProductRepository();
     $product = Factory::create(new Product());
     $response = $repo->findBySlug($product->slug);
     $this->assertEquals($product->id, $response->id);
     $this->setExpectedException('Illuminate\\Database\\Eloquent\\ModelNotFoundException');
     $response = $repo->findBySlug('foofoofoo');
 }
예제 #5
0
 public function seedDiscounts()
 {
     $expired = Factory::create(new Discount(), ['start_at' => null, 'end_at' => Carbon::yesterday()]);
     $running = Factory::create(new Discount(), ['start_at' => Carbon::yesterday(), 'end_at' => Carbon::tomorrow()]);
     $running->products()->sync([1, 2, 3]);
     $running->save();
     $upcoming = Factory::create(new Discount(), ['start_at' => Carbon::tomorrow(), 'end_at' => null]);
     $upcoming->categories()->sync([5]);
     $upcoming->save();
 }
예제 #6
0
 public function test_where_has_selections_scope()
 {
     $foo = Factory::create(new Inventory());
     $s1 = Factory::create(new Selection());
     $s2 = Factory::create(new Selection());
     $signature = [$s1->id, $s2->id];
     $bar = Factory::make(new Inventory());
     $bar->setSelections($signature);
     $bar->save();
     $this->assertEquals($foo->id, Inventory::whereHasSelections([])->first()->id);
     $this->assertEquals(1, Inventory::whereHasSelections([])->count());
     $this->assertEquals($bar->id, Inventory::whereHasSelections($signature)->first()->id);
     $this->assertEquals(1, Inventory::whereHasSelections($signature)->count());
 }
 public function test_updating_a_cart()
 {
     $repository = new CartRepository();
     $product1 = Factory::create(new Product());
     $product2 = Factory::create(new Product());
     $inventory1 = Factory::create(new Inventory(), ['product_id' => $product1->id, 'quantity' => 5]);
     $inventory2 = Factory::create(new Inventory(), ['product_id' => $product2->id, 'quantity' => 5]);
     $repository->addToCart($product1->id, [], 1);
     $repository->addToCart($product2->id, [], 2);
     // Set product 1 to quantity: 3, and delete product 2
     $repository->updateCart([1 => 3, 2 => 0]);
     $this->assertEquals(3, $repository->getItemCount());
     $this->assertEquals($product1->id, $repository->getItems()->first()->id);
 }
예제 #8
0
 public function test_timeable_scopes()
 {
     $past = Factory::create(new Discount(), ['start_at' => Carbon::now()->subDays(10), 'end_at' => Carbon::now()->subDays(5)]);
     $present = Factory::create(new Discount(), ['start_at' => Carbon::now()->subDays(5), 'end_at' => Carbon::now()->addDays(5)]);
     $future = Factory::create(new Discount(), ['start_at' => Carbon::now()->addDays(5), 'end_at' => Carbon::now()->addDays(10)]);
     $expired = Discount::isExpired()->get();
     $this->assertEquals(1, count($expired));
     $this->assertEquals($past->id, $expired->first()->id);
     $running = Discount::isRunning()->get();
     $this->assertEquals(1, count($running));
     $this->assertEquals($present->id, $running->first()->id);
     $upcoming = Discount::isUpcoming()->get();
     $this->assertEquals(1, count($upcoming));
     $this->assertEquals($future->id, $upcoming->first()->id);
     $runningOrUpcoming = Discount::isRunningOrUpcoming()->get();
     $this->assertEquals(2, count($runningOrUpcoming));
     $this->assertTrue($runningOrUpcoming->contains('id', $present->id));
     $this->assertTrue($runningOrUpcoming->contains('id', $future->id));
 }
 public function test_fetching_a_page_of_products()
 {
     $parent = Factory::create(new Category(), ['is_inheriting' => true, 'page_rows' => 2, 'page_columns' => 2]);
     $child = Factory::create(new Category(), ['parent_id' => $parent->id]);
     $parent->products()->attach(Factory::create(new Product(), ['name' => 'one']));
     $parent->products()->attach(Factory::create(new Product(), ['name' => 'two']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'three']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'four']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'five']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'six']));
     $child->products()->attach(Factory::create(new Product(), ['name' => 'seven', 'is_enabled' => false]));
     $repo = new CategoryRepository();
     $page1 = $repo->getProducts($parent, 1, true, true, true);
     $page2 = $repo->getProducts($parent, 2);
     $page3 = $repo->getProducts($parent, 3);
     $this->assertEquals(4, $page1->count());
     $this->assertEquals(2, $page2->count());
     $this->assertEquals(0, $page3->count());
     $this->assertNotNull($page1->first()->inventory);
 }
예제 #10
0
 public function test_in_category_scope()
 {
     $parent = Factory::create(new Category(), ['is_inheriting' => true]);
     $child = Factory::create(new Category(), ['parent_id' => $parent->id, 'is_inheriting' => false]);
     $uninherited = Factory::create(new Category(), ['parent_id' => $child->id]);
     $orphan = Factory::create(new Category());
     $filtered = Factory::create(new Category());
     $filter = Factory::create(new Filter(), ['category_id' => $filtered->id, 'left' => 'base_price', 'operator' => '<', 'right' => 10]);
     $hiding = Factory::create(new Category(), ['is_hiding_out_of_stock' => true]);
     $product1 = Factory::create(new Product(), ['base_price' => 5]);
     $product2 = Factory::create(new Product(), ['base_price' => 10]);
     $product3 = Factory::create(new Product(), ['base_price' => 15]);
     $parent->products()->attach($product1);
     $child->products()->attach($product2);
     $uninherited->products()->attach($product3);
     $hiding->products()->attach($product3);
     $this->assertEquals(2, Product::inCategory($parent)->count());
     $this->assertEquals(1, Product::inCategory($child)->count());
     $this->assertEquals(1, Product::inCategory($uninherited)->count());
     $this->assertEquals(0, Product::inCategory($orphan)->count());
     $this->assertEquals(1, Product::inCategory($filtered)->count());
     $this->assertEquals(0, Product::inCategory($hiding)->count());
     $this->assertEquals($product1->id, Product::inCategory($filtered)->first()->id);
 }
예제 #11
0
 public function test_prices_for_products_of_descendent_categories_added_to_discounts()
 {
     $product = Factory::create(new Product());
     $parent = Factory::create(new Category(), ['is_inheriting' => true]);
     $child = Factory::create(new Category(), ['parent_id' => $parent->id]);
     $child->products()->attach($product);
     $discount = Factory::create(new Discount());
     $discount->categories()->add($parent);
     $discount->save();
     $this->assertEquals(1, Price::where('product_id', $product->id)->where('discount_id', $discount->id)->count());
 }
예제 #12
0
 public function test_isFiltered_and_isNotFiltered_scopes()
 {
     $normal = Factory::create(new Category());
     $filtered = Factory::create(new Category());
     $filter = Factory::create(new Filter(), ['category_id' => $filtered->id]);
     $this->assertEquals(1, Category::isNotFiltered()->count());
     $this->assertEquals($normal->id, Category::isNotFiltered()->first()->id);
     $this->assertEquals(1, Category::isFiltered()->count());
     $this->assertEquals($filtered->id, Category::isFiltered()->first()->id);
 }
예제 #13
0
 public function test_create_should_return_a_saved_model()
 {
     $model = Factory::create(new Product());
     $this->assertTrue((bool) $model->id);
 }