public function testSimple()
 {
     $categoryToys = new Category(['name' => 'Toys']);
     $this->assertTrue($categoryToys->getIsNewRecord());
     $categoryToys->save();
     $this->assertFalse($categoryToys->getIsNewRecord());
     $category_animals = new Category();
     $category_animals->name = 'Animals';
     $category_animals->save();
     $db = ConnectionManager::getDb();
     $tableSql = $db->schema->quoteColumnName('tests_product');
     $tableAliasSql = $db->schema->quoteColumnName('tests_product_1');
     $categoryIdSql = $db->schema->quoteColumnName('category_id');
     $this->assertEquals("SELECT COUNT(*) FROM {$tableSql} {$tableAliasSql} WHERE ({$tableAliasSql}.{$categoryIdSql}='1')", $categoryToys->products->countSql());
     $this->assertEquals(0, $categoryToys->products->count());
     $product_bear = new Product(['category' => $categoryToys, 'name' => 'Bear', 'price' => 100, 'description' => 'Funny white bear']);
     $product_bear->save();
     $this->assertEquals(1, $categoryToys->products->count());
     $product_rabbit = new Product(['category' => $category_animals, 'name' => 'Rabbit', 'price' => 110, 'description' => 'Rabbit with carrot']);
     $product_rabbit->save();
     $this->assertEquals(1, $categoryToys->products->count());
     $product_rabbit->category = $categoryToys;
     $product_rabbit->save();
     $this->assertEquals(2, $categoryToys->products->count());
 }
Esempio n. 2
0
 public function setUp()
 {
     parent::setUp();
     $model_one = new Category();
     $model_one->name = 'one';
     $model_one->save();
     $model_two = new Category();
     $model_two->name = 'two';
     $model_two->save();
 }
Esempio n. 3
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. 4
0
 public function setUp()
 {
     parent::setUp();
     $category = new Category();
     $category->name = 'test';
     $category->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;
     }
     $order1 = new Order();
     $order1->customer = $customer;
     $order1->save();
     foreach ($products as $p) {
         $order1->products->link($p);
     }
     $order2 = new Order();
     $order2->customer = $customer;
     $order2->discount = 1;
     $order2->save();
     $order2->products = $products;
     $order2->save();
 }
Esempio n. 5
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;
 }
Esempio n. 6
0
 public function testSetter()
 {
     $model = new Product();
     $model->name = 'example';
     $this->assertEquals('example', $model->name);
     $this->assertEquals('SIMPLE', $model->type);
     $model->type = '123';
     $this->assertEquals('123', $model->type);
     $category = new Category();
     $category->name = 'Toys';
     $category->save();
     $product = new Product();
     $product->name = 'Bear';
     $product->price = 100;
     $product->description = 'Funny white bear';
     $this->assertNull($product->category);
     $this->assertNull($product->category_id);
     $this->assertEquals(1, $category->pk);
     // Also working
     // $product->category = $category;
     $product->category_id = $category->pk;
     $this->assertEquals(['id', 'name'], $category->attributes());
     $this->assertEquals(['id', 'name', 'price', 'description', 'category_id'], $product->attributes());
     $this->assertEquals(1, $product->category_id);
     $this->assertEquals(1, $product->getAttribute('category_id'));
     $product->save();
     $this->assertInstanceOf('\\Tests\\Models\\Category', $product->category);
     $this->assertTrue(is_numeric($product->category_id));
 }
 public function testCross()
 {
     $category = new Category();
     $category->name = 'Toys';
     $category->save();
     $product_bear = new Product();
     $product_bear->category = $category;
     $product_bear->name = 'Bear';
     $product_bear->price = 100;
     $product_bear->description = 'Funny white bear';
     $product_bear->save();
     $product_rabbit = new Product();
     $product_rabbit->category = $category;
     $product_rabbit->name = 'Rabbit';
     $product_rabbit->price = 110;
     $product_rabbit->description = 'Rabbit with carrot';
     $product_rabbit->save();
     $this->assertInstanceOf('\\Mindy\\Orm\\ManyToManyManager', $product_rabbit->lists);
     $this->assertEquals(0, $product_rabbit->lists->count());
     $best_sellers = new ProductList();
     $best_sellers->name = 'Best sellers';
     $best_sellers->save();
     $this->assertEquals(0, $best_sellers->products->count());
     $best_sellers->products->link($product_rabbit);
     $this->assertEquals(1, $best_sellers->products->count());
     $this->assertEquals(1, $product_rabbit->lists->count());
     $product_bear->lists->link($best_sellers);
     $this->assertEquals(2, $best_sellers->products->count());
     $this->assertEquals(1, $product_bear->lists->count());
 }