Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Blackhole / Meta.php
1 <?php
2
3 namespace RedUNIT\Blackhole;
4
5 use RedUNIT\Blackhole as Blackhole;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\OODBBean as OODBBean;
8
9 /**
10  * Meta
11  *
12  * Beans can have meta data. Meta data will not be stored
13  * in the database and cannot be loaded from the database
14  * (except for using special meta masks - this feature is available
15  * in 4.3.2+). This test suite tests whether we can set and get
16  * meta data from beans and verifies meta data does not end up
17  * in the database.
18  *
19  * @file    RedUNIT/Blackhole/Meta.php
20  * @desc    Tests meta data features on OODBBean class.
21  * @author  Gabor de Mooij and the RedBeanPHP Community
22  * @license New BSD/GPLv2
23  *
24  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
25  * This source file is subject to the New BSD/GPLv2 License that is bundled
26  * with this source code in the file license.txt.
27  */
28 class Meta extends Blackhole
29 {
30         /**
31          * Test meta data methods.
32          *
33          * @return void
34          */
35         public function testMetaData()
36         {
37                 testpack( 'Test meta data' );
38                 $bean = new OODBBean;
39                 $bean->setMeta( "this.is.a.custom.metaproperty", "yes" );
40                 asrt( $bean->getMeta( "this.is.a.custom.metaproperty" ), "yes" );
41                 asrt( $bean->getMeta( "nonexistant" ), NULL );
42                 asrt( $bean->getMeta( "nonexistant", "abc" ), "abc" );
43                 asrt( $bean->getMeta( "nonexistant.nested" ), NULL );
44                 asrt( $bean->getMeta( "nonexistant,nested", "abc" ), "abc" );
45                 $bean->setMeta( "test.two", "second" );
46                 asrt( $bean->getMeta( "test.two" ), "second" );
47                 $bean->setMeta( "another.little.property", "yes" );
48                 asrt( $bean->getMeta( "another.little.property" ), "yes" );
49                 asrt( $bean->getMeta( "test.two" ), "second" );
50                 // Copy Metadata
51                 $bean = new OODBBean;
52                 $bean->setMeta( "meta.meta", "123" );
53                 $bean2 = new OODBBean;
54                 asrt( $bean2->getMeta( "meta.meta" ), NULL );
55                 $bean2->copyMetaFrom( $bean );
56                 asrt( $bean2->getMeta( "meta.meta" ), "123" );
57         }
58
59         /**
60          * Meta properties should not be saved.
61          *
62          * @return void
63          */
64         public function testMetaPersist()
65         {
66                 $bean = R::dispense( 'bean' );
67                 $bean->property = 'test';
68                 $bean->setMeta( 'meta', 'hello' );
69                 R::store( $bean );
70                 asrt( $bean->getMeta( 'meta' ), 'hello' );
71                 $bean = $bean->fresh();
72                 asrt( $bean->getMeta( 'meta' ), NULL );
73         }
74
75         /**
76          * You cant access meta data using the array accessors.
77          *
78          * @return void
79          */
80         public function testNoArrayMetaAccess()
81         {
82                 $bean = R::dispense( 'bean' );
83                 $bean->setMeta( 'greet', 'hello' );
84                 asrt( isset( $bean['greet'] ), FALSE );
85                 asrt( isset( $bean['__info']['greet'] ), FALSE );
86                 asrt( isset( $bean['__info'] ), FALSE );
87                 asrt( isset( $bean['meta'] ), FALSE );
88                 asrt( count( $bean ), 1 );
89         }
90 }