/**
     * @covers Windwalker\DataMapper\RelationDataMapper::findOne
     * @todo   Implement testFindOne().
     */
    public function testFindOne()
    {
        $data = $this->object->findOne(array('cont.access' => 1, new GteCompare('cat.id', 25)), 'cont.title DESC');
        $sql = <<<SQL
SELECT `cont`.`id` AS `id`,
\t`cont`.`title` AS `title`,
\t`cont`.`catid` AS `catid`,
\t`cont`.`created` AS `created`,
\t`cont`.`created_by` AS `created_by`,
\t`cont`.`access` AS `access`,
\t`cat`.`id` AS `cat_id`,
\t`cat`.`parent_id` AS `cat_parent_id`,
\t`cat`.`title` AS `cat_title`,
\t`user`.`id` AS `user_id`,
\t`user`.`name` AS `user_name`,
\t`user`.`username` AS `user_username`
FROM `ww_content` AS `cont`
\tLEFT JOIN `ww_categories` AS `cat` ON cont.catid = cat.id
\tLEFT JOIN `ww_users` AS `user` ON cont.created_by = user.id
WHERE cont.access = 1
\tAND cat.id >= 25
ORDER BY cont.title DESC
SQL;
        $item = $this->db->setQuery($sql)->loadObject('Windwalker\\Data\\Data');
        $this->assertEquals($data, $item);
    }
    /**
     * Test find one.
     *
     * @covers Windwalker\DataMapper\RelationDataMapper::findOne
     *
     * @return void
     */
    public function testFindOne()
    {
        $data = $this->instance->findOne(array('flower.state' => 1, new GteCompare('category.id', 2)), 'flower.title DESC');
        $sql = <<<SQL
SELECT `flower`.`id`,
\t`flower`.`catid`,
\t`flower`.`title`,
\t`flower`.`meaning`,
\t`flower`.`ordering`,
\t`flower`.`state`,
\t`flower`.`params`,
\t`category`.`id` AS `category_id`,
\t`category`.`title` AS `category_title`,
\t`category`.`ordering` AS `category_ordering`,
\t`category`.`params` AS `category_params`
FROM `ww_flower` AS `flower`
\tLEFT JOIN `ww_categories` AS `category` ON flower.catid = category.id
WHERE `flower`.`state` = 1
\tAND `category`.`id` >= 2
ORDER BY flower.title DESC
SQL;
        $this->assertEquals($data, $this->loadToData($sql));
    }
Esempio n. 3
0
 /**
  * getLastPost
  *
  * @param int $pk
  *
  * @return  Data
  */
 public function getLastPost($pk)
 {
     $mapper = new RelationDataMapper('post', Table::POSTS);
     $mapper->addTable('topic', Table::TOPICS, 'topic.id = post.topic_id')->addTable('category', LunaTable::CATEGORIES, 'category.id = topic.category_id')->addTable('user', WarderTable::USERS, 'user.id = post.user_id');
     $post = $mapper->findOne(array('category.id' => $pk), 'post.created DESC');
     return $post;
 }