metaQueryBuilder.php 792 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
<?php
use PHPUnit\Framework\TestCase;

class metaQueryBuilder extends TestCase
{
    protected $query_builder;

    protected function setUp()
    {
        include '../ninja-forms/includes/database/MetaQueryBuilder.php';
        $this->query_builder = new NF_Database_MetaQueryBuilder( 'object', 'object_meta', 1 );
    }

    public function testMetaSql()
    {
        $expected = "
            SELECT Meta.parent_id, Meta.key, Meta.value
            FROM object as Object
            JOIN object_meta as Meta
            ON Object.id = Meta.parent_id
            WHERE Object.id IN ( SELECT DISTINCT object.id FROM object WHERE object.parent_id = 1 )
        ";
        $actual = $this->query_builder->get_meta_sql();
        $this->assertEquals( trim($expected), trim($actual) );
    }
}