3 namespace RedUNIT\Blackhole;
5 use RedUNIT\Blackhole as Blackhole;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\OODBBean as OODBBean;
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
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
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.
28 class Meta extends Blackhole
31 * Test meta data methods.
35 public function testMetaData()
37 testpack( 'Test meta data' );
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" );
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" );
60 * Meta properties should not be saved.
64 public function testMetaPersist()
66 $bean = R::dispense( 'bean' );
67 $bean->property = 'test';
68 $bean->setMeta( 'meta', 'hello' );
70 asrt( $bean->getMeta( 'meta' ), 'hello' );
71 $bean = $bean->fresh();
72 asrt( $bean->getMeta( 'meta' ), NULL );
76 * You cant access meta data using the array accessors.
80 public function testNoArrayMetaAccess()
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 );