Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Blackhole / Glue.php
1 <?php
2
3 namespace RedUNIT\Blackhole;
4
5 use RedUNIT\Blackhole as Blackhole;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\QueryWriter as QueryWriter;
8
9 /**
10  * Glue
11  *
12  * RedBeanPHP does NOT parse entire queries and it does not
13  * ship with a query builder. However because RedBeanPHP
14  * facilitates mixing-in SQL snippets using methods like
15  * find(), via(), with(), withCondition() and so on...,
16  * it needs to be able to figure out how two query part strings
17  * can be connected to eachother. In particular parts beginning with or
18  * without 'WHERE', 'AND' and 'OR'. This test checks whether the
19  * QueryWriter has the ability to glue together query parts correctly.
20  * The gluer is part of the QueryWriter, however since this narrow
21  * slice of SQL syntax is so generic it's been implemented at Writer
22  * level and all drivers in RedBeanPHP inherit the generic implementation.
23  * At the moment of writing no additional glue methods had to be
24  * implemented.
25  *
26  * @file    RedUNIT/Blackhole/Glue.php
27  * @desc    Tests query gluer.
28  * @author  Gabor de Mooij and the RedBeanPHP Community
29  * @license New BSD/GPLv2
30  *
31  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
32  * This source file is subject to the New BSD/GPLv2 License that is bundled
33  * with this source code in the file license.txt.
34  */
35 class Glue extends Blackhole
36 {
37         /**
38          * Tests whether we can intelligently glue together SQL snippets.
39          *
40          * @return void
41          */
42         public function testGlue()
43         {
44                 $writer = R::getWriter();
45                 //Can we add a condition without having to type 'WHERE' - usual suspects
46                 asrt( $writer->glueSQLCondition( ' name = ? '), ' WHERE  name = ? ' );
47                 asrt( $writer->glueSQLCondition( ' value1 > ? OR value < ? '), ' WHERE  value1 > ? OR value < ? ' );
48                 //Does it recognize NON-WHERE conditions? - usual suspects
49                 asrt( $writer->glueSQLCondition( ' ORDER BY name '), ' ORDER BY name ' );
50                 asrt( $writer->glueSQLCondition( ' LIMIT 10 '), ' LIMIT 10 ' );
51                 asrt( $writer->glueSQLCondition( ' OFFSET 20 '), ' OFFSET 20 ' );
52                 //highly doubtful but who knows... - I think nobody will ever use this in a query snippet.
53                 asrt( $writer->glueSQLCondition( ' GROUP BY grp '), ' GROUP BY grp ' );
54                 asrt( $writer->glueSQLCondition( ' HAVING x = ? '), ' HAVING x = ? ' );
55                 //can we replace WHERE with AND ?
56                 asrt( $writer->glueSQLCondition( ' AND name = ? ', QueryWriter::C_GLUE_WHERE ), ' WHERE  name = ? ' );
57                 //can we glue with AND instead of WHERE ?
58                 asrt( $writer->glueSQLCondition( ' value1 > ? OR value < ? ', QueryWriter::C_GLUE_AND ), ' AND  value1 > ? OR value < ? ' );
59                 //non-cases
60                 asrt( $writer->glueSQLCondition( ' GROUP BY grp ', QueryWriter::C_GLUE_WHERE ), ' GROUP BY grp ' );
61                 asrt( $writer->glueSQLCondition( ' GROUP BY grp ', QueryWriter::C_GLUE_AND ), ' GROUP BY grp ' );
62         }
63 }