Exemplo n.º 1
0
 /**
  *  fixed by dfa (Dominik Fässler <*****@*****.**>)
  */
 function testNormalIteration()
 {
     $m1 = new Model1();
     $m1->doQuery();
     $a1 = $m1->a;
     $m1->next();
     $a2 = $m1->a;
     $this->assertNotEquals($a1, $a2);
 }
Exemplo n.º 2
0
 public function testValidatesPresence()
 {
     try {
         $c = new Model1();
         $c->b = 'cesar';
         $c->save();
         $this->assertTrue(FALSE);
     } catch (ActiveMongo_FilterException $e) {
         $this->assertTrue(TRUE);
     }
 }
Exemplo n.º 3
0
 /**
  *  @depends testReferences
  */
 public function testDeferencing()
 {
     $d = new Model1();
     $d->where('a', 'barfoo');
     foreach ($d as $doc) {
         $this->assertTrue(isset($doc->next));
         $this->assertTrue(MongoDBRef::isRef($doc->next));
         $this->assertTrue(MongoDBRef::isRef($doc->nested[0]));
         $this->assertTrue(MongoDBRef::isRef($doc->nested[1]));
         $this->assertTrue(MongoDBRef::isRef($doc->query));
         /* Check dynamic references properties */
         $this->assertTrue(is_array($doc->query['dynamic']));
         $this->assertTrue(count($doc->query['dynamic']) > 0);
         /* Deference */
         $doc->doDeferencing();
         /* Test deferenced values */
         $this->assertTrue($doc->next instanceof Model1);
         $this->assertTrue($doc->nested[0] instanceof Model1);
         $this->assertTrue($doc->nested[1] instanceof Model1);
         $this->assertTrue(is_array($doc->query));
         $this->assertTrue($doc->query[0] instanceof Model1);
         /* Testing mongodb refs */
         $this->assertTrue(is_array($doc->mdbref));
         foreach ($doc->mdbref as $property => $value) {
             if ($property == '_id') {
                 $this->assertEquals($value, $doc->next->getID());
                 continue;
             } else {
                 $this->assertEquals($value, $doc->next->{$property});
                 continue;
             }
             $this->assertTrue(FALSE);
         }
         /* Testing Iteration in defered documents */
         /* They should fail because they are cloned */
         /* instances of a real document */
         try {
             $doc->next->next();
             $this->assertTrue(FALSE);
         } catch (ActiveMongo_Exception $e) {
             $this->assertTrue(TRUE);
         }
     }
 }
Exemplo n.º 4
0
 public function testOutputHTMLSpecialChars()
 {
     $html = "<html>Foobar \" <script foo='bar'>derp;</script> </html>";
     $m1 = Blueprint::make('Model1', ['str1' => $html]);
     SnakeDruid::$output_htmlspecialchars = false;
     $m1 = Model1::from_id($m1->id);
     $this->assertEquals($html, $m1->str1);
     SnakeDruid::$output_htmlspecialchars = true;
     $escaped = htmlspecialchars($html, ENT_QUOTES, 'utf-8');
     $this->assertEquals($escaped, $m1->str1);
     SnakeDruid::$output_htmlspecialchars = false;
 }
Exemplo n.º 5
0
 function testScalarToArray()
 {
     $c = new Model1();
     $c->a = 1;
     $c->save();
     $c->a = array(1, 2);
     $c->save();
     $c->a[0] = array(1, 2);
     $c->a[1] = 3;
     $c->save();
     $id = $c->getID();
     $c->reset();
     $c->where('_id', $id);
     $c->doQuery();
     $this->assertEquals(array(array(1, 2), 3), $c->a);
 }
Exemplo n.º 6
0
 function testBeforeDelete()
 {
     Model1::addEvent('before_delete', array($this, 'on_delete'));
     $m1 = new Model1();
     $m1->a = rand();
     $m1->save();
     $id = (string) $m1->getId();
     $m1->delete();
     $this->assertEquals($id, $this->deleted);
 }
Exemplo n.º 7
0
 /**
  */
 public function testSum()
 {
     Blueprint::make('Model1', ['int1' => 100, 'str1' => 'testSum']);
     Blueprint::make('Model1', ['int1' => 10, 'str1' => 'testSum']);
     $this->assertEquals(220, Model1::sum(['int1', '+', 'int1'], ['str1' => 'testSum']));
 }
Exemplo n.º 8
0
 function testFindWithSingleID()
 {
     $d = new Model1();
     $d->a = 5;
     $d->save();
     $c = new Model1();
     $c->find($d->getID());
     $this->assertEquals(1, $c->count());
     $this->assertEquals($c->a, $d->a);
 }
Exemplo n.º 9
0
 /**
  * @depends testSelection
  */
 public function testMultipleOr()
 {
     $date = date('Y-m-d H:i:s');
     $models = [Blueprint::make('Model1', ['str1' => "or_test_multiple", 'timestamp1' => $date]), Blueprint::make('Model1', ['int1' => 5715, 'timestamp1' => $date])];
     $res = Model1::selection(["@or" => ['str1' => "or_test_multiple", 'int1' => 5715], "@or:banana" => ["timestamp1" => $date]]);
     $this->assertCount(2, $res);
 }
Exemplo n.º 10
0
 public function testInTableFalseWithTable()
 {
     $this->assertFalse(Model1::test_in_table('not_a_column', 'model_1'));
 }