|
|
@@ -28,7 +28,13 @@ use Cake\TestSuite\TestCase;
|
|
|
class QueryTest extends TestCase
|
|
|
{
|
|
|
|
|
|
- public $fixtures = ['core.articles', 'core.authors', 'core.comments', 'core.profiles'];
|
|
|
+ public $fixtures = [
|
|
|
+ 'core.articles',
|
|
|
+ 'core.authors',
|
|
|
+ 'core.comments',
|
|
|
+ 'core.profiles',
|
|
|
+ 'core.menu_link_trees'
|
|
|
+ ];
|
|
|
|
|
|
public $autoFixtures = false;
|
|
|
|
|
|
@@ -743,6 +749,80 @@ class QueryTest extends TestCase
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * Tests Query::whereNull()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSelectWhereNull()
|
|
|
+ {
|
|
|
+ $this->loadFixtures('MenuLinkTrees');
|
|
|
+
|
|
|
+ $query = new Query($this->connection);
|
|
|
+ $result = $query
|
|
|
+ ->select(['id', 'parent_id'])
|
|
|
+ ->from('menu_link_trees')
|
|
|
+ ->whereNull(['parent_id'])
|
|
|
+ ->execute();
|
|
|
+ $this->assertCount(5, $result);
|
|
|
+ $result->closeCursor();
|
|
|
+
|
|
|
+ $query = new Query($this->connection);
|
|
|
+ $result = $query
|
|
|
+ ->select(['id'])
|
|
|
+ ->from('menu_link_trees')
|
|
|
+ ->whereNull($this->connection->newQuery()->select('parent_id'))
|
|
|
+ ->execute();
|
|
|
+ $this->assertCount(5, $result);
|
|
|
+ $result->closeCursor();
|
|
|
+
|
|
|
+ $query = new Query($this->connection);
|
|
|
+ $result = $query
|
|
|
+ ->select(['id'])
|
|
|
+ ->from('menu_link_trees')
|
|
|
+ ->whereNull('parent_id')
|
|
|
+ ->execute();
|
|
|
+ $this->assertCount(5, $result);
|
|
|
+ $result->closeCursor();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Tests Query::whereNotNull()
|
|
|
+ *
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function testSelectWhereNotNull()
|
|
|
+ {
|
|
|
+ $this->loadFixtures('MenuLinkTrees');
|
|
|
+
|
|
|
+ $query = new Query($this->connection);
|
|
|
+ $result = $query
|
|
|
+ ->select(['id', 'parent_id'])
|
|
|
+ ->from('menu_link_trees')
|
|
|
+ ->whereNotNull(['parent_id'])
|
|
|
+ ->execute();
|
|
|
+ $this->assertCount(13, $result);
|
|
|
+ $result->closeCursor();
|
|
|
+
|
|
|
+ $query = new Query($this->connection);
|
|
|
+ $result = $query
|
|
|
+ ->select(['id'])
|
|
|
+ ->from('menu_link_trees')
|
|
|
+ ->whereNotNull($this->connection->newQuery()->select('parent_id'))
|
|
|
+ ->execute();
|
|
|
+ $this->assertCount(13, $result);
|
|
|
+ $result->closeCursor();
|
|
|
+
|
|
|
+ $query = new Query($this->connection);
|
|
|
+ $result = $query
|
|
|
+ ->select(['id'])
|
|
|
+ ->from('menu_link_trees')
|
|
|
+ ->whereNotNull('parent_id')
|
|
|
+ ->execute();
|
|
|
+ $this->assertCount(13, $result);
|
|
|
+ $result->closeCursor();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* Tests that passing an array type to any where condition will replace
|
|
|
* the passed array accordingly as a proper IN condition
|
|
|
*
|