Skip to content

Commit

Permalink
fixed view tests
Browse files Browse the repository at this point in the history
  • Loading branch information
= committed Dec 4, 2011
1 parent 0793064 commit 45df416
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 79 deletions.
12 changes: 0 additions & 12 deletions RedBean/Facade.php
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ public static function dup($bean,$trail=array()) {
$trail[$key]=true;
$copy = RedBean_Facade::dispense($type);
$copy->import( $bean->export() );
//$copy->copyMetaFrom( $bean );
$copy->id = 0;
$tables = self::$writer->getTables();
foreach($tables as $table) {
Expand Down Expand Up @@ -967,17 +966,6 @@ public static function genSlots($array) {
}
}

/**
* Installs the default bean formatter with a prefix.
*
* @param string $prefix prefix
*/
public static function prefix($prefix) {
$beanFormatter = new RedBean_DefaultBeanFormatter;
$beanFormatter->setPrefix($prefix);
self::$writer->setBeanFormatter($beanFormatter);
}

/**
* Nukes the entire database.
*/
Expand Down
28 changes: 7 additions & 21 deletions testing/RedUNIT/Mysql/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,7 @@ class RedUNIT_Mysql_Views extends RedUNIT_Mysql {
* @return void
*/
public function run() {
testpack("test views");
$tf = new Fm();
R::$writer->setBeanFormatter($tf);
$this->views("prefix_");
$tf2 = new Fm2();
R::$writer->setBeanFormatter($tf2);
$this->views("prefix_");
}

/**
* Helper function to generate views
*
* @param string $p prefix for views
*/
public function views($p='') {
$p='';
R::nuke();
R::exec(" drop table if exists prefix_bandmember_musician ");
R::exec(" drop table if exists prefix_band_bandmember ");
Expand Down Expand Up @@ -93,7 +79,7 @@ public function views($p='') {
fail();
}
//can we do a simple query?
$nameOfBandWithID1 = R::getCell("select `name` from ".$p."bandlist where ".R::$writer->getIDField("band")." = 1 group by ".R::$writer->getIDField("band"));
$nameOfBandWithID1 = R::getCell("select `name` from ".$p."bandlist where id = 1 group by id");
asrt($nameOfBandWithID1,"The Groofy");
//can we generate a report? list all bandleaders
$bandleaders = R::getAll("select `bandleader_of_bandmember`,`name_of_musician`,`name` AS bandname
Expand All @@ -109,8 +95,8 @@ public function views($p='') {
}
//can we draw statistics?
$inHowManyBandsDoYouPlay = R::getAll("select
`name_of_musician` ,count( distinct `".R::$writer->getIDField("band")."`) as bands
from ".$p."bandlist group by `".R::$writer->getIDField("musician")."_of_musician` order by `name_of_musician` asc
`name_of_musician` ,count( distinct `id`) as bands
from ".$p."bandlist group by `id_of_musician` order by `name_of_musician` asc
");
asrt($inHowManyBandsDoYouPlay[0]["name_of_musician"],"Donald");
asrt($inHowManyBandsDoYouPlay[0]["bands"],'2');
Expand All @@ -121,9 +107,9 @@ public function views($p='') {
//who plays in band 2
//can we make a selectbox
$selectbox = R::getAll("
select m.".R::$writer->getIDField("musician").", m.name, b.".R::$writer->getIDField("band")." as selected from ".$p."musician as m
left join ".$p."bandlist as b on b.".R::$writer->getIDField("musician")."_of_musician = m.".R::$writer->getIDField("musician")." and
b.".R::$writer->getIDField("band")." =2
select m.id, m.name, b.id as selected from ".$p."musician as m
left join ".$p."bandlist as b on b.id_of_musician = m.id and
b.id =2
order by m.name asc
");

Expand Down
34 changes: 10 additions & 24 deletions testing/RedUNIT/Postgres/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,8 @@ class RedUNIT_Postgres_Views extends RedUNIT_Postgres {
* @return void
*/
public function run() {
testpack("test views");
$tf = new Fm();
R::$writer->setBeanFormatter($tf);
$this->views("prefix_");
$tf2 = new Fm2();
R::$writer->setBeanFormatter($tf2);
$this->views("prefix_");
}

/**
* Helper function to test views.
*
* @param string $p prefix to be used for views.
*/
public function views($p='') {
R::nuke();
R::nuke();
$p='';
R::exec(" drop table if exists bandmember_musician CASCADE");
R::exec(" drop table if exists band_bandmember CASCADE");
R::exec(" drop table if exists prefix_bandmember_musician CASCADE");
Expand Down Expand Up @@ -92,13 +78,13 @@ public function views($p='') {
}

//can we do a simple query?
$nameOfBandWithID1 = R::getCell("select name from ".$p."bandlist where ".R::$writer->getIDField("band")." = 1
group by ".R::$writer->getIDField("band").",\"name\"");
$nameOfBandWithID1 = R::getCell("select name from ".$p."bandlist where id = 1
group by id,\"name\"");
asrt($nameOfBandWithID1,"The Groofy");

//can we generate a report? list all bandleaders
$bandleaders = R::getAll("select bandleader_of_bandmember,name_of_musician,\"name\" AS bandname
from ".$p."bandlist where bandleader_of_bandmember = 1 group by id ");
from ".$p."bandlist where bandleader_of_bandmember = 1 ");

foreach($bandleaders as $bl) {
if ($bl["bandname"]=="Wickey Mickey") {
Expand All @@ -110,8 +96,8 @@ public function views($p='') {
}
//can we draw statistics?
$inHowManyBandsDoYouPlay = R::getAll("select
name_of_musician ,count( distinct ".R::$writer->getIDField("band").") as bands
from ".$p."bandlist group by ".R::$writer->getIDField("musician")."_of_musician,name_of_musician order by name_of_musician asc
name_of_musician ,count( distinct id ) as bands
from ".$p."bandlist group by id_of_musician,name_of_musician order by name_of_musician asc
");

asrt($inHowManyBandsDoYouPlay[0]["name_of_musician"],"Donald");
Expand All @@ -124,9 +110,9 @@ public function views($p='') {
//who plays in band 2
//can we make a selectbox
$selectbox = R::getAll("
select m.".R::$writer->getIDField("musician").", m.name, b.".R::$writer->getIDField("band")." as selected from ".$p."musician as m
left join ".$p."bandlist as b on b.".R::$writer->getIDField("musician")."_of_musician = m.".R::$writer->getIDField("musician")." and
b.".R::$writer->getIDField("band")." =2
select m.id, m.name, b.id as selected from ".$p."musician as m
left join ".$p."bandlist as b on b.id_of_musician = m.id and
b.id =2
order by m.name asc
");

Expand Down
29 changes: 7 additions & 22 deletions testing/RedUNIT/Sqlite/Views.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,7 @@ class RedUNIT_Sqlite_Views extends RedUNIT_Sqlite {
* @return void
*/
public function run() {
testpack("test views");
$tf = new Fm();
R::$writer->setBeanFormatter($tf);
$this->views("prefix_");
$tf2 = new Fm2();
R::$writer->setBeanFormatter($tf2);
$this->views("prefix_");
}

/**
* Helper function to test views
*
* @param string $p prefix for views
*/
public function views($p='') {
R::nuke();
$p='';
R::exec(" drop table if exists prefix_bandmember_musician ");
R::exec(" drop table if exists prefix_band_bandmember ");
R::exec(" drop table if exists bandmember_musician ");
Expand Down Expand Up @@ -91,7 +76,7 @@ public function views($p='') {
}

//can we do a simple query?
$nameOfBandWithID1 = R::getCell("select name from ".$p."bandlist where ".R::$writer->getIDField("band")." = 1 group by ".R::$writer->getIDField("band"));
$nameOfBandWithID1 = R::getCell("select name from ".$p."bandlist where id = 1 group by id ");
asrt($nameOfBandWithID1,"The Groofy");

//can we generate a report? list all bandleaders
Expand All @@ -108,8 +93,8 @@ public function views($p='') {
}
//can we draw statistics?
$inHowManyBandsDoYouPlay = R::getAll("select
name_of_musician ,count( distinct ".R::$writer->getIDField("band").") as bands
from ".$p."bandlist group by ".R::$writer->getIDField("musician")."_of_musician order by name_of_musician asc
name_of_musician ,count( distinct id ) as bands
from ".$p."bandlist group by id_of_musician order by name_of_musician asc
");
asrt($inHowManyBandsDoYouPlay[0]["name_of_musician"],"Donald");
asrt($inHowManyBandsDoYouPlay[0]["bands"],'2');
Expand All @@ -120,9 +105,9 @@ public function views($p='') {
//who plays in band 2
//can we make a selectbox
$selectbox = R::getAll("
select m.".R::$writer->getIDField("musician").", m.name, b.".R::$writer->getIDField("band")." as selected from ".$p."musician as m
left join ".$p."bandlist as b on b.".R::$writer->getIDField("musician")."_of_musician = m.".R::$writer->getIDField("musician")." and
b.".R::$writer->getIDField("band")." =2
select m.id, m.name, b.id as selected from ".$p."musician as m
left join ".$p."bandlist as b on b.id_of_musician = m.id and
b.id =2
order by m.name asc
");
asrt($selectbox[0]["name"],"Donald");
Expand Down

0 comments on commit 45df416

Please sign in to comment.