コード例 #1
0
 public function seedProducts($products)
 {
     $categories = Category::all()->lists('id');
     for ($i = 0; $i < $products; $i++) {
         $keys = array_rand($categories, rand(1, 2));
         if (is_int($keys)) {
             $keys = [$keys];
         }
         $sync = [];
         foreach ($keys as $key) {
             $sync[] = $categories[$key];
         }
         $product = Factory::create(new Product(), ['is_enabled' => rand(0, 100) > 20]);
         $size = Factory::make(new Option(), ['name' => 'Size']);
         $size->bindSelections(['id' => [null, null, null], 'name' => ['Small', 'Medium', 'Large']]);
         $size->save();
         $product->options()->add($size);
         $color = Factory::make(new Option(), ['name' => 'Color']);
         $color->bindSelections(['id' => [null, null, null], 'name' => ['Red', 'Green', 'Blue']]);
         $color->save();
         $product->options()->add($color);
         $product->categories()->sync($sync);
         $inventory = Factory::create(new Inventory(), ['product_id' => $product->id, 'quantity' => rand(0, 5)]);
     }
 }
コード例 #2
0
 public function test_selection_names_must_be_unique()
 {
     $selections = ['id' => [null, null], 'name' => [' Foo', 'foo ']];
     $option = Factory::make(new Option());
     $this->setExpectedException('October\\Rain\\Exception\\ValidationException');
     $option->bindSelections($selections);
 }
コード例 #3
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());
 }
コード例 #4
0
 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);
 }
コード例 #5
0
 public function test_prices_are_generated_during_initial_create_through_deferred_bindings()
 {
     $product1 = Factory::create(new Product());
     $product2 = Factory::create(new Product());
     $category = Factory::create(new Category());
     $category->products()->attach($product2);
     $sessionKey = uniqid();
     $discount = Factory::make(new Discount());
     $discount->products()->add($product1, $sessionKey);
     $discount->categories()->add($category, $sessionKey);
     $discount->save(null, $sessionKey);
     $this->assertEquals(1, Price::where('product_id', $product1->id)->where('discount_id', $discount->id)->count());
     $this->assertEquals(1, Price::where('product_id', $product2->id)->where('discount_id', $discount->id)->count());
 }
コード例 #6
0
 public function test_category_page_sizes()
 {
     $category = Factory::make(new Category(), ['page_rows' => 2, 'page_columns' => 3]);
     $this->assertEquals(6, $category->getPageSize());
 }
コード例 #7
0
 public function test_populating_a_model_with_all_fields()
 {
     $model = Factory::make(new Product());
     $this->assertTrue(count($model->attributes) > 0);
 }
コード例 #8
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);
 }
コード例 #9
-1
 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());
 }