/** * test de rollback de toda la transaccion del save en cascada. */ public function test2() { $a = new AAA(); $c = new CCC(array('attrBBB' => 'sfasdf', 'attrCCC' => 'aa')); $a->addToBs($c); $this->assert(!$a->save(), 'Test rollback ' . print_r($c->getErrors(), true)); }
/** * There previously was a problem with a model being created, then a new custom field added, then if you try * to access the available CustomFieldData it was not available on that model. Since performance3 work * this has been resolve and this test confirms it works ok */ public function testConstructIncompleteIsNotNeeded() { //First create AAA model and save $aaa = new AAA(); $aaa->aaaMember = 'test'; $saved = $aaa->save(); $this->assertTrue($saved); $aaaId = $aaa->id; $aaa->forget(); unset($aaa); //Second create customFieldData $values = array('Item 1', 'Item 2', 'Item 3'); $labels = array('fr' => 'Item 1 fr', 'fr' => 'Item 2 fr', 'fr' => 'Item 3 fr'); $customFieldData = CustomFieldData::getByName('Items'); $customFieldData->serializedData = serialize($values); $customFieldData->serializedLabels = serialize($labels); $this->assertTrue($customFieldData->save()); $id = $customFieldData->id; unset($customFieldData); //Third create a CustomField on AAA $metadata = AAA::getMetadata(); $metadata['AAA']['customFields']['newCustomField'] = 'Items'; $metadata['AAA']['relations']['newCustomField'] = array(RedBeanModel::HAS_ONE, 'CustomField'); AAA::setMetadata($metadata); //Fourth make sure AAA can utilize CustomFieldData after being constructed $aaa = AAA::GetById($aaaId); $this->assertTrue($aaa->isAnAttribute('newCustomField')); $dropDownArray = unserialize($aaa->newCustomField->data->serializedData); $this->assertCount(3, $dropDownArray); //Fifth make sure a new model has the data available $aaa = new AAA(); $this->assertTrue($aaa->isAnAttribute('newCustomField')); $dropDownArray = unserialize($aaa->newCustomField->data->serializedData); $this->assertCount(3, $dropDownArray); }
public function testGetColumnNameByAttribute() { $a = new A(); $columnName = A::getColumnNameByAttribute('name'); $this->assertEquals('name', $columnName); $extendedNoBean = new ExtendsNoBean(); $columnName = ExtendsNoBean::getColumnNameByAttribute('name'); $this->assertEquals('name', $columnName); $aaa = new AAA(); $columnName = AAA::getColumnNameByAttribute('noBean'); $this->assertEquals('redbeanmodel_id', $columnName); }
/** * AAA -> hasOne -> BBB -> hasMany -> FFF -> hasOne -> EEE * @depends testHasOneToHasOneToHasOneUsingRelatedAttributeName */ public function testHasOneToHasManyToHasOne() { $quote = DatabaseCompatibilityUtil::getQuote(); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'bbb', 'relatedModelData' => array('attributeName' => 'fff', 'relatedModelData' => array('attributeName' => 'eee', 'relatedModelData' => array('attributeName' => 'eeeMember', 'operatorType' => 'equals', 'value' => 'somevalue'))))); //Build the query 'where' and 'joins'. Confirm they are as expected $searchAttributeData['structure'] = '1'; //Build the query 'where' and 'joins'. Confirm they are as expected $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('AAA'); $where = ModelDataProviderUtil::makeWhere('AAA', $searchAttributeData, $joinTablesAdapter); $compareWhere = "({$quote}eee{$quote}.{$quote}eeemember{$quote} = 'somevalue')"; $this->assertEquals($compareWhere, $where); $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount()); $this->assertEquals(3, $joinTablesAdapter->getLeftTableJoinCount()); $leftTables = $joinTablesAdapter->getLeftTablesAndAliases(); $this->assertEquals('bbb', $leftTables[0]['tableName']); $this->assertEquals('fff', $leftTables[1]['tableName']); $this->assertEquals('eee', $leftTables[2]['tableName']); //Stringing together some hasMany relations, so we need to select distinct. $this->assertTrue($joinTablesAdapter->getSelectDistinct()); //Now test that the subsetSQL query produced is correct. $subsetSql = AAA::makeSubsetOrCountSqlQuery('aaa', $joinTablesAdapter, 1, 5, $where, null, false, $joinTablesAdapter->getSelectDistinct()); $compareSubsetSql = "select distinct {$quote}aaa{$quote}.{$quote}id{$quote} id "; $compareSubsetSql .= "from {$quote}aaa{$quote} "; $compareSubsetSql .= "left join {$quote}bbb{$quote} on "; $compareSubsetSql .= "{$quote}bbb{$quote}.{$quote}id{$quote} = {$quote}aaa{$quote}.{$quote}bbb_id{$quote} "; $compareSubsetSql .= "left join {$quote}fff{$quote} on "; $compareSubsetSql .= "{$quote}fff{$quote}.{$quote}bbb_id{$quote} = {$quote}bbb{$quote}.{$quote}id{$quote} "; $compareSubsetSql .= "left join {$quote}eee{$quote} on "; $compareSubsetSql .= "{$quote}eee{$quote}.{$quote}id{$quote} = {$quote}fff{$quote}.{$quote}eee_id{$quote} "; $compareSubsetSql .= "where " . $compareWhere . ' '; $compareSubsetSql .= 'limit 5 offset 1'; $this->assertEquals($compareSubsetSql, $subsetSql); //Make sure the sql runs properly. $data = AAA::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct()); }
public function testMultipleManyManysToTheSameModelSearchQueryFormsCorrectly() { $quote = DatabaseCompatibilityUtil::getQuote(); $searchAttributeData = array(); $searchAttributeData['clauses'] = array(1 => array('attributeName' => 'ppManyAssumptive', 'relatedModelData' => array('attributeName' => 'name', 'operatorType' => 'equals', 'value' => 'somevalue')), 2 => array('attributeName' => 'ppManySpecific', 'relatedModelData' => array('attributeName' => 'name', 'operatorType' => 'equals', 'value' => 'somevalue2'))); $searchAttributeData['structure'] = '1 and 2'; //Build the query 'where' and 'joins'. Confirm they are as expected $joinTablesAdapter = new RedBeanModelJoinTablesQueryAdapter('P'); $where = ModelDataProviderUtil::makeWhere('P', $searchAttributeData, $joinTablesAdapter); $compareWhere = "({$quote}pp{$quote}.{$quote}name{$quote} = 'somevalue') and "; $compareWhere .= "({$quote}pp1{$quote}.{$quote}name{$quote} = 'somevalue2')"; $this->assertEquals($compareWhere, $where); $this->assertEquals(0, $joinTablesAdapter->getFromTableJoinCount()); $this->assertEquals(4, $joinTablesAdapter->getLeftTableJoinCount()); $leftTables = $joinTablesAdapter->getLeftTablesAndAliases(); $this->assertEquals('p_pp', $leftTables[0]['tableName']); $this->assertEquals('pp', $leftTables[1]['tableName']); $this->assertEquals('ppmanyspecificlink_p_pp', $leftTables[2]['tableName']); $this->assertEquals('pp', $leftTables[3]['tableName']); //Distinct because MANY_MANY relationships $this->assertTrue($joinTablesAdapter->getSelectDistinct()); //Now test that the subsetSQL query produced is correct. $subsetSql = AAA::makeSubsetOrCountSqlQuery('p', $joinTablesAdapter, 1, 5, $where, null, false, $joinTablesAdapter->getSelectDistinct()); $compareSubsetSql = "select distinct {$quote}p{$quote}.{$quote}id{$quote} id "; $compareSubsetSql .= "from {$quote}p{$quote} "; $compareSubsetSql .= "left join {$quote}p_pp{$quote} on "; $compareSubsetSql .= "{$quote}p_pp{$quote}.{$quote}p_id{$quote} = {$quote}p{$quote}.{$quote}id{$quote} "; $compareSubsetSql .= "left join {$quote}pp{$quote} on "; $compareSubsetSql .= "{$quote}pp{$quote}.{$quote}id{$quote} = {$quote}p_pp{$quote}.{$quote}pp_id{$quote} "; $compareSubsetSql .= "left join {$quote}ppmanyspecificlink_p_pp{$quote} on "; $compareSubsetSql .= "{$quote}ppmanyspecificlink_p_pp{$quote}.{$quote}p_id{$quote} = {$quote}p{$quote}.{$quote}id{$quote} "; $compareSubsetSql .= "left join {$quote}pp{$quote} pp1 on "; $compareSubsetSql .= "{$quote}pp1{$quote}.{$quote}id{$quote} = {$quote}ppmanyspecificlink_p_pp{$quote}.{$quote}pp_id{$quote} "; $compareSubsetSql .= "where " . $compareWhere . ' '; $compareSubsetSql .= 'limit 5 offset 1'; $this->assertEquals($compareSubsetSql, $subsetSql); //Make sure the sql runs properly. $data = P::getSubset($joinTablesAdapter, 0, 5, $where, null, null, $joinTablesAdapter->getSelectDistinct()); }
<?php function __autoload($name) { throw new Exception($name); } try { echo AAA::$a; //zend_fetch_var_address_helper } catch (Exception $e) { try { echo AAA::XXX; //ZEND_FETCH_CONSTANT } catch (Exception $e) { try { echo AAA::foo(); //ZEND_INIT_STATIC_METHOD_CALL } catch (Exception $e) { try { unset(AAA::$a); // ZEND_UNSET_VAR } catch (Exception $e) { try { isset(AAAA::$a); // ZEND_ISSET_ISEMPTY_VAR } catch (Exception $e) { try { $a = array("AAA", "foo"); $a(); //ZEND_INIT_FCALL_BY_NAME } catch (Exception $e) {
{ $input_array = array_keys($input); $first_key = $input_array[0]; $first_value = $input[$first_key]; $min = $first_value; for ($i = 0; $i < count($input_array); $i++) { $key = $input_array[$i]; $value = $input[$key]; if ($value >= $min) { $min = $value; $min_key = $key; } } $min_and_key = array('min' => $min, 'key' => $min_key); return $min_and_key; } function sortMin($input) { $tmp_input = $input; for ($i = 0; $i < count($input); $i++) { $output_fn = $this->findMin($tmp_input); $min = $output_fn['min']; unset($tmp_input[$output_fn['key']]); $output[] = $min; } return $output; } } $aaa1 = new AAA(); $out = $aaa1->sortMin($input); print_r($out);