1<?php 2 3class Doctrine_Ticket_1323b2_TestCase extends Doctrine_UnitTestCase { 4 public function prepareTables() { 5 $this->tables = array(); 6 $this->tables[] = "Concept"; 7 $this->tables[] = "ConceptRelation"; 8 parent::prepareTables(); 9 } 10 11 public function prepareData() {} 12 13 /** 14 * setting some polyhierarchical relations 15 */ 16 public function resetData() 17 { 18 $q = Doctrine_Query::create(); 19 $q->delete()->from("ConceptRelation")->execute(); 20 $q = Doctrine_Query::create(); 21 $q->delete()->from("Concept")->execute(); 22 23 $concepts = array("Woodworking", "Metalworking", 24 "Submetalworking 1", "Submetalworking 2", 25 "Subwoodworking 1", "Subwoodworking 2", 26 "Surfaceworking", 27 "drilled", "welded", "turned"); 28 29 foreach ($concepts as $concept) { 30 $c = new Concept(); 31 $c->identifier = $concept; 32 $c->status = "approved"; 33 $c->source = "test"; 34 $c->created = "today"; 35 $c->creator = "me"; 36 $c->creationIdentifier = "nothing"; 37 $c->save(); 38 } 39 $w = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Woodworking"); 40 $sw1 = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Subwoodworking 1"); 41 $sw2 = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Subwoodworking 2"); 42 $m = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Metalworking"); 43 $sm1 = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Submetalworking 1"); 44 $sm2 = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Submetalworking 2"); 45 $d = Doctrine_Core::getTable("Concept")->findOneByIdentifier("drilled"); 46 $wd = Doctrine_Core::getTable("Concept")->findOneByIdentifier("welded"); 47 $t = Doctrine_Core::getTable("Concept")->findOneByIdentifier("turned"); 48 $s = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Surfaceworking"); 49 50 $w->narrowerConcepts[] = $sw1; 51 $w->narrowerConcepts[] = $sw2; 52 $w->save(); 53 54 $sw1->narrowerConcepts[] = $s; 55 $sw1->narrowerConcepts[] = $d; 56 $sw1->narrowerConcepts[] = $t; 57 $sw1->save(); 58 59 $sw2->narrowerConcepts[] = $d; 60 $sw2->save(); 61 62 $m->narrowerConcepts[] = $sm1; 63 $m->narrowerConcepts[] = $sm2; 64 $m->save(); 65 66 $sm1->narrowerConcepts[] = $wd; 67 $sm1->narrowerConcepts[] = $s; 68 $sm1->save(); 69 70 $sm2->narrowerConcepts[] = $t; 71 $sm2->save(); 72 73 $s->narrowerConcepts[] = $t; 74 $s->narrowerConcepts[] = $d; 75 $s->save(); 76 } 77 78 /** 79 * this test will fail ... 80 */ 81 public function testFAIL() { 82 $this->resetData(); 83 84 ConceptRelation::showAllRelations(); 85 //lets count all relations 86 $relCount = ConceptRelation::countAll(); 87 88 $oRecord = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Surfaceworking"); 89 $oRecord->identifier = "MySurfaceworking"; 90 $oRecord->save(); 91 92 ConceptRelation::showAllRelations(); 93 94 // we did not change any relations, so we assume this test to be passed 95 $this->assertEqual(ConceptRelation::countAll(), $relCount); 96 // -> where do the additional relations come from ??? 97 } 98 99 /* 100 * ... while this test is ok (since we dont save anything) 101 */ 102 public function testOK() { 103 $this->resetData(); 104 105 ConceptRelation::showAllRelations(); 106 //lets count all relations 107 $relCount = ConceptRelation::countAll(); 108 109 $oRecord = Doctrine_Core::getTable("Concept")->findOneByIdentifier("Surfaceworking"); 110 $oRecord->identifier = "MySurfaceworking"; 111 // $oRecord->save(); --> only this line differs !!! 112 113 ConceptRelation::showAllRelations(); 114 115 // we did not change any relations, so we assume this test to be passed 116 $this->assertEqual(ConceptRelation::countAll(), $relCount); 117 } 118} 119 120 121 122 123 124 125 126 127/** 128 * This class has been auto-generated by the Doctrine ORM Framework 129 */ 130class BaseConcept extends Doctrine_Record 131{ 132 public function setTableDefinition() 133 { 134 $this->setTableName('concepts'); 135 $this->hasColumn('id', 'integer', 4, array('primary' => true, 'autoincrement' => true, 'type' => 'integer', 'length' => '4')); 136 $this->hasColumn('vok_id as vokId', 'integer', 4, array('type' => 'integer', 'length' => '4')); 137 $this->hasColumn('identifier', 'string', 255, array('notnull' => true, 'type' => 'string', 'length' => '255')); 138 $this->hasColumn('status', 'string', 20, array('notnull' => true, 'type' => 'string', 'length' => '20')); 139 $this->hasColumn('source', 'string', 255, array('notnull' => true, 'type' => 'string', 'length' => '255')); 140 $this->hasColumn('created_on as created', 'string', 255, array('notnull' => true, 'type' => 'string', 'length' => '255')); 141 $this->hasColumn('creator', 'string', 255, array('notnull' => true, 'type' => 'string', 'length' => '255')); 142 $this->hasColumn('creation_identifier as creationIdentifier', 'string', 255, array('notnull' => true, 'type' => 'string', 'length' => '255')); 143 144 $this->option('type', 'INNODB'); 145 $this->option('collate', 'utf8_unicode_ci'); 146 $this->option('charset', 'utf8'); 147 } 148 149 public function setUp() 150 { 151 $this->hasMany('Concept as broaderConcepts', array('refClass' => 'ConceptRelation', 152 'local' => 'concept_id', 153 'foreign' => 'parent_concept_id', 154 'refClassRelationAlias' => 'broaderLinks')); 155 156 157 $this->hasMany('Concept as narrowerConcepts', array('refClass' => 'ConceptRelation', 158 'local' => 'parent_concept_id', 159 'foreign' => 'concept_id', 160 'refClassRelationAlias' => 'narrowerLinks')); 161 } 162} 163 164/** 165 * This class has been auto-generated by the Doctrine ORM Framework 166 */ 167class BaseConceptRelation extends Doctrine_Record 168{ 169 public function setTableDefinition() 170 { 171 $this->setTableName('concepts_x_concepts'); 172 $this->hasColumn('concept_id as conceptId', 'integer', 4, array('type' => 'integer', 'notnull' => true, 'length' => '4', 'primary' => true)); 173 $this->hasColumn('parent_concept_id as conceptIdParent', 'integer', 4, array('type' => 'integer', 'notnull' => true, 'length' => '4', 'primary' => true)); 174 175 $this->option('type', 'INNODB'); 176 $this->option('collate', 'utf8_unicode_ci'); 177 $this->option('charset', 'utf8'); 178 } 179 180 public function setUp() 181 { 182 $this->hasOne('Concept as concept', array('local' => 'concept_id', 183 'foreign' => 'id')); 184 185 $this->hasOne('Concept as broaderConcept', array('local' => 'parent_concept_id', 186 'foreign' => 'id')); 187 } 188} 189 190 191/** 192 * This class has been auto-generated by the Doctrine ORM Framework 193 */ 194class Concept extends BaseConcept 195{ 196 197} 198 199/** 200 * This class has been auto-generated by the Doctrine ORM Framework 201 */ 202class ConceptRelation extends BaseConceptRelation 203{ 204 public static function showAllRelations() { 205 /*$relations = Doctrine_Core::getTable("ConceptRelation")->findAll(); 206 foreach ($relations as $relation) { 207 echo $relation->broaderConcept->identifier."(".$relation->conceptIdParent.")->".$relation->concept->identifier."(".$relation->conceptId.")\n<br/>"; 208 } 209 echo "\n\n<br/><br/>";*/ 210 } 211 212 public static function countAll() { 213 return Doctrine_Core::getTable("ConceptRelation")->count(); 214 } 215} 216?> 217