Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Sqlite / Rebuild.php
1 <?php
2
3 namespace RedUNIT\Sqlite;
4
5 use RedUNIT\Sqlite as Sqlite;
6 use RedBeanPHP\Facade as R;
7
8 /**
9  * Rebuild
10  *
11  * SQLite cannot ALTER tables like other databases can.
12  * To implement fluid mode in RedBeanPHP we have to
13  * rebuild the entire table whenever we add or remove a column.
14  * This test class tests whether rebuilding tables works properly,
15  * i.e. we get the same table plus/minus some column...
16  *
17  * @file    RedUNIT/Sqlite/Rebuild.php
18  * @desc    Test rebuilding of tables for SQLite
19  * @author  Gabor de Mooij and the RedBeanPHP Community
20  * @license New BSD/GPLv2
21  *
22  * (c) G.J.G.T. (Gabor) de Mooij and the RedBeanPHP Community.
23  * This source file is subject to the New BSD/GPLv2 License that is bundled
24  * with this source code in the file license.txt.
25  */
26 class Rebuild extends Sqlite
27 {
28         /**
29          * Test SQLite table rebuilding.
30          *
31          * @return void
32          */
33         public function testRebuilder()
34         {
35                 $toolbox = R::getToolBox();
36                 $adapter = $toolbox->getDatabaseAdapter();
37                 $writer  = $toolbox->getWriter();
38                 $redbean = $toolbox->getRedBean();
39                 $pdo     = $adapter->getDatabase();
40                 $book = R::dispense( 'book' );
41                 $page = R::dispense( 'page' );
42                 $book->xownPage[] = $page;
43                 $id = R::store( $book );
44                 $book = R::load( 'book', $id );
45                 asrt( count( $book->xownPage ), 1 );
46                 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 1 );
47                 R::trash( $book );
48                 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 0 );
49                 $book = R::dispense( 'book' );
50                 $page = R::dispense( 'page' );
51                 $book->xownPage[] = $page;
52                 $id = R::store( $book );
53                 $book = R::load( 'book', $id );
54                 asrt( count( $book->xownPage ), 1 );
55                 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 1 );
56                 $book->added = 2;
57                 R::store( $book );
58                 $book->added = 'added';
59                 R::store( $book );
60                 R::trash( $book );
61                 asrt( (int) R::getCell( 'SELECT COUNT(*) FROM page' ), 0 );
62         }
63 }