Exemplo n.º 1
0
 public function setUp()
 {
     parent::setUp();
     $this->initModels([new User(), new Group(), new Membership(), new Customer()]);
     $group = new Group();
     $group->name = 'Administrators';
     $group->save();
     $group_prog = new Group();
     $group_prog->name = 'Programmers';
     $group_prog->save();
     $anton = new User();
     $anton->username = '******';
     $anton->password = '******';
     $anton->save();
     $group_prog->users->link($anton);
     $anton_home = new Customer();
     $anton_home->address = "Anton home";
     $anton_home->user = $anton;
     $anton_home->save();
     $anton_work = new Customer();
     $anton_work->address = "Anton work";
     $anton_work->user = $anton;
     $anton_work->save();
     $max = new User();
     $max->username = '******';
     $max->password = '******';
     $max->save();
     $group->users->link($max);
     $max_home = new Customer();
     $max_home->address = "Max home";
     $max_home->user = $max;
     $max_home->save();
 }
Exemplo n.º 2
0
 public function setUp()
 {
     parent::setUp();
     $this->basePath = realpath(__DIR__ . '/../../protected');
     $group = new Group();
     $group->name = 'Administrators';
     $group->save();
     $group_prog = new Group();
     $group_prog->name = 'Programmers';
     $group_prog->save();
     $anton = new User();
     $anton->username = '******';
     $anton->password = '******';
     $anton->save();
     $group_prog->users->link($anton);
     $anton_home = new Customer();
     $anton_home->address = "Anton home";
     $anton_home->user = $anton;
     $anton_home->save();
     $anton_work = new Customer();
     $anton_work->address = "Anton work";
     $anton_work->user = $anton;
     $anton_work->save();
     $max = new User();
     $max->username = '******';
     $max->password = '******';
     $max->save();
     $group->users->link($max);
     $group_prog->users->link($max);
     $max_home = new Customer();
     $max_home->address = "Max home";
     $max_home->user = $max;
     $max_home->save();
 }
 /**
  * method that test if the system saved a record
  */
 public function testSave()
 {
     $user = new User();
     $user->load(['name' => 'Eric']);
     $saved = $user->save();
     $this->assertTrue($saved);
 }
Exemplo n.º 4
0
 public function setUp()
 {
     parent::setUp();
     $user = new User(['username' => 'foo']);
     $user->save();
     (new User(['username' => 'bar']))->save();
     (new Customer(['user' => $user, 'address' => 'address']))->save();
 }
 public function testCreateUser()
 {
     $user = new User(['nickname' => 'Alex']);
     $user->setScenario('insert');
     $this->assertTrue($user->save());
     $path = $user->getUploadPath('image');
     $this->assertTrue(is_file($path));
     $this->assertEquals(sha1_file($path), sha1_file(__DIR__ . '/data/test-image.jpg'));
 }
Exemplo n.º 6
0
 public function setUp()
 {
     parent::setUp();
     $user = new User(['username' => 'foo']);
     $user->save();
     (new User(['username' => 'bar']))->save();
     (new Customer(['user' => $user, 'address' => 'address']))->save();
     $tyre = new Tyre();
     $tyre->save();
     $modelTyre = new ModelTyre(['tyre' => $tyre, 'name' => 'Nordman 4']);
     $modelTyre->save();
     $modelTyre = new ModelTyre(['tyre' => $tyre, 'name' => 'Nordman 3']);
     $modelTyre->save();
     $modelTyre = new ModelTyre(['tyre' => $tyre, 'name' => 'Nordman 2']);
     $modelTyre->save();
 }
Exemplo n.º 7
0
 public function setUp()
 {
     parent::setUp();
     $group = new Group();
     $group->name = 'test';
     $group->save();
     $this->items = [['username' => 'Anton', 'password' => 'VeryGoodPassWord'], ['username' => 'Max', 'password' => 'The6estP@$$w0rd']];
     $users = [];
     foreach ($this->items as $item) {
         $tmp = new User($item);
         $tmp->save();
         $users[] = $tmp;
     }
     foreach ($users as $user) {
         $group->users->link($user);
         Customer::objects()->getOrCreate(['address' => 'test', 'user' => $user]);
     }
     $model = new User();
     $this->prefix = $model->getDb()->tablePrefix;
 }
 public function testVia()
 {
     $group = new Group();
     $group->name = 'Administrators';
     $this->assertNull($group->pk);
     $this->assertInstanceOf('\\Mindy\\Orm\\ManyToManyManager', $group->users);
     $this->assertEquals(0, $group->users->count());
     $this->assertEquals([], $group->users->all());
     $this->assertTrue($group->save());
     $this->assertEquals(1, $group->pk);
     $user = new User();
     $user->username = '******';
     $user->password = '******';
     $this->assertTrue($user->save());
     $this->assertEquals(0, count($group->users->all()));
     $group->users->link($user);
     $this->assertEquals(1, count($group->users->all()));
     $new = Group::objects()->get(['id' => 1]);
     $this->assertEquals(1, count($new->users->all()));
     $memberships = Membership::objects()->filter(['group_id' => 1, 'user_id' => 1])->all();
     $this->assertEquals(1, count($memberships));
 }
