Skip to content
Browse files

removed bean formatters

  • Loading branch information...
1 parent ee58825 commit 07930645aaaa5d55974eca61caf76d1142894af5 = committed
View
13 RedBean/AssociationManager.php
@@ -90,8 +90,7 @@ public function setUseConstraints( $trueFalse ) {
* @return mixed $id either the link ID or null
*/
protected function associateBeans(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, RedBean_OODBBean $bean) {
- $idfield1 = $this->writer->getIDField($bean1->getMeta('type'));
- $idfield2 = $this->writer->getIDField($bean2->getMeta('type'));
+ $idfield1 = $idfield2 = 'id';
$property1 = $bean1->getMeta('type') . '_id';
$property2 = $bean2->getMeta('type') . '_id';
if ($property1==$property2) $property2 = $bean2->getMeta('type').'2_id';
@@ -148,7 +147,7 @@ protected function associateBeans(RedBean_OODBBean $bean1, RedBean_OODBBean $bea
*/
public function related( RedBean_OODBBean $bean, $type, $getLinks=false, $sql=false) {
$table = $this->getTable( array($bean->getMeta('type') , $type) );
- $idfield = $this->writer->getIDField($bean->getMeta('type'));
+ $idfield = 'id';
if ($type==$bean->getMeta('type')) {
$type .= '2';
$cross = 1;
@@ -207,8 +206,7 @@ public function unassociate(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, $f
$this->oodb->store($bean1);
$this->oodb->store($bean2);
$table = $this->getTable( array($bean1->getMeta('type') , $bean2->getMeta('type')) );
- $idfield1 = $this->writer->getIDField($bean1->getMeta('type'));
- $idfield2 = $this->writer->getIDField($bean2->getMeta('type'));
+ $idfield1 = $idfield2 = 'id';
$type = $bean1->getMeta('type');
if ($type==$bean2->getMeta('type')) {
$type .= '2';
@@ -260,7 +258,7 @@ public function unassociate(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2, $f
public function clearRelations(RedBean_OODBBean $bean, $type) {
$this->oodb->store($bean);
$table = $this->getTable( array($bean->getMeta('type') , $type) );
- $idfield = $this->writer->getIDField($bean->getMeta('type'));
+ $idfield = 'id';
if ($type==$bean->getMeta('type')) {
$property2 = $type.'2_id';
$cross = 1;
@@ -295,8 +293,7 @@ public function clearRelations(RedBean_OODBBean $bean, $type) {
public function areRelated(RedBean_OODBBean $bean1, RedBean_OODBBean $bean2) {
if (!$bean1->getID() || !$bean2->getID()) return false;
$table = $this->getTable( array($bean1->getMeta('type') , $bean2->getMeta('type')) );
- $idfield1 = $this->writer->getIDField($bean1->getMeta('type'));
- $idfield2 = $this->writer->getIDField($bean2->getMeta('type'));
+ $idfield1 = $idfield2 = 'id';
$type = $bean1->getMeta('type');
if ($type==$bean2->getMeta('type')) {
$type .= '2';
View
4 RedBean/Facade.php
@@ -314,7 +314,7 @@ public static function related( RedBean_OODBBean $bean, $type, $sql=null, $value
$keys = self::$associationManager->related( $bean, $type );
if (count($keys)==0) return array();
if (!$sql) return self::batch($type, $keys);
- $idfield = self::$writer->getIDField( $type );
+ $idfield = 'id';
$rows = self::$writer->selectRecord( $type, array($idfield=>$keys),array($sql,$values),false );
return self::$redbean->convertToBeans($type,$rows);
}
@@ -347,7 +347,7 @@ public static function areRelated( RedBean_OODBBean $bean1, RedBean_OODBBean $be
* @return array $beans beans
*/
public static function unrelated(RedBean_OODBBean $bean, $type, $sql=null, $values=array()) {
- $idfield = self::$writer->getIDField( $type );
+ $idfield = 'id';
$keys = self::$associationManager->related( $bean, $type );
$rows = self::$writer->selectRecord( $type, array($idfield=>$keys), array($sql,$values), false, true );
return self::$redbean->convertToBeans($type,$rows);
View
22 RedBean/OODB.php
@@ -97,7 +97,7 @@ public function dispense($type ) {
$bean = new RedBean_OODBBean();
$bean->setBeanHelper($this->beanhelper);
$bean->setMeta('type',$type );
- $idfield = $this->writer->getIDField($bean->getMeta('type'));
+ $idfield = 'id';
$bean->setMeta('sys.idfield',$idfield);
$bean->$idfield = 0;
if (!$this->isFrozen) $this->check( $bean );
@@ -126,7 +126,7 @@ public function setBeanHelper( RedBean_IBeanHelper $beanhelper) {
* @param RedBean_OODBBean $bean
*/
public function check( RedBean_OODBBean $bean ) {
- $idfield = $this->writer->getIDField($bean->getMeta('type'));
+ $idfield ='id';
//Is all meta information present?
if (!isset($bean->$idfield) ) {
@@ -205,7 +205,7 @@ public function find($type,$conditions=array(),$addSQL=null) {
public function tableExists($table) {
//does this table exist?
$tables = $this->writer->getTables();
- return in_array($this->writer->getFormattedTableName($table), $tables);
+ return in_array(($table), $tables);
}
@@ -288,7 +288,7 @@ public function store( RedBean_OODBBean $bean ) {
foreach($bean as $p=>$v) {
if ($v instanceof RedBean_OODBBean) {
$embtype = $v->getMeta('type');
- $idfield = $this->writer->getIDField($embtype);
+ $idfield = 'id';
if (!$v->$idfield || $v->getMeta('tainted')) {
$this->store($v);
}
@@ -321,7 +321,7 @@ public function store( RedBean_OODBBean $bean ) {
if (!$this->isFrozen) $this->check($bean);
//what table does it want
$table = $bean->getMeta("type");
- $idfield = $this->writer->getIDField($table);
+ $idfield = 'id';
if ($bean->getMeta('tainted')) {
//Does table exist? If not, create
@@ -406,7 +406,7 @@ public function store( RedBean_OODBBean $bean ) {
$this->writer->addIndex($bean->getMeta('type'),
'index_foreignkey_'.$embeddedBean->getMeta('type'),
$linkField);
- $this->writer->addFK($bean->getMeta('type'),$embeddedBean->getMeta('type'),$linkField,$this->writer->getIDField($embeddedBean->getMeta('type')));
+ $this->writer->addFK($bean->getMeta('type'),$embeddedBean->getMeta('type'),$linkField,'id');
}
}
@@ -505,7 +505,7 @@ public function load($type,$id) {
}
else {
try {
- $idfield = $this->writer->getIDField($type);
+ $idfield = 'id';
$rows = $this->writer->selectRecord($type,array($idfield=>array($id)));
}catch(RedBean_Exception_SQL $e ) {
if (
@@ -542,7 +542,7 @@ public function load($type,$id) {
* @param RedBean_OODBBean $bean bean you want to remove from database
*/
public function trash( RedBean_OODBBean $bean ) {
- $idfield = $this->writer->getIDField($bean->getMeta('type'));
+ $idfield ='id';
$this->signal('delete',$bean);
foreach($bean as $p=>$v) {
if ($v instanceof RedBean_OODBBean) {
@@ -586,7 +586,7 @@ public function batch( $type, $ids ) {
if (!$ids) return array();
$collection = array();
try {
- $idfield = $this->writer->getIDField($type);
+ $idfield = 'id';
$rows = $this->writer->selectRecord($type,array($idfield=>$ids));
}catch(RedBean_Exception_SQL $e) {
if (!$this->writer->sqlStateIn($e->getSQLState(),
@@ -600,7 +600,7 @@ public function batch( $type, $ids ) {
$this->stash = array();
if (!$rows) return array();
foreach($rows as $row) {
- $this->stash[$row[$this->writer->getIDField($type)]] = $row;
+ $this->stash[$row['id']] = $row;
}
foreach($ids as $id) {
$collection[ $id ] = $this->load( $type, $id );
@@ -620,7 +620,7 @@ public function convertToBeans($type, $rows) {
$collection = array();
$this->stash = array();
foreach($rows as $row) {
- $id = $row[$this->writer->getIDField($type)];
+ $id = $row['id'];
$this->stash[$id] = $row;
$collection[ $id ] = $this->load( $type, $id );
}
View
27 RedBean/OODBBean.php
@@ -52,7 +52,21 @@ class RedBean_OODBBean implements IteratorAggregate, ArrayAccess {
*
* @var null
*/
- public static $fetchType = NULL;
+ private $fetchType = NULL;
+
+ /** Returns the alias for a type
+ *
+ * @param $type aliased type
+ *
+ * @return string $type type
+ */
+ private function getAlias( $type ) {
+ if ($this->fetchType) {
+ $type = $this->fetchType;
+ $this->fetchType = null;
+ }
+ return $type;
+ }
/**
* Sets the Bean Helper. Normally the Bean Helper is set by OODB.
@@ -211,11 +225,10 @@ public function removeProperty( $property ) {
* @return mixed $value
*/
public function &__get( $property ) {
-
if ($this->beanHelper)
$toolbox = $this->beanHelper->getToolbox();
- if (!isset($this->properties[$property])) {
- $fieldLink = $property.'_id';
+ if (!isset($this->properties[$property])) {
+ $fieldLink = $property.'_id';
/**
* All this magic can be become very complex quicly. For instance,
* my PHP CLI produced a segfault while testing this code. Turns out that
@@ -223,8 +236,8 @@ public function &__get( $property ) {
* instead of giving a clue they simply crash and burn isnt that nice?
*/
if (isset($this->$fieldLink) && $fieldLink != $this->getMeta('sys.idfield')) {
- $this->setMeta('tainted',true);
- $type = $toolbox->getWriter()->getAlias($property);
+ $this->setMeta('tainted',true);
+ $type = $this->getAlias($property);
$targetType = $this->properties[$fieldLink];
$bean = $toolbox->getRedBean()->load($type,$targetType);
//return $bean;
@@ -434,7 +447,7 @@ public function offsetGet($offset) {
* @return RedBean_OODBBean
*/
public function fetchAs($type) {
- self::$fetchType = $type;
+ $this->fetchType = $type;
return $this;
}
View
53 RedBean/QueryWriter.php
@@ -46,15 +46,6 @@
const C_SQLSTATE_INTEGRITY_CONSTRAINT_VIOLATION = 3;
/**
- * Returns the table to store beans of a given type.
- *
- * @param string $type type of bean you want the table name of
- *
- * @return string $tableName name of the table where bean records are stored
- */
- public function getFormattedTableName($type);
-
- /**
* Returns the tables that are in the database.
*
* @return array $arrayOfTables list of tables
@@ -183,17 +174,7 @@ public function selectRecord($type, $conditions, $addSql = null, $delete = false
*/
public function addUniqueIndex($type,$columns);
- /**
- * Returns the property that contains the Primary Key ID in an
- * OODBBean instance.
- *
- * @param string $tableOfTheBean
- *
- * @return void
- */
- public function getIDField($type);
-
-
+
/**
* This method should check whether the SQL state is in the list of specified states
* and returns true if it does appear in this list or false if it
@@ -231,17 +212,6 @@ public function count($type);
/**
- * This method should set the new bean formatter. A bean formatter is an instance
- * of the class BeanFormatter that determines how a bean should be represented
- * in the database.
- *
- * @param RedBean_IBeanFormatter $beanFormatter bean format
- *
- * @return void
- */
- public function setBeanFormatter(RedBean_IBeanFormatter $beanFormatter);
-
- /**
* This method should create a view with name $viewID and
* based on the reference type. A list of types
* will be provided in the second argument. This method should create
@@ -347,27 +317,6 @@ public function addFK( $type, $targetType, $field, $targetField);
* @return void
*/
public function addIndex($type, $name, $column);
-
-
- /**
- * This method should return the true type name of a given alias.
- * For instance 'magazine' -> 'book' if magazine is just another name
- * of the real 'type' called book.
- *
- * @param string $type type
- *
- * @return string $realType type
- */
- public function getAlias($type);
-
-
- /**
- * This method should return the datatype to be used for primary key IDS and
- * foreign keys. Return one if the data type constants.
- *
- * @return integer $const data type to be used for IDS.
- */
- public function getTypeForID();
public function getValue();
View
70 RedBean/QueryWriter/AQueryWriter.php
@@ -27,14 +27,6 @@
*/
protected $fcache = array();
- /**
- *
- * @var RedBean_IBeanFormatter
- * Holds the bean formatter to be used for applying
- * table schema.
- */
- public $tableFormatter;
-
/**
* @var array
@@ -75,7 +67,7 @@
* subclass to achieve this.
*/
public function __construct() {
- $this->tableFormatter = new RedBean_DefaultBeanFormatter();
+
}
/**
@@ -86,7 +78,6 @@ public function __construct() {
* @return string table name
*/
public function safeTable($name, $noQuotes = false) {
- $name = $this->getFormattedTableName($name);
$name = $this->check($name);
if (!$noQuotes) $name = $this->noKW($name);
return $name;
@@ -116,45 +107,9 @@ protected function getInsertSuffix ($table) {
return "";
}
- /**
- * Returns the string identifying a table for a given type.
- *
- * @param string $type
- *
- * @return string $table
- */
- public function getFormattedTableName($type) {
- return $this->tableFormatter->formatBeanTable($type);
- }
-
- /**
- * Returns an alias type based on a reference type. If the writer has
- * a tableformatter this method will pass the type to the writer's alias
- * function to get the alias of the type back.
- *
- * @param string $type type you want an alias for
- *
- * @return
- */
- public function getAlias($type) {
- return $this->tableFormatter->getAlias($type);
- }
/**
- * Sets the new bean formatter. A bean formatter is an instance
- * of the class BeanFormatter that determines how a bean should be represented
- * in the database.
- *
- * @param RedBean_IBeanFormatter $beanFormatter bean format
- *
- * @return void
- */
- public function setBeanFormatter( RedBean_IBeanFormatter $beanFormatter ) {
- $this->tableFormatter = $beanFormatter;
- }
-
- /**
* Get sql column type.
*
* @param integer $type constant
@@ -166,18 +121,6 @@ public function getFieldType( $type = "" ) {
}
/**
- * Returns the column name that should be used
- * to store and retrieve the primary key ID.
- *
- * @param string $type type of bean to get ID Field for
- *
- * @return string $idfieldtobeused ID field to be used for this type of bean
- */
- public function getIDField( $type ) {
- return $this->tableFormatter->formatBeanID($type);
- }
-
- /**
* Checks table name or column name.
*
* @param string $table table string
@@ -249,7 +192,7 @@ public function updateRecord( $type, $updatevalues, $id=null) {
return $this->insertRecord($table,$insertcolumns,array($insertvalues));
}
if ($id && !count($updatevalues)) return $id;
- $idfield = $this->safeColumn($this->getIDField($table));
+
$table = $this->safeTable($table);
$sql = "UPDATE $table SET ";
$p = $v = array();
@@ -257,7 +200,7 @@ public function updateRecord( $type, $updatevalues, $id=null) {
$p[] = " {$this->safeColumn($uv["property"])} = ? ";
$v[]=$uv["value"];
}
- $sql .= implode(",", $p ) ." WHERE $idfield = ".intval($id);
+ $sql .= implode(",", $p ) ." WHERE id = ".intval($id);
$this->adapter->exec( $sql, $v );
return $id;
}
@@ -274,7 +217,7 @@ public function updateRecord( $type, $updatevalues, $id=null) {
*/
protected function insertRecord( $table, $insertcolumns, $insertvalues ) {
$default = $this->defaultValue;
- $idfield = $this->safeColumn($this->getIDField($table));
+ $idfield = 'id';
$suffix = $this->getInsertSuffix($table);
$table = $this->safeTable($table);
if (count($insertvalues)>0 && is_array($insertvalues[0]) && count($insertvalues[0])>0) {
@@ -553,9 +496,8 @@ public function addConstraint( RedBean_OODBBean $bean1, RedBean_OODBBean $bean2,
$writer = $this;
$adapter = $this->adapter;
$table = $this->getAssocTableFormat( array( $table1,$table2) );
- $idfield1 = $writer->getIDField($bean1->getMeta('type'));
- $idfield2 = $writer->getIDField($bean2->getMeta('type'));
-
+ $idfield1 = $idfield2 = 'id';
+
$property1 = $bean1->getMeta('type') . '_id';
$property2 = $bean2->getMeta('type') . '_id';
if ($property1==$property2) $property2 = $bean2->getMeta("type").'2_id';
View
10 RedBean/QueryWriter/MySQL.php
@@ -230,7 +230,7 @@ public function getTables() {
* @return void
*/
public function createTable( $table ) {
- $idfield = $this->safeColumn($this->getIDfield($table));
+ $idfield = 'id';
$table = $this->safeTable($table);
$sql = "
CREATE TABLE $table (
@@ -424,7 +424,7 @@ protected function constrain($table, $table1, $table2, $property1, $property2, $
$fks = $adapter->getCell("
SELECT count(*)
FROM information_schema.KEY_COLUMN_USAGE
- WHERE TABLE_SCHEMA ='$db' AND TABLE_NAME ='".$writer->getFormattedTableName($table)."' AND
+ WHERE TABLE_SCHEMA ='$db' AND TABLE_NAME ='".($table)."' AND
CONSTRAINT_NAME <>'PRIMARY' AND REFERENCED_TABLE_NAME is not null
");
//already foreign keys added in this association table
@@ -439,11 +439,7 @@ protected function constrain($table, $table1, $table2, $property1, $property2, $
$writer->widenColumn($table, $property2, RedBean_QueryWriter_MySQL::C_DATATYPE_UINT32);
}
- $idfield1 = $writer->getIDField($table1);
- $idfield2 = $writer->getIDField($table2);
- $table = $writer->getFormattedTableName($table);
- $table1 = $writer->getFormattedTableName($table1);
- $table2 = $writer->getFormattedTableName($table2);
+ $idfield1 = $idfield2 = 'id';
$sql = "
ALTER TABLE ".$writer->noKW($table)."
ADD FOREIGN KEY($property1) references `$table1`($idfield1) ON DELETE CASCADE;
View
10 RedBean/QueryWriter/PostgreSQL.php
@@ -112,7 +112,7 @@ public function getTypeForID() {
* @return string $sql SQL Snippet
*/
protected function getInsertSuffix($table) {
- return "RETURNING ".$this->getIDField($table);
+ return "RETURNING id ";
}
/**
@@ -142,9 +142,8 @@ public function getTables() {
* @param string $table table to create
*/
public function createTable( $table ) {
- $idfield = $this->getIDfield($table);
$table = $this->safeTable($table);
- $sql = " CREATE TABLE $table ($idfield SERIAL PRIMARY KEY); ";
+ $sql = " CREATE TABLE $table (id SERIAL PRIMARY KEY); ";
$this->adapter->exec( $sql );
}
@@ -399,11 +398,6 @@ protected function constrain($table, $table1, $table2, $property1, $property2, $
$rows = $adapter->get( $sql );
if (!count($rows)) {
-
- $table = $writer->getFormattedTableName($table);
- $table1 = $writer->getFormattedTableName($table1);
- $table2 = $writer->getFormattedTableName($table2);
-
if (!$dontCache) $this->fkcache[ $fkCode ] = true;
$sql1 = "ALTER TABLE \"$table\" ADD CONSTRAINT
{$fkCode}a FOREIGN KEY ($property1)
View
10 RedBean/QueryWriter/SQLiteT.php
@@ -135,7 +135,6 @@ public function scanType( $value, $flagSpecial=false ) {
* @param integer $type type
*/
public function addColumn( $table, $column, $type) {
- $table = $this->getFormattedTableName($table);
$column = $this->check($column);
$table = $this->check($table);
$type=$this->typeno_sqltype[$type];
@@ -183,7 +182,7 @@ private function quote( $items ) {
public function widenColumn( $type, $column, $datatype ) {
$table = $this->safeTable($type,true);
$column = $this->safeColumn($column,true);
- $idfield = $this->safeColumn($this->getIDfield($type),true);
+ $idfield = 'id';
$newtype = $this->typeno_sqltype[$datatype];
$oldColumns = $this->getColumns($type);
$oldColumnNames = $this->quote(array_keys($oldColumns));
@@ -228,7 +227,7 @@ public function getTables() {
* @param string $table table
*/
public function createTable( $table ) {
- $idfield = $this->safeColumn($this->getIDfield($table));
+ $idfield = 'id';
$table = $this->safeTable($table);
$sql = "
CREATE TABLE $table ( $idfield INTEGER PRIMARY KEY AUTOINCREMENT )
@@ -334,7 +333,7 @@ protected function buildFK($type, $targetType, $field, $targetField,$constraint=
$targetTable = $this->safeTable($targetType,true);
$field = $this->safeColumn($field,true);
$targetField = $this->safeColumn($targetField,true);
- $idfield = $this->safeColumn($this->getIDfield($type),true);
+ $idfield = 'id';
$oldColumns = $this->getColumns($type);
$oldColumnNames = $this->quote(array_keys($oldColumns));
$newTableDefStr='';
@@ -400,8 +399,7 @@ protected function constrain($table, $table1, $table2, $property1, $property2,
try{
$writer = $this;
$adapter = $this->adapter;
- $idfield1 = $writer->getIDField($table1);
- $idfield2 = $writer->getIDField($table2);
+ $idfield1 = $idfield2 = 'id';
$this->buildFK($table,$table1,$property1,$idfield1,true);
$this->buildFK($table,$table2,$property2,$idfield2,true);
return true;
View
6 RedBean/ViewManager.php
@@ -69,17 +69,17 @@ public function createView($viewID,$refType,$types) {
if (isset($tables[$connectionTable])) {
//this connection exists
$srcPoint = $this->writer->safeTable($connection).'.'.$this->writer->safeColumn($currentTable.'_id'); //i.e. partic_project.project_id
- $dstPoint = $this->writer->safeTable($currentTable).'.'.$this->writer->safeColumn($this->writer->getIDField($currentTable)); //i.e. project.id
+ $dstPoint = $this->writer->safeTable($currentTable).'.id'; //i.e. project.id
$joins[$connection] = array($srcPoint,$dstPoint);
//now join the type
$srcPoint = $this->writer->safeTable($connection).'.'.$this->writer->safeColumn($t.'_id');
- $dstPoint = $this->writer->safeTable($t).'.'.$this->writer->safeColumn($this->writer->getIDField($t));
+ $dstPoint = $this->writer->safeTable($t).'.id';
$joins[$t] = array($srcPoint,$dstPoint);
}
else {
//this connection does not exist
$srcPoint = $this->writer->safeTable($t).'.'.$this->writer->safeColumn($currentTable.'_id');
- $dstPoint = $this->writer->safeTable($currentTable).'.'.$this->writer->safeColumn($this->writer->getIDField($currentTable));
+ $dstPoint = $this->writer->safeTable($currentTable).'.id';
$joins[$t] = array($srcPoint,$dstPoint);
}
}
View
2 replica.xml
@@ -32,8 +32,6 @@
<item type="php">RedBean/ExtAssociationManager.php</item>
<item type="php">RedBean/ViewManager.php</item>
<item type="php">RedBean/Setup.php</item>
- <item type="php">RedBean/IBeanFormatter.php</item>
- <item type="php">RedBean/DefaultBeanFormatter.php</item>
<item type="php">RedBean/IModelFormatter.php</item>
<item type="php">RedBean/IBeanHelper.php</item>
<item type="php">RedBean/BeanHelperFacade.php</item>
View
1 testing/RedUNIT.php
@@ -24,7 +24,6 @@
*/
public function prepare() {
R::freeze(false);
- R::$writer->setBeanFormatter(new DF);
RedBean_ModelHelper::setModelFormatter(new DefaultModelFormatter);
R::nuke();
View
63 testing/RedUNIT/Base/Aliasing.php
@@ -144,70 +144,7 @@ public function run() {
catch(Exception $e){fail();}
- //test views icw aliases and n1
R::nuke();
- $book = R::dispense('book');
- $page = R::dispense('page');
- $book->title = 'my book';
- $page->title = 'my page';
- $book->ownPage[] = $page;
- R::store($book);
- R::view('library2','book,page');
- $l2 = R::getRow('select * from library2 limit 1');
- asrt($l2['title'],'my book');
- asrt($l2['title_of_page'],'my page');
-
-
-
- $formatter = new Aliaser2();
- R::$writer->setBeanFormatter($formatter);
- $message = R::dispense('message');
- list($creator,$recipient) = R::dispense('user',2);
- $recipient->name = 'r';
- $creator->name = 'c';
- $message->recipient = $recipient;
- $message->creator = $creator;
- $id = R::store($message);
- $message = R::load('message', $id);
- $recipient = $message->recipient;
-
-
- R::nuke();
-
-
- R::$writer->setBeanFormatter(new Alias3);
-
- list($p1,$p2,$p3) = R::dispense('person',3);
- $p1->name = 'Joe';
- $p2->name = 'Jack';
- $p3->name = 'James';
- $fm = R::dispense('familymember');
- $fr = R::dispense('friend');
- $fr->buddy = $p1;
- $fm->familyman = $p2;
- $p3->ownFamilymember[] = $fm;
- $p3->ownFriend[] = $fr;
- $id = R::store($p3);
-
-
- $friend = R::load('person', $id);
- asrt(reset($friend->ownFamilymember)->familyman->name,'Jack');
- asrt(reset($friend->ownFriend)->buddy->name,'Joe');
-
- $Jill = R::dispense('person');
- $Jill->name = 'Jill';
- $familyJill = R::dispense('familymember');
- $friend->ownFamilymember[] = $familyJill;
- R::store($friend);
- $friend = R::load('person', $id);
- asrt(count($friend->ownFamilymember),2);
- array_pop($friend->ownFamilymember);
- R::store($friend);
- $friend = R::load('person', $id);
- asrt(count($friend->ownFamilymember),1);
-
- R::nuke();
- R::$writer->setBeanFormatter(new RedBean_DefaultBeanFormatter);
$message = R::dispense('message');
$message->subject = 'Roommate agreement';
list($sender,$recipient) = R::dispense('person',2);
View
15 testing/RedUNIT/Base/Export.php
@@ -154,19 +154,17 @@ public function run() {
$v3 = R::load('village',$v3->getID());
-
- R::$toolbox->getWriter()->setBeanFormatter( new ExportBeanFormatter );
+ /*
$e->loadSchema();
- //print_r($e->export($v2));
$export = $e->export($v2);
$out = json_encode($export);
- $expected = '{"2":{"id":"2","name":"Sandy winds","world_id":null,"universe_id":"1","universe":{"1":{"id":"1","name":"Middle Earth","ownVillage":{"1":{"id":"1","name":"Ole Town","world_id":"1","universe_id":null,"world":{"1":null},"ownBuilding":{"1":{"id":"1","kind":"pub","village_id":"1","village":{"1":null},"ownAmulet":{"1":{"id":"1","name":"4","building_id":"1","building":{"1":null}}}},"2":{"id":"2","kind":"tower","village_id":"1","village":{"1":null},"ownAmulet":[]}},"sharedArmy":[]}}}},"ownBuilding":{"3":{"id":"3","kind":"mill","village_id":"2","village":{"2":null},"ownAmulet":[]},"4":{"id":"4","kind":"shed","village_id":"2","village":{"2":null},"ownAmulet":[]},"5":{"id":"5","kind":"shop","village_id":"2","village":{"2":null},"ownAmulet":{"2":{"id":"2","name":"3","building_id":"5","building":{"5":null}}}}},"sharedArmy":{"1":{"id":"1","name":"Army 1","sharedVillage":{"2":null}},"2":{"id":"2","name":"Army 2","sharedVillage":{"2":null,"3":{"id":"3","name":"Autumn Hill","world_id":null,"universe_id":null,"ownBuilding":{"6":{"id":"6","kind":"farm","village_id":"3","village":{"3":null},"ownAmulet":{"3":{"id":"3","name":"1","building_id":"6","building":{"6":null}},"4":{"id":"4","name":"2","building_id":"6","building":{"6":null}}}}},"sharedArmy":{"2":null}}}}}}}';
+ $expected = '{"2":{"id":"2","name":"Sandy winds","world_id":null,"world_id":"1","universe":{"1":{"id":"1","name":"Middle Earth","ownVillage":{"1":{"id":"1","name":"Ole Town","world_id":"1","universe_id":null,"world":{"1":null},"ownBuilding":{"1":{"id":"1","kind":"pub","village_id":"1","village":{"1":null},"ownAmulet":{"1":{"id":"1","name":"4","building_id":"1","building":{"1":null}}}},"2":{"id":"2","kind":"tower","village_id":"1","village":{"1":null},"ownAmulet":[]}},"sharedArmy":[]}}}},"ownBuilding":{"3":{"id":"3","kind":"mill","village_id":"2","village":{"2":null},"ownAmulet":[]},"4":{"id":"4","kind":"shed","village_id":"2","village":{"2":null},"ownAmulet":[]},"5":{"id":"5","kind":"shop","village_id":"2","village":{"2":null},"ownAmulet":{"2":{"id":"2","name":"3","building_id":"5","building":{"5":null}}}}},"sharedArmy":{"1":{"id":"1","name":"Army 1","sharedVillage":{"2":null}},"2":{"id":"2","name":"Army 2","sharedVillage":{"2":null,"3":{"id":"3","name":"Autumn Hill","world_id":null,"universe_id":null,"ownBuilding":{"6":{"id":"6","kind":"farm","village_id":"3","village":{"3":null},"ownAmulet":{"3":{"id":"3","name":"1","building_id":"6","building":{"6":null}},"4":{"id":"4","name":"2","building_id":"6","building":{"6":null}}}}},"sharedArmy":{"2":null}}}}}}}';
asrt(preg_replace("/\W/","",trim($out)),preg_replace("/\W/","",trim($expected)));
$export=R::exportAll($v2,true);
$out = json_encode($export);
asrt(preg_replace("/\W/","",trim($out)),preg_replace("/\W/","",trim($expected)));
-
+ */
testpack("Test Export All");
list($p1,$p2) = R::dispense("page",2);
@@ -200,13 +198,6 @@ public function run() {
asrt(count($objs),2);
foreach($objs as $o) asrt(is_object($o),true);
- testpack("Test Simple Facade Prefix");
- droptables();
- R::prefix('bla');
- $t = R::dispense('testje');
- R::store($t);
- $tables = R::$writer->getTables();
- asrt(true,in_array('blatestje',$tables));
}
View
4 testing/RedUNIT/Base/Fuse.php
@@ -25,7 +25,7 @@ public function run() {
$writer = $toolbox->getWriter();
$redbean = $toolbox->getRedBean();
$pdo = $adapter->getDatabase();
- R::$writer->setBeanFormatter(new MyBeanFormatter());
+
$blog = R::dispense('blog');
$blog->title = 'testing';
$blog->blog = 'tesing';
@@ -34,7 +34,7 @@ public function run() {
$post = R::dispense("post");
$post->message = "hello";
R::associate($blog,$post);
- $a = R::getAll("select * from ".tbl("blog")." ");
+ $a = R::getAll("select * from blog ");
RedBean_ModelHelper::setModelFormatter(new mymodelformatter);
$w = R::dispense("weirdo");
asrt($w->blah(),"yes!");
View
16 testing/RedUNIT/Base/Graph.php
@@ -253,22 +253,6 @@ public function run() {
- //Test combination of bean formatter and N1
-
- R::$writer->setBeanFormatter(new N1AndFormatter);
- R::nuke();
- $book=R::dispense('book');
- $page=R::dispense('page');
- $book->ownPage[] = $page;
- $bookid = R::store($book);
- pass(); //survive?
- asrt($page->getMeta('cast.book_id'),'id');
- $book = R::load('book',$bookid);
- asrt(count($book->ownPage),1);
- $book->ownPage[] = R::dispense('page');
- $bookid = R::store($book);
- $book = R::load('book',$bookid);
- asrt(count($book->ownPage),2);
//Test whether a nested bean will be saved if tainted
R::nuke();
View
4 testing/RedUNIT/Base/Relations.php
@@ -215,13 +215,11 @@ public function run() {
asrt(end($book->ownPage)->title,'yet another page 4');
testids($book->ownPage);
//test with alias format
- $formatter = new Aliaser();
- R::$writer->setBeanFormatter($formatter);
$book3->cover = $page6;
$idb3=R::store($book3);
$book3=R::load('book',$idb3);
+ $justACover = $book3->fetchAs('page')->cover;
asrt(($book3->cover instanceof RedBean_OODBBean),true);
- $justACover = $book3->cover;
asrt($justACover->title,'cover1');
asrt(isset($book3->page),false);//no page property
//test doubling and other side effects ... should not occur..
View
119 testing/helpers/classes.php
@@ -27,68 +27,7 @@ public function onEvent($event, $info) {
$this->info = $info;
}
}
-/**
- * Shared helper class for tests.
- * A Basic Bean Formatter.
- */
-class BF extends RedBean_DefaultBeanFormatter {
- public function formatBeanTable($t) {
- return '_'.$t;
- }
-}
-/**
- * Shared helper class for tests.
- * A Basic Bean Formatter.
- */
-class Fm implements RedBean_IBeanFormatter{
- public function formatBeanTable($table) {return "prefix_$table";}
- public function formatBeanID( $table ) {return $table."__id";}
- public function getAlias($a){return $a;}
-}
-/**
- * Shared helper class for tests.
- * A Basic Bean Formatter.
- */
-class Fm2 implements RedBean_IBeanFormatter{
- public function formatBeanTable($table) {return "prefix_$table";}
- public function formatBeanID( $table ) {return $table."_id";}
- public function getAlias($a){return $a;}
-}
-/**
- * Shared helper class for tests.
- * A Basic Bean Formatter.
- */
-class TestFormatter implements RedBean_IBeanFormatter{
- public function formatBeanTable($table) {return "xx_$table";}
- public function formatBeanID( $table ) {return "id";}
- public function getAlias($a){ return $a; }
-}
-/**
- * Shared helper class for tests.
- * A Basic Bean Formatter.
- */
-class MyTableFormatter implements RedBean_IBeanFormatter{
- public function formatBeanTable($table) {
- return "xx_$table";
- }
- public function formatBeanID( $table ) {
- return "id";
- }
- public function getAlias($a){ return '__';}
-}
-/**
- * Shared helper class for tests.
- * A Basic Bean Formatter.
- */
-class MyBeanFormatter implements RedBean_IBeanFormatter{
- public function formatBeanTable($table) {
- return "cms_$table";
- }
- public function formatBeanID( $table ) {
- return "{$table}_id"; // append table name to id. The table should not inclide the prefix.
- }
- public function getAlias($a){ return '__'.$a; }
-}
+
/**
* Shared helper class for tests.
* A Basic Model Formatter for FUSE tests.
@@ -114,20 +53,7 @@ public function formatModel($model) {
class my_weird_weirdo_model extends RedBean_SimpleModel {
public function blah(){ return "yes!"; }
}
-/**
- * Shared helper class for tests.
- * Default Bean Formatter to reset bean formatting rules for Format tests.
- */
-class DF extends RedBean_DefaultBeanFormatter {}
-/**
- * Shared helper class for tests.
- * Bean Formatter to test aliasing of beans in N:1 relations. See Aliasing tests.
- */
-class Aliaser extends RedBean_DefaultBeanFormatter {
- public function getAlias($a){
- if ($a=='cover') return 'page'; else return $a;
- }
-}
+
/**
* Shared helper class for tests.
* A test model to test FUSE functions.
@@ -140,46 +66,7 @@ public function update() {
}
}
}
-/**
- * Shared helper class for tests.
- * Bean Formatter to test aliasing of beans in N:1 relations. See Aliasing tests.
- */
-class N1AndFormatter implements RedBean_IBeanFormatter{
- public function formatBeanTable($table) {return "xy_$table";}
- public function formatBeanID( $table ) {return "theid";}
- public function getAlias($a){ return $a; }
-}
-/**
- * Shared helper class for tests.
- * Bean Formatter to test aliasing of beans in N:1 relations. See Aliasing tests.
- */
-class Aliaser2 implements RedBean_IBeanFormatter {
- public function formatBeanID($t){ return 'id'; }
- public function formatBeanTable($t){ return $t; }
- public function getAlias($a){
- if ($a=='creator' || $a=='recipient') return 'user';
- return $a;
- }
-}
-/**
- * Shared helper class for tests.
- * Bean Formatter to test aliasing of beans in N:1 relations. See Aliasing tests.
- */
-class Alias3 extends RedBean_DefaultBeanFormatter {
- public function getAlias($type) {
- if ($type=='familyman' || $type=='buddy') return 'person';
- return $type;
- }
-}
-/**
- * Shared helper class for tests.
- * Bean Formatter to test aliasing of beans in N:1 relations. See Aliasing tests.
- */
-class ExportBeanFormatter extends RedBean_DefaultBeanFormatter{
- public function getAlias( $type ) {
- if ($type == 'universe') return 'world'; else return $type;
- }
-}
+
/**
* Shared helper class for tests.
* A Model class for testing Models/FUSE and related features.
View
1 testing/helpers/selector.php
@@ -74,7 +74,6 @@ function activate_driver($d) {
'Base/Facade',
'Base/Unrelated',
'Base/Fuse',
- 'Base/Formats',
'Base/Tags',
'Base/Graph',
'Base/Null',

0 comments on commit 0793064

Please sign in to comment.
Something went wrong with that request. Please try again.