Exemplo n.º 1
0
 public function testWithPaginate()
 {
     QuerycacheTable1Query::create()->deleteAll();
     $coll = new ObjectCollection();
     $coll->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\QuerycacheTable1');
     for ($i = 0; $i < 5; $i++) {
         $b = new QuerycacheTable1();
         $b->setTitle('Title' . $i);
         $coll[] = $b;
     }
     $coll->save();
     $pager = $this->getPager(2, 1);
     $this->assertEquals(5, $pager->getNbResults());
     $results = $pager->getResults();
     $this->assertEquals('query cache with paginate offset 0 limit 2', $pager->getQuery()->getQueryKey());
     $this->assertEquals(2, count($results));
     $this->assertEquals('Title1', $results[1]->getTitle());
     //jump to page 3
     $pager = $this->getPager(2, 3);
     $this->assertEquals(5, $pager->getNbResults());
     $results = $pager->getResults();
     $this->assertEquals('query cache with paginate offset 4 limit 2', $pager->getQuery()->getQueryKey());
     $this->assertEquals(1, count($results));
     $this->assertEquals('Title4', $results[0]->getTitle());
 }
Exemplo n.º 2
0
 /**
  * @expectedException \Propel\Runtime\Exception\PropelException
  */
 public function testSaveOnReadOnlyEntityThrowsException()
 {
     $col = new ObjectCollection();
     $col->setModel('\\Propel\\Tests\\Bookstore\\ContestView');
     $cv = new ContestView();
     $col[] = $cv;
     $col->save();
 }
Exemplo n.º 3
0
 protected function createBooks($nb = 15, $con = null)
 {
     BookQuery::create()->deleteAll($con);
     $books = new ObjectCollection();
     $books->setModel('\\Propel\\Tests\\Bookstore\\Book');
     for ($i = 0; $i < $nb; $i++) {
         $b = new Book();
         $b->setTitle('Book' . $i);
         $books[] = $b;
     }
     $books->save($con);
 }
Exemplo n.º 4
0
 /**
  * @param string $itemType
  * @param string $itemEvent
  * @param array $itemIds
  *
  * @return int
  */
 protected function insertChunk($itemType, $itemEvent, array $itemIds)
 {
     $propelCollection = new ObjectCollection();
     $propelCollection->setModel(SpyTouch::class);
     foreach ($itemIds as $itemId) {
         $touchEntity = new SpyTouch();
         $touchEntity->setItemEvent($itemEvent)->setItemId($itemId)->setItemType($itemType)->setTouched(new \DateTime());
         $propelCollection->append($touchEntity);
     }
     $propelCollection->save();
     return $propelCollection->count();
 }
 public function testFromArray()
 {
     $author = new Author();
     $author->setFirstName('Jane');
     $author->setLastName('Austen');
     $author->save();
     $books = array(array('Title' => 'Mansfield Park', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()), array('Title' => 'Pride And Prejudice', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()));
     $col = new ObjectCollection();
     $col->setModel('Propel\\Tests\\Bookstore\\Book');
     $col->fromArray($books);
     $col->save();
     $nbBooks = PropelQuery::from('Propel\\Tests\\Bookstore\\Book')->count();
     $this->assertEquals(6, $nbBooks);
     $booksByJane = PropelQuery::from('Propel\\Tests\\Bookstore\\Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count();
     $this->assertEquals(2, $booksByJane);
 }
Exemplo n.º 6
0
 public function save($key = null)
 {
     if ($key === null) {
         $data = [];
         foreach (array_keys($this->preferences) as $key) {
             $data[] = $this->getPreference($key);
         }
         $collection = new ObjectCollection($data);
         $collection->setModel(PreferenceTableMap::CLASS_NAME);
         $collection->save();
     } else {
         if ($this->has($key)) {
             $p = $this->getPreference($key);
             $p->save();
         }
     }
 }
 protected function populateCreatedAt()
 {
     Table2Query::create()->deleteAll();
     $ts = new ObjectCollection();
     $ts->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\Table2');
     for ($i = 0; $i < 10; $i++) {
         $t = new Table2();
         $t->setTitle('CreatedAt' . $i);
         $t->setCreatedAt(time() - $i * 24 * 60 * 60 - 30);
         $ts[] = $t;
     }
     $ts->save();
 }