public function populateDb() { $this->_users = array('bob' => array('_id' => new MongoId('4c04516a1f5f5e21361e3ab0'), '_type' => array('My_ShantyMongo_Teacher', 'My_ShantyMongo_User'), 'name' => array('first' => 'Bob', 'last' => 'Jones'), 'addresses' => array(array('street' => '19 Hill St', 'suburb' => 'Brisbane', 'state' => 'QLD', 'postcode' => '4000', 'country' => 'Australia'), array('street' => '742 Evergreen Terrace', 'suburb' => 'Springfield', 'state' => 'Nevada', 'postcode' => '89002', 'country' => 'USA')), 'friends' => array(MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), MongoDBRef::create('user', new MongoId('4c0451791f5f5e21361e3ab2')), MongoDBRef::create('user', new MongoId('broken reference'))), 'faculty' => 'Maths', 'email' => '*****@*****.**', 'sex' => 'M', 'partner' => MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), 'bestFriend' => MongoDBRef::create('user', new MongoId('4c0451791f5f5e21361e3ab2'))), 'cherry' => array('_id' => new MongoId('4c04516f1f5f5e21361e3ab1'), '_type' => array('My_ShantyMongo_Student', 'My_ShantyMongo_User'), 'name' => array('first' => 'Cherry', 'last' => 'Jones'), 'email' => '*****@*****.**', 'sex' => 'F', 'concession' => true), 'roger' => array('_id' => new MongoId('4c0451791f5f5e21361e3ab2'), '_type' => array('My_ShantyMongo_ArtStudent', 'My_ShantyMongo_Student', 'My_ShantyMongo_User'), 'name' => array('first' => 'Roger', 'last' => 'Smith'), 'email' => '*****@*****.**', 'sex' => 'M', 'concession' => false)); $this->_userCollection = $this->_connection->selectDb(TESTS_SHANTY_MONGO_DB)->selectCollection('user'); foreach ($this->_users as $user) { $this->_userCollection->insert($user, true); } $this->_articles = array('regular' => array('_id' => new MongoId('4c04516f1f5f5e21361e3ac1'), 'title' => 'How to use Shanty Mongo', 'author' => MongoDBRef::create('user', new MongoId('4c04516a1f5f5e21361e3ab0')), 'editor' => MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), 'contributors' => array(MongoDBRef::create('user', new MongoId('4c04516f1f5f5e21361e3ab1')), MongoDBRef::create('user', new MongoId('4c0451791f5f5e21361e3ab2'))), 'relatedArticles' => array(MongoDBRef::create('article', new MongoId('4c04516f1f5f5e21361e3ac2'))), 'tags' => array('awesome', 'howto', 'mongodb')), 'broken' => array('_id' => new MongoId('4c04516f1f5f5e21361e3ac2'), 'title' => 'How to use Bend Space and Time', 'author' => MongoDBRef::create('user', new MongoId('broken_reference')), 'tags' => array('physics', 'hard', 'cool'))); $this->_articleCollection = $this->_connection->selectDb(TESTS_SHANTY_MONGO_DB)->selectCollection('article'); foreach ($this->_articles as $article) { $this->_articleCollection->insert($article, true); } // Insert some countries require_once 'Zend/Json.php'; $countries = Zend_Json::decode(file_get_contents($this->getFilesDir() . '/countries.json')); My_ShantyMongo_Country::insertBatch($countries); }
public function testPaginator() { $countries = My_ShantyMongo_Country::all(); $this->assertEquals(239, $countries->count()); $paginator = new Zend_Paginator(new Shanty_Paginator_Adapter_Mongo($countries)); $paginator->setItemCountPerPage(10); $paginator->setCurrentPageNumber(3); $this->assertEquals(24, $paginator->count()); // Count pages $this->assertEquals(239, $paginator->getTotalItemCount()); // count total items $this->assertEquals(10, $paginator->getCurrentItemCount()); // count items on this page $paginator->getCurrentItems()->rewind(); $firstItem = $paginator->getCurrentItems()->current(); $this->assertEquals($firstItem->code, 'BB'); $this->assertEquals($firstItem->name, 'Barbados'); }