Exemplo n.º 9
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();
 }
Exemplo n.º 10
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 setUp()
 {
     parent::setUp();
     $group = new Group();
     $group->name = 'Administrators';
     $group->save();
     $group_prog = new Group();
     $group_prog->name = 'Programmers';
     $group_prog->save();
     $anton = new User();
     $anton->username = '******';
     $anton->password = '******';
     $anton->save();
     $group->users->link($anton);
     $group_prog->users->link($anton);
     $anton_home = new Customer();
     $anton_home->address = "Anton home";
     $anton_home->user = $anton;
     $anton_home->save();
     $anton_work = new Customer();
     $anton_work->address = "Anton work";
     $anton_work->user = $anton;
     $anton_work->save();
     $max = new User();
     $max->username = '******';
     $max->password = '******';
     $max->save();
     $group->users->link($max);
     $group_prog->users->link($max);
     $max_home = new Customer();
     $max_home->address = "Max home";
     $max_home->user = $max;
     $max_home->save();
     $model = new Customer();
     $this->prefix = $model->getDb()->tablePrefix;
 }
Exemplo n.º 12
0
 public function testChangedValues()
 {
     $model = new User();
     $this->assertTrue($model->getIsNewRecord());
     $model->username = '******';
     $model->password = '******';
     $this->assertEquals($model->getDirtyAttributes(), ['username' => 'Anton', 'password' => 'VeryGoodP@ssword']);
     $model->save();
     $this->assertEquals($model->getDirtyAttributes(), []);
     $this->assertFalse($model->getIsNewRecord());
     $model->username = '******';
     $model->username = '******';
     $this->assertEquals($model->getDirtyAttributes(), ['username' => 'Vasya']);
     $model->save();
     $finded = User::objects()->filter(['pk' => $model->pk])->get();
     $this->assertEquals('Vasya', $finded->username);
     $this->assertEquals($finded->getDirtyAttributes(), []);
     $finded->username = '******';
     $this->assertEquals($finded->getDirtyAttributes(), ['username' => 'Max']);
 }
Exemplo n.º 13
0
 public function testValuesList()
 {
     $group = new Group();
     $group->name = 'Administrators';
     $group->save();
     $groupProg = new Group();
     $groupProg->name = 'Programmers';
     $groupProg->save();
     $anton = new User();
     $anton->username = '******';
     $anton->password = '******';
     $anton->save();
     $groupProg->users->link($anton);
     $anton_home = new Customer();
     $anton_home->address = "Anton home";
     $anton_home->user = $anton;
     $anton_home->save();
     $anton_work = new Customer();
     $anton_work->address = "Anton work";
     $anton_work->user = $anton;
     $anton_work->save();
     $max = new User();
     $max->username = '******';
     $max->password = '******';
     $max->save();
     $group->users->link($max);
     $max_home = new Customer();
     $max_home->address = "Max home";
     $max_home->user = $max;
     $max_home->save();
     $values = Customer::objects()->valuesList(['address', 'user__username']);
     $this->assertEquals([['address' => 'Anton home', 'user__username' => 'Anton'], ['address' => "Anton work", 'user__username' => 'Anton'], ['address' => "Max home", 'user__username' => 'Max']], $values);
     $this->assertEquals([['address' => 'Anton home', 'user__username' => 'Anton'], ['address' => "Anton work", 'user__username' => 'Anton'], ['address' => "Max home", 'user__username' => 'Max']], Customer::objects()->valuesList(['address', 'user__username']));
     $this->assertEquals(['Anton', 'Anton', 'Max'], Customer::objects()->valuesList(['user__username'], true));
 }