Esempio n. 1
0
 public function setUp()
 {
     parent::setUp();
     $category = new Category(['name' => 'cat']);
     $category->save();
     $product1 = new Product(['name' => 'foo', 'category' => $category]);
     $product1->save();
     $product2 = new Product(['name' => 'bar', 'category' => $category]);
     $product2->save();
     $list = new ProductList(['name' => 'test']);
     $list->save();
     $list->products->link($product1);
     $list->products->link($product2);
     $list = new ProductList(['name' => 'asd']);
     $list->save();
     $list->products->link($product1);
 }
Esempio n. 2
0
 public function setUp()
 {
     parent::setUp();
     $category = new Category();
     $category->name = 'test';
     $category->save();
     $product_list = new ProductList();
     $product_list->name = 'First product list';
     $product_list->date_action = '2014-04-29 10:35:45';
     $product_list->save();
     $user = new User();
     $user->password = 123456;
     $user->username = '******';
     $user->save();
     $customer = new Customer();
     $customer->user = $user;
     $customer->address = 'example super address';
     $customer->save();
     $products = [];
     foreach ([1, 2, 3, 4, 5] as $i) {
         $product = new Product();
         $product->name = $i;
         $product->price = $i;
         $product->description = $i;
         $product->category = $category;
         $product->save();
         $products[] = $product;
     }
     $order = new Order();
     $order->customer = $customer;
     $order->save();
     $order->products = $products;
     $order->save();
     $model = new Category();
     $this->prefix = $model->getDb()->tablePrefix;
 }
 public function testExtraLinkRecords()
 {
     $product = new Product();
     $product->name = 'Bear';
     $product->price = 100;
     $product->description = 'Funny white bear';
     $product->save();
     $list1 = new ProductList();
     $list1->name = 'Toys';
     $list1->save();
     $list2 = new ProductList();
     $list2->name = 'Trash';
     $list2->save();
     $this->assertEquals(1, Product::objects()->count());
     $this->assertEquals(2, ProductList::objects()->count());
     $tableName = $product->getField('lists')->getTableName();
     $cmd = ConnectionManager::getDb()->createCommand("SELECT * FROM {$tableName}");
     $all = $cmd->queryAll();
     $this->assertEquals([], $all);
     $this->assertEquals(0, count($all));
     $product->lists = [$list1];
     $product->save();
     $cmd = ConnectionManager::getDb()->createCommand("SELECT * FROM {$tableName}");
     $all = $cmd->queryAll();
     $this->assertEquals([['product_id' => 1, 'product_list_id' => 1]], $all);
     $this->assertEquals(1, count($all));
     $product->lists = [$list2];
     $product->save();
     $cmd = ConnectionManager::getDb()->createCommand("SELECT * FROM {$tableName}");
     $all = $cmd->queryAll();
     $this->assertEquals([['product_id' => 1, 'product_list_id' => 2]], $all);
     $this->assertEquals(1, count($all));
     $product->lists = [$list1];
     $product->save();
     $cmd = ConnectionManager::getDb()->createCommand("SELECT * FROM {$tableName}");
     $all = $cmd->queryAll();
     $this->assertEquals([['product_id' => 1, 'product_list_id' => 1]], $all);
     $this->assertEquals(1, count($all));
     $product->lists = [$list1, $list1, $list1];
     $product->save();
     $cmd = ConnectionManager::getDb()->createCommand("SELECT * FROM {$tableName}");
     $all = $cmd->queryAll();
     $this->assertEquals([['product_id' => 1, 'product_list_id' => 1], ['product_id' => 1, 'product_list_id' => 1], ['product_id' => 1, 'product_list_id' => 1]], $all);
     $this->assertEquals(3, count($all));
 }