Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Base / Issue408.php
1 <?php
2
3 namespace RedUNIT\Base;
4
5 use RedUNIT\Base as Base;
6 use RedBeanPHP\Facade as R;
7
8 /**
9  * Issue 408
10  *
11  * Tests whether this specific issue on github has been resolved.
12  * Tests whether we can use export on beans having arrays in properties.
13  *
14  * @file    RedUNIT/Mysql/Issue408.php
15  * @desc    Test whether we can export beans with arrays in properties
16  *          (deserialized/serialized on open/update).
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 Issue408 extends Base
25 {
26
27         /**
28          * In the past it was not possible to export beans
29          * like 'feed' (Model_Feed).
30          *
31          * @return void
32          */
33         public function testExportIssue()
34         {
35                 R::nuke();
36                 $feed = R::dispense( 'feed' );
37                 $feed->post = array(
38                         'first',
39                         'second'
40                 );
41                 R::store( $feed );
42                 $rows = R::getAll('SELECT * FROM feed');
43                 asrt( $rows[0]['post'], '["first","second"]' );
44                 $feed = $feed->fresh();
45                 asrt( is_array( $feed->post ), TRUE );
46                 asrt( $feed->post[0], 'first' );
47                 asrt( $feed->post[1], 'second' );
48                 R::store( $feed );
49                 $rows = R::getAll('SELECT * FROM feed');
50                 asrt( $rows[0]['post'], '["first","second"]' );
51                 $feed = R::load( 'feed', $feed->id );
52                 $feed->post[] = 'third';
53                 R::store( $feed );
54                 $rows = R::getAll('SELECT * FROM feed');
55                 asrt( $rows[0]['post'], '["first","second","third"]' );
56                 $feed = $feed->fresh();
57                 asrt( is_array( $feed->post ), TRUE );
58                 asrt( $feed->post[0], 'first' );
59                 asrt( $feed->post[1], 'second' );
60                 asrt( $feed->post[2], 'third' );
61                 //now the catch: can we use export?
62                 //PHP Fatal error:  Call to a member function export() on a non-object
63                 $feeds = R::exportAll( R::find( 'feed' ) );
64                 asrt( is_array( $feeds ), TRUE );
65                 $feed = reset( $feeds );
66                 asrt( $feed['post'][0], 'first' );
67                 asrt( $feed['post'][1], 'second' );
68                 asrt( $feed['post'][2], 'third' );
69                 //can we also dup()?
70                 $feedOne = R::findOne( 'feed' );
71                 R::store( R::dup( $feedOne ) );
72                 asrt( R::count( 'feed' ), 2 );
73                 //can we delete?
74                 R::trash( $feedOne );
75                 asrt( R::count( 'feed' ), 1 );
76                 $feedTwo = R::findOne( 'feed' );
77                 $feed = $feedTwo->export();
78                 asrt( $feed['post'][0], 'first' );
79                 asrt( $feed['post'][1], 'second' );
80                 asrt( $feed['post'][2], 'third' );
81         }
82 }