예제 #1
0
 public function testQuery()
 {
     BookstoreDataPopulator::depopulate();
     BookstoreDataPopulator::populate();
     $book = PropelQuery::from('\\Propel\\Tests\\Bookstore\\Book b')->where('b.Title like ?', 'Don%')->orderBy('b.ISBN', 'desc')->findOne();
     $this->assertTrue($book instanceof Book);
     $this->assertEquals('Don Juan', $book->getTitle());
 }
 public function testDeleteAllFilter()
 {
     BookstoreDataPopulator::depopulate($this->con);
     $manager = new BookstoreManager();
     $manager->save($this->con);
     $cashier1 = new BookstoreCashier();
     $cashier1->save($this->con);
     $cashier2 = new BookstoreCashier();
     $cashier2->save($this->con);
     BookstoreManagerQuery::create()->deleteAll();
     $nbCash = BookstoreEmployeeQuery::create()->count();
     $this->assertEquals(2, $nbCash, 'Delete in sub query affects only child results');
 }
예제 #3
0
 public function testFormatterDoesNotReenableInstancePoolIfItWasInitiallyDisabled()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     BookstoreDataPopulator::depopulate($con);
     Propel::disableInstancePooling();
     $stmt = $con->query('SELECT * FROM book');
     $formatter = new OnDemandFormatter();
     $formatter->init(new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book'));
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     $books = $formatter->format($stmt);
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     $books->getIterator()->closeCursor();
     $this->assertFalse(Propel::isInstancePoolingEnabled());
     Propel::enableInstancePooling();
 }
 public function testUpdateOneByOne()
 {
     $con = Propel::getServiceContainer()->getConnection(BookTableMap::DATABASE_NAME);
     BookstoreDataPopulator::depopulate($con);
     BookstoreDataPopulator::populate($con);
     // save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $books = $c->find();
     foreach ($books as $book) {
         $book->save();
     }
     $count = $con->getQueryCount();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $nbBooks = $c->update(array('Title' => 'foo'), $con, true);
     $this->assertEquals(4, $nbBooks, 'update() returns the number of updated rows');
     $this->assertEquals($count + 1 + 4, $con->getQueryCount(), 'update() updates the objects one by one when called with true as last parameter');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
     $c->where('b.Title = ?', 'foo');
     $nbBooks = $c->count();
     $this->assertEquals(4, $nbBooks, 'update() updates all records by default');
     BookstoreDataPopulator::depopulate($con);
     BookstoreDataPopulator::populate($con);
     // save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book');
     $books = $c->find();
     foreach ($books as $book) {
         $book->save();
     }
     $count = $con->getQueryCount();
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
     $c->where('b.Title = ?', 'Don Juan');
     $nbBooks = $c->update(array('ISBN' => '3456'), $con, true);
     $this->assertEquals(1, $nbBooks, 'update() updates only the records matching the criteria');
     $this->assertEquals($count + 1 + 1, $con->getQueryCount(), 'update() updates the objects one by one when called with true as last parameter');
     $c = new ModelCriteria('bookstore', 'Propel\\Tests\\Bookstore\\Book', 'b');
     $c->where('b.Title = ?', 'Don Juan');
     $book = $c->findOne();
     $this->assertEquals('3456', $book->getISBN(), 'update() updates only the records matching the criteria');
 }
 public function testPruneCompositeKey()
 {
     BookstoreDataPopulator::depopulate();
     BookstoreDataPopulator::populate();
     // save all books to make sure related objects are also saved - BookstoreDataPopulator keeps some unsaved
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $books = $c->find();
     foreach ($books as $book) {
         $book->save();
     }
     BookTableMap::clearInstancePool();
     $nbBookListRel = BookListRelQuery::create()->prune()->count();
     $this->assertEquals(2, $nbBookListRel, 'prune() does nothing when passed a null object');
     $testBookListRel = BookListRelQuery::create()->findOne();
     $nbBookListRel = BookListRelQuery::create()->prune($testBookListRel)->count();
     $this->assertEquals(1, $nbBookListRel, 'prune() removes an object from the result');
 }
 public function testSelectArrayWithColumn()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $c = new ModelCriteria('bookstore', '\\Propel\\Tests\\Bookstore\\Book');
     $c->join('Book.Author');
     $c->withColumn('LOWER(Book.Title)', 'LowercaseTitle');
     $c->select(array('LowercaseTitle', 'Book.Title'));
     $c->orderBy('Book.Title');
     $rows = $c->find($this->con);
     $expectedSQL = 'SELECT LOWER(book.TITLE) AS LowercaseTitle, book.TITLE AS "Book.Title" FROM `book` INNER JOIN `author` ON (book.AUTHOR_ID=author.ID) ORDER BY book.TITLE ASC';
     $this->assertEquals($expectedSQL, $this->con->getLastExecutedQuery(), 'find() called after select(array) can cope with a column added with withColumn()');
     $expectedRows = array(array('LowercaseTitle' => 'don juan', 'Book.Title' => 'Don Juan'), array('LowercaseTitle' => 'harry potter and the order of the phoenix', 'Book.Title' => 'Harry Potter and the Order of the Phoenix'), array('LowercaseTitle' => 'quicksilver', 'Book.Title' => 'Quicksilver'), array('LowercaseTitle' => 'the tin drum', 'Book.Title' => 'The Tin Drum'));
     $this->assertEquals(serialize($rows->getData()), serialize($expectedRows), 'find() called after select(array) can cope with a column added with withColumn()');
 }
 public function testSelectArrayPaginate()
 {
     BookstoreDataPopulator::depopulate($this->con);
     BookstoreDataPopulator::populate($this->con);
     $pager = BookQuery::create()->select(array('Id', 'Title', 'ISBN', 'Price'))->paginate(1, 10, $this->con);
     $this->assertInstanceOf('Propel\\Runtime\\Util\\PropelModelPager', $pager);
     foreach ($pager as $result) {
         $this->assertEquals(array('Id', 'Title', 'ISBN', 'Price'), array_keys($result));
     }
 }
 protected function setUp()
 {
     parent::setUp();
     BookstoreDataPopulator::depopulate();
     BookstoreDataPopulator::populate();
 }