Beispiel #1
0
 public function testGet()
 {
     $m = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User');
     $b = new Boolean();
     $this->assertTrue(is_bool($b->get($m, 'bool', 1)));
     $this->assertTrue($b->get($m, 'bool', 1));
     $this->assertTrue(is_bool($b->get($m, 'bool', 0)));
     $this->assertFalse($b->get($m, 'bool', 0));
 }
Beispiel #2
0
 public function testSave()
 {
     // For most fields, there's no transform so this is a straight pass back
     $m = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User');
     $i = $this->fieldInstance();
     $this->assertNull($i->save($m, 'name', null));
     $this->assertEquals('Alex', $i->save($m, 'name', 'Alex'));
     $this->assertEquals(27.5, $i->save($m, 'age', 27.5));
 }
Beispiel #3
0
 public function testInstancesCollectionMagic()
 {
     $results = [['id' => 1, 'name' => 'Alex', 'email' => '*****@*****.**'], ['id' => 2, 'name' => 'Lucie', 'email' => null], ['id' => 3, 'name' => 'Archibald', 'email' => '*****@*****.**']];
     $c = new Resultset($results);
     $m = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User');
     $c->resultModel($m);
     $ranged = $c['1:2'];
     $this->assertCount(2, $ranged);
     foreach ($ranged as $idx => $item) {
         $this->assertInstanceOf('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User', $item);
         $this->assertEquals($results[$idx + 1]['id'], $item->get('id'));
         $this->assertEquals($results[$idx + 1]['name'], $item->get('name'));
         $this->assertEquals($results[$idx + 1]['email'], $item->get('email'));
     }
 }
Beispiel #4
0
 public function testGet()
 {
     $m = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User');
     $zone = new DateTimeZone('Europe/London');
     $d = new DateTime(['timezone' => $zone]);
     // Testing with a timestamp:
     $now = time();
     $expected = (new NativeDateTime(null, $zone))->setTimestamp($now);
     $this->assertInstanceOf('\\DateTime', $d->get($m, 'created', $now));
     $this->assertEquals($expected->format('Y-m-d H:i:s'), $d->get($m, 'created', $now)->format('Y-m-d H:i:s'));
     // Testing with a date style format from a db:
     $date = '2014-07-02';
     $this->assertInstanceOf('\\DateTime', $d->get($m, 'created', $date));
     $this->assertEquals($date, $d->get($m, 'created', $date)->format('Y-m-d'));
     // Testing with a datetime style format from a db:
     $date = '2014-07-02 08:45:32';
     $this->assertInstanceOf('\\DateTime', $d->get($m, 'created', $date));
     $this->assertEquals($date, $d->get($m, 'created', $date)->format('Y-m-d H:i:s'));
 }
Beispiel #5
0
 public function testValidationI18nWithLang()
 {
     $object = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\UserValidated');
     try {
         $object->validate([], 'fr', __DIR__ . '/../lang');
     } catch (ValidationException $e) {
         $messages = $e->getMessages();
         $this->assertEquals('Name is required [in French]', $messages['name'][0]);
     }
 }
Beispiel #6
0
 public function testSet()
 {
     $m = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User');
     $p = $this->fieldInstance();
     $this->assertEquals('de5f7d71dda25c2e9957be163800502b1abe95cb', $p->set($m, 'password', 'MyAwesomePassword'));
 }
Beispiel #7
0
 public function testDeletingNonSavedItem()
 {
     $user = Model::factory('Solution10\\ORM\\Tests\\ActiveRecord\\Stubs\\User');
     $this->assertEquals($user, $user->delete());
 }