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()); }
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); }
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'); }
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(); }
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); }
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); }
public function test_on_page_scope() { $paginated = Factory::make(new Category(), ['page_rows' => 3, 'page_columns' => 4]); $query = Product::onPage($paginated, 1)->getQuery(); $this->assertEquals(0, $query->offset); $this->assertEquals(12, $query->limit); $query = Product::onPage($paginated, 2)->getQuery(); $this->assertEquals(12, $query->offset); $infinite = Factory::make(new Category(), ['page_rows' => 0, 'page_columns' => 4]); $query = Product::onPage($infinite, 1)->getQuery(); $this->assertEquals(0, $query->offset); $this->assertEquals(0, $query->limit); }
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()); }
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); }
public function test_populating_a_model_with_all_fields() { $model = Factory::make(new Product()); $this->assertTrue(count($model->attributes) > 0); }
public function test_string_formatting_filters() { $filter = Factory::make(new Filter(), ['left' => 'created_at', 'operator' => '<', 'right' => 1]); $this->assertEquals('bedard.shop::lang.filter.string_created_more_than', $filter->filter_string); $filter->operator = '>'; $this->assertEquals('bedard.shop::lang.filter.string_created_less_than', $filter->filter_string); $filter->left = 'price'; $this->assertEquals('bedard.shop::lang.filter.string_price_greater_than', $filter->filter_string); $filter->operator = '<'; $this->assertEquals('bedard.shop::lang.filter.string_price_less_than', $filter->filter_string); $filter->right = 'base_price'; $this->assertEquals('bedard.shop::lang.filter.string_discounted', $filter->filter_string); }
public function test_has_expiration_and_has_ended_methods() { $running1 = Factory::make(new Discount(), ['end_at' => null]); $running2 = Factory::make(new Discount(), ['end_at' => Carbon::tomorrow()]); $ended = Factory::make(new Discount(), ['end_at' => Carbon::yesterday()]); $this->assertFalse($running1->hasEnded()); $this->assertFalse($running2->hasEnded()); $this->assertTrue($ended->hasEnded()); $this->assertFalse($running1->hasExpiration()); $this->assertTrue($running2->hasExpiration()); }