Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Base / Frozen.php
1 <?php
2
3 namespace RedUNIT\Base;
4
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\RedException as RedException;
8 use RedBeanPHP\OODBBean as OODBBean;
9
10 /**
11  * Frozen
12  *
13  * Frozen mode tests
14  * When I split the repositories in frozen and fluid I discovered some missed
15  * code-paths in the tests.
16  * These tests are here to make sure the following scenarios work properly
17  * in frozen mode as well.
18  *
19  * @file    RedUNIT/Base/Frozen.php
20  * @desc    Test some scenarios we haven't covered for frozen mode.
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 Frozen extends Base
29 {
30         /**
31          * Tests the handling of trashed beans in frozen mode.
32          * Are the lists unset etc?
33          *
34          * @return void
35          */
36         public function testTrash()
37         {
38                 R::nuke();
39                 $book = R::dispense( 'book' );
40                 $book->xownPageList[] = R::dispense( 'page' );
41                 $book->sharedTagList[] = R::dispense( 'tag' );
42                 R::store( $book );
43                 $book = $book->fresh();
44                 R::freeze( TRUE );
45
46                 $book->xownPageList = array();
47
48                 R::store( $book );
49                 $book = $book->fresh();
50
51                 asrt( R::count('page'), 0 );
52
53                 $book->xownPageList[] = R::dispense( 'page' );
54
55                 R::store( $book );
56                 $book = $book->fresh();
57
58                 asrt( R::count('page'), 1 );
59
60                 $book->xownPageList;
61                 $book->sharedTagList;
62                 R::trash( $book );
63
64                 asrt( R::count('book'), 0 );
65                 asrt( R::count('page'), 0 );
66                 asrt( R::count('tag'), 1 );
67                 asrt( R::count('book_tag'), 0 );
68
69                 R::freeze( FALSE );
70         }
71
72         /**
73          * Tests whether invalid list checks are
74          * operational in frozen mode.
75          *
76          * @return void
77          */
78         public function testInvalidList()
79         {
80                 R::nuke();
81                 $book = R::dispense( 'book' );
82                 $book->xownPageList[] = R::dispense( 'page' );
83                 $book->sharedTagList[] = R::dispense( 'tag' );
84                 R::store( $book );
85                 R::freeze( TRUE );
86
87                 $book = R::dispense( 'book' );
88                 $book->xownPageList[] = 'nonsense';
89                 try {
90                         R::store( $book );
91                         fail();
92                 } catch( \Exception $e ) {
93                         pass();
94                 }
95
96                 R::freeze( FALSE );
97         }
98
99         /**
100          * Tests whether loading non-existant beans
101          * returns the same results in frozen mode.
102          *
103          * @return
104          */
105         public function testLoadNonExistant()
106         {
107                 R::nuke();
108                 R::store( R::dispense( 'bean' ) );
109                 R::freeze( TRUE );
110                 $bean = R::load( 'bean', 123 );
111                 R::freeze( FALSE );
112                 asrt( ( $bean instanceof OODBBean ), TRUE );
113                 asrt( $bean->id, 0 );
114         }
115 }