Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Base / Issue259.php
1 <?php
2
3 namespace RedUNIT\Base;
4
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\SimpleModel as SimpleModel;
8
9 /**
10  * Issue259
11  *
12  * Tests whether this specific issue on github has been resolved.
13  * Issue #259 - Stash Cache breaks model delegation in open().
14  *
15  * @file    RedUNIT/Base/Issue259.php
16  * @desc    Issue #259 - Stash cache breaks model delegation in open().
17  * @author  Gabor de Mooij and the RedBeanPHP Community
18  * @license New BSD/GPLv2
19  *
20  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
21  * This source file is subject to the New BSD/GPLv2 License that is bundled
22  * with this source code in the file license.txt.
23  */
24 class Issue259 extends Base
25 {
26         /**
27          * Test to make sure stash cache works with recursively opening models
28          * with FUSE.
29          *
30          * @return void
31          */
32         public function testIssue259()
33         {
34                 testpack( 'Testing Issue #259 - Stash Cache breaks model delegation in open().' );
35                 $mother = R::dispense( 'mother' );
36                 $mother->desc = 'I am mother';
37                 R::store( $mother );
38                 $child = R::dispense( 'child' );
39                 $child->mother = $mother;
40                 $child->desc   = 'I am child';
41                 $id = R::store( $child );
42                 R::findOne( 'child', ' id = ?', array( $id ) );
43                 R::find( 'child', ' id = ? ', array( $id ) );
44                 R::load( 'child', $id );
45         }
46 }
47 /**
48  * Mock Model.
49  */
50 class Model_Mother extends SimpleModel
51 {
52         public function open()
53         {
54                 $bean = $this->bean;
55                 // $this & $bean are both referencing child incorrectly!
56                 asrt( $this->bean->desc, 'I am mother' );
57         }
58 }
59 /**
60  * Mock Model.
61  */
62 class Model_Child extends SimpleModel
63 {
64         public function open()
65         {
66                 $this->bean->mother;
67                 asrt( $this->bean->desc, 'I am child' );
68         }
69 }