Yaffs site version 1.1
[yaffs-website] / vendor / gabordemooij / redbean / testing / RedUNIT / Mysql / Preexist.php
1 <?php
2
3 namespace RedUNIT\Mysql;
4
5 use RedUNIT\Mysql as Mysql;
6 use RedBeanPHP\Facade as R;
7 use RedBeanPHP\AssociationManager as AssociationManager;
8
9 /**
10  * Preexist
11  *
12  * Tests whether RedBeanPHP can work with existing
13  * MySQL schemas.
14  *
15  * @file    RedUNIT/Mysql/Preexist.php
16  * @desc    Tests integration with pre-existing schemas.
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 Preexist extends Mysql
25 {
26         /**
27          * Test integration with pre-existing schemas.
28          *
29          * @return void
30          */
31         public function testPlaysNiceWithPreExitsingSchema()
32         {
33                 $toolbox     = R::getToolBox();
34                 $adapter     = $toolbox->getDatabaseAdapter();
35                 $writer      = $toolbox->getWriter();
36                 $redbean     = $toolbox->getRedBean();
37                 $pdo         = $adapter->getDatabase();
38                 $a           = new AssociationManager( $toolbox );
39                 $page        = $redbean->dispense( "page" );
40                 $page->name  = "John's page";
41                 $idpage      = $redbean->store( $page );
42                 $page2       = $redbean->dispense( "page" );
43                 $page2->name = "John's second page";
44                 $idpage2     = $redbean->store( $page2 );
45                 $a->associate( $page, $page2 );
46                 $adapter->exec( "ALTER TABLE " . $writer->esc( 'page' ) . "
47                 CHANGE " . $writer->esc( 'name' ) . " " . $writer->esc( 'name' ) . "
48                 VARCHAR( 254 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL " );
49                 $page       = $redbean->dispense( "page" );
50                 $page->name = "Just Another Page In a Table";
51                 $cols       = $writer->getColumns( "page" );
52                 asrt( $cols["name"], "varchar(254)" );
53                 $redbean->store( $page );
54                 pass(); // No crash?
55                 $cols = $writer->getColumns( "page" );
56                 asrt( $cols["name"], "varchar(254)" ); //must still be same
57         }
58 }