Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Base / Keywords.php
1 <?php
2
3 namespace RedUNIT\Base;
4
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\OODBBean as OODBBean;
8
9 /**
10  * Keywords
11  *
12  * Tests whether we can use keywords as bean types and
13  * property names without running into security or stablity issues.
14  * RedBeanPHP should properly escape all bean types and properties
15  * so we may use whatever string we want.
16  *
17  * @file    RedUNIT/Base/Keywords.php
18  * @desc    Tests for possible keyword clashes.
19  * @author  Gabor de Mooij and the RedBeanPHP Community
20  * @license New BSD/GPLv2
21  *
22  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
23  * This source file is subject to the New BSD/GPLv2 License that is bundled
24  * with this source code in the file license.txt.
25  */
26 class Keywords extends Base
27 {
28         /**
29          * What drivers should be loaded for this test pack?
30          *
31          * CUBRID has inescapable keywords :/
32          *
33          * @return array
34          */
35         public function getTargetDrivers()
36         {
37                 return array( 'mysql', 'pgsql', 'sqlite' ); // CUBRID excluded for now.
38         }
39
40         /**
41          * Test if RedBeanPHP can properly handle keywords.
42          *
43          * @return void
44          */
45         public function testKeywords()
46         {
47                 $keywords = array(
48                         'anokeyword', 'znokeyword', 'group', 'drop',
49                         'inner', 'join', 'select', 'table',
50                         'int', 'cascade', 'float', 'call',
51                         'in', 'status', 'order', 'limit',
52                         'having', 'else', 'if', 'while',
53                         'distinct', 'like'
54                 );
55                 foreach ( $keywords as $k ) {
56                         R::nuke();
57                         $bean = R::dispense( $k );
58                         $bean->$k = $k;
59                         $id = R::store( $bean );
60                         $bean = R::load( $k, $id );
61                         $bean2 = R::dispense( 'other' );
62                         $bean2->name = $k;
63                         $bean->bean = $bean2;
64                         $bean->ownBean[]    = $bean2;
65                         $bean->sharedBean[] = $bean2;
66                         $id = R::store( $bean );
67                         R::trash( $bean );
68                         pass();
69                 }
70         }
71 }