/** * this goes into a more advanced sorting problem to make sure stuff is being * sorted correctly * * @since 9-12-11 */ public function testSortAdvanced() { $row_count = 20; $db = $this->getDb(); $user_list = array(1, 2, 3); // create a more advanced table... $table = new MingoTable(__FUNCTION__); $table->setField('userId', MingoField::TYPE_INT); $table->setField('url', MingoField::TYPE_STR); // set defaults like the MingoOrm getTable() would... $table->setField(MingoOrm::_CREATED, MingoField::TYPE_INT); $table->setField(MingoOrm::_UPDATED, MingoField::TYPE_INT); ///$table->setIndex('created_index',array(MingoOrm::_CREATED)); $table->setIndex('url_and_user', array('url', 'userId')); $table->setIndex('user_and_created', array('userId', MingoOrm::_CREATED)); $this->setTable($table); // add some rows... for ($i = 0; $i < $row_count; $i++) { $map = array('userid' => $user_list[array_rand($user_list, 1)], 'url' => sprintf('http://%s.com', md5(microtime(true)))); $map = $db->set($table, $map); $this->assertArrayHasKey('_id', $map); } //for // test sort... foreach ($user_list as $user_id) { $where_criteria = new MingoCriteria(); $where_criteria->setUserId($user_id); $where_criteria->desc_created(); $list = $db->get($table, $where_criteria); $last_created = time() + 500; foreach ($list as $map) { $this->assertSame($user_id, $map['userid']); $this->assertLessThanOrEqual($last_created, (int) $map['_created']); $last_created = (int) $map['_created']; } //foreach } //foreach }