Beispiel #1
0
 protected function factoryMethod()
 {
     $product = new Postac2();
     $property = new Property();
     $property->set('actionpkt', 0);
     $property->set('imie', 'Piotr');
     $property->set('sila', 10);
     $property->set('zycie', 20);
     $property->set('speed', 15);
     $product->setProperties($property);
     return $product;
 }
Beispiel #2
0
	public function set($val)
	{
		parent::set($val);
		if ($val instanceof IFileUpload)
		{
			$this->_value->setStoreManager(CoOrg::getDataManager($this->_dataPath));
		}
	}
Beispiel #3
0
 public function test_for_has_and_belongs_to_many()
 {
     $Property = new Property(array('description' => 'Gandia Palace'));
     $this->assertEqual($Property->property_type->getType(), 'hasAndBelongsToMany');
     $this->assertTrue(is_array($Property->property_types) && count($Property->property_types) === 0);
     $Property->property_type->load();
     $this->assertEqual($Property->property_type->count(), 0);
     $Chalet = new PropertyType(array('description' => 'Chalet'));
     $Property->property_type->add($Chalet);
     $this->assertEqual($Property->property_type->count(), 1);
     $this->assertReference($Property->property_types[0], $Chalet);
     $Property->property_type->add($Chalet);
     $this->assertEqual($Property->property_type->count(), 1);
     $Condo = new PropertyType(array('description' => 'Condominium'));
     $Property->property_type->add($Condo);
     $this->assertEqual($Property->property_type->count(), 2);
     $this->assertTrue($Property->save());
     $this->assertFalse($Chalet->isNewRecord());
     $this->assertFalse($Condo->isNewRecord());
     $this->assertTrue($Chalet = $Chalet->findFirstBy('description', 'Chalet', array('include' => 'properties')));
     $this->assertEqual($Chalet->properties[0]->getId(), $Property->getId());
     $this->assertTrue($Condo = $Condo->findFirstBy('description', 'Condominium', array('include' => 'properties')));
     $this->assertEqual($Condo->properties[0]->getId(), $Property->getId());
     $this->assertReference($Chalet, $Property->property_types[0]);
     $this->assertReference($Condo, $Property->property_types[1]);
     $Property = new Property($Property->getId());
     $Property->property_type->load();
     $this->assertEqual($Property->property_type->association_id, 'property_types');
     $this->assertEqual($Property->property_type->count(), 2);
     $Property->property_types = array();
     $this->assertEqual($Property->property_type->count(), 0);
     $Property->property_type->load();
     $this->assertEqual($Property->property_type->count(), 0);
     $Property->property_type->load(true);
     $this->assertEqual($Property->property_type->count(), 2);
     $this->assertEqual($Property->property_types[1]->getType(), 'PropertyType');
     $Property->property_type->delete($Property->property_types[1]);
     $this->assertEqual($Property->property_type->count(), 1);
     $Property->property_type->load(true);
     $this->assertEqual($Property->property_type->count(), 1);
     $Property =& $Property->findFirstBy('description', 'Gandia Palace');
     $PropertyType = new PropertyType();
     $PropertyTypes =& $PropertyType->find();
     $Property->property_type->set($PropertyTypes);
     $this->assertEqual($Property->property_type->count(), count($PropertyTypes));
     $Property =& $Property->findFirstBy('description', 'Gandia Palace');
     $Property->property_type->load();
     $this->assertEqual($Property->property_type->count(), count($PropertyTypes));
     $Property =& $Property->findFirstBy('description', 'Gandia Palace');
     $PropertyType->set('description', 'Palace');
     $Property->property_type->set($PropertyType);
     $this->assertEqual($Property->property_type->count(), 1);
     $this->assertTrue(in_array('property_types', $Property->getAssociatedIds()));
     $Property = $Property->findFirstBy('description', 'Gandia Palace', array('include' => 'property_types'));
     $this->assertIdentical($Property->property_type->count(), 1);
     $this->assertTrue($Property->property_type->delete($Property->property_types[0]));
     $this->assertIdentical($Property->property_type->count(), 0);
     $Property = $Property->findFirstBy('description', 'Gandia Palace');
     $this->assertIdentical($Property->property_type->count(), 0);
     // It should return existing Property even if it doesnt have property_types
     $this->assertTrue($Property->findFirstBy('description', 'Gandia Palace', array('include' => 'property_types')));
     $Property = new Property(array('description' => 'Luxury Downtown House'));
     $Apartment =& $PropertyType->create(array('description' => 'Apartment'));
     $Loft =& $PropertyType->create(array('description' => 'Loft'));
     $Penthouse =& $PropertyType->create(array('description' => 'Penthouse'));
     $Property->property_type->setByIds(array($Apartment->getId(), $Loft->getId(), $Penthouse->getId()));
     $this->assertEqual($Property->property_type->count(), 3);
     $this->assertTrue($Property->save());
     $this->assertTrue($Property->save());
     $this->assertTrue($Property =& $Property->findFirstBy('description', 'Luxury Downtown House'));
     $Property->property_type->load();
     $this->assertEqual($Property->property_type->count(), 3);
     $FoundApartment = $Property->property_type->find('first', array('description' => 'Apartment'));
     $this->assertEqual($Apartment->get('description') . $Apartment->getId(), $FoundApartment->get('description') . $FoundApartment->getId());
     $FoundTypes = $Property->property_type->find();
     $this->assertEqual(count($FoundTypes), $Property->property_type->count());
     $descriptions = array();
     foreach ($FoundTypes as $FoundType) {
         $descriptions[] = $FoundType->get('description');
     }
     sort($descriptions);
     $this->assertEqual($descriptions, array('Apartment', 'Loft', 'Penthouse'));
     $this->assertFalse($Property->property_type->isEmpty());
     $this->assertEqual($Property->property_type->getSize(), 3);
     $this->assertTrue($Property->property_type->clear());
     $this->assertTrue($Property->property_type->isEmpty());
     $this->assertEqual($Property->property_type->getSize(), 0);
     $Property = new Property();
     $LandProperty =& $Property->property_type->build(array('description' => 'Land'));
     $this->assertReference($LandProperty, $Property->property_types[0]);
     $this->assertTrue($Property->property_types[0]->isNewRecord());
     $this->assertEqual($LandProperty->getType(), 'PropertyType');
     $Property->set('description', 'Plot of Land in Spain');
     $this->assertTrue($Property->save());
     $this->assertTrue($LandProperty = $Property->findFirstBy('description', 'Plot of Land in Spain', array('include' => 'property_types')));
     $this->assertEqual($LandProperty->property_types[0]->get('description'), 'Land');
     $Property = new Property(array('description' => 'Seaside house in Altea'));
     $SeasidePropertyType =& $Property->property_type->create(array('description' => 'Seaside property'));
     $this->assertReference($SeasidePropertyType, $Property->property_types[0]);
     $this->assertTrue($SeasidePropertyType->isNewRecord());
     $Property = new Property(array('description' => 'Bermi\'s appartment in Altea'));
     $this->assertTrue($Property->save());
     $SeasidePropertyType =& $Property->property_type->create(array('description' => 'Seaside property'));
     $this->assertReference($SeasidePropertyType, $Property->property_types[0]);
     $this->assertFalse($SeasidePropertyType->isNewRecord());
     $this->assertTrue($PropertyInAltea = $Property->findFirstBy('description', 'Bermi\'s appartment in Altea', array('include' => 'property_types')));
     $this->assertEqual($PropertyInAltea->property_types[0]->get('description'), 'Seaside property');
     // Testing destroy callbacks
     $this->assertTrue($Property =& $Property->findFirstBy('description', 'Bermi\'s appartment in Altea'));
     $property_id = $Property->getId();
     //echo '<pre>'.print_r($Property->_associations, true).'</pre>';
     $this->assertTrue($Property->destroy());
     $RecordSet = $PropertyInAltea->_db->execute('SELECT * FROM properties_property_types WHERE property_id = ' . $property_id);
     $this->assertEqual($RecordSet->RecordCount(), 0);
 }
Beispiel #4
0
	public function set($v)
	{
		parent::set(trim($v));
	}
Beispiel #5
0
 public function test_for_has_many()
 {
     $Property = new Property();
     $this->assertEqual($Property->picture->getType(), 'hasMany');
     $this->assertTrue(is_array($Property->pictures) && count($Property->pictures) === 0);
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 0);
     $SeaViews = new Picture(array('title' => 'Sea views'));
     $Property->picture->add($SeaViews);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertReference($Property->pictures[0], $SeaViews);
     $Property->picture->add($SeaViews);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertNull($Property->pictures[0]->get('property_id'));
     $MountainViews = new Picture(array('title' => 'Mountain views'));
     $this->assertTrue($MountainViews->isNewRecord());
     $Property->picture->add($MountainViews);
     $this->assertEqual($Property->picture->count(), 2);
     $this->assertTrue($Property->save());
     $this->assertFalse($SeaViews->isNewRecord());
     $this->assertFalse($MountainViews->isNewRecord());
     $this->assertEqual($SeaViews->get('property_id'), $Property->getId());
     $this->assertEqual($MountainViews->get('property_id'), $Property->getId());
     $this->assertReference($SeaViews, $Property->pictures[0]);
     $this->assertReference($MountainViews, $Property->pictures[1]);
     $Property = new Property($Property->getId());
     $Property->picture->load();
     $this->assertEqual($Property->picture->association_id, 'pictures');
     $this->assertEqual($Property->picture->count(), 2);
     $Property->pictures = array();
     $this->assertEqual($Property->picture->count(), 0);
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 0);
     $Property->picture->load(true);
     $this->assertEqual($Property->picture->count(), 2);
     $this->assertEqual($Property->pictures[1]->getType(), 'Picture');
     $Property->picture->delete($Property->pictures[1]);
     $this->assertEqual($Property->picture->count(), 1);
     $Property->picture->load(true);
     $this->assertEqual($Property->picture->count(), 1);
     $Property = $Property->find('first');
     $Picture = new Picture();
     $Pictures = $Picture->find();
     $Property->picture->set($Pictures);
     $this->assertEqual($Property->picture->count(), count($Pictures));
     $Property = $Property->find('first');
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), count($Pictures));
     $Picture = $Picture->find('first');
     $Property->picture->set($Picture);
     $this->assertEqual($Property->picture->count(), 1);
     $this->assertTrue(in_array('pictures', $Property->getAssociatedIds()));
     $Property = $Property->find('first', array('include' => 'pictures'));
     $this->assertIdentical($Property->picture->count(), 1);
     $this->assertEqual($Property->pictures[0]->getId(), $Picture->getId());
     $this->assertTrue($Property->picture->delete($Property->pictures[0]));
     $this->assertIdentical($Property->picture->count(), 0);
     $Property =& $Property->find('first');
     $this->assertIdentical($Property->picture->count(), 0);
     //$this->assertTrue($Property =& $Property->find('first', array('include'=>'pictures')));
     //$this->assertIdentical($Property->picture->count(), 0);
     $Picture = new Picture();
     $Alicia =& $Picture->create(array('title' => 'Alicia'));
     $Bermi =& $Picture->create(array('title' => 'Bermi'));
     $Hilario =& $Picture->create(array('title' => 'Hilario'));
     $Property->picture->setByIds(array($Alicia->getId(), $Bermi->getId(), $Hilario->getId()));
     $Property->set('description', 'Cool house');
     $this->assertTrue($Property->save());
     $this->assertTrue($Property =& $Property->findFirstBy('description', 'Cool house'));
     $Property->picture->load();
     $this->assertEqual($Property->picture->count(), 3);
     $FoundAlicia = $Property->picture->find('first', array('conditions' => array('title = ?', "Alicia")));
     $this->assertEqual($Alicia->get('title') . $Alicia->getId(), $FoundAlicia->get('title') . $FoundAlicia->getId());
     $FoundPals = $Property->picture->find();
     $this->assertEqual(count($FoundPals), $Property->picture->count());
     $titles = array();
     foreach ($FoundPals as $FoundPal) {
         $titles[] = $FoundPal->get('title');
     }
     sort($titles);
     $this->assertEqual($titles, array('Alicia', 'Bermi', 'Hilario'));
     $this->assertFalse($Property->picture->isEmpty());
     $this->assertEqual($Property->picture->getSize(), 3);
     $this->assertTrue($Property->picture->clear());
     $this->assertTrue($Property->picture->isEmpty());
     $this->assertEqual($Property->picture->getSize(), 0);
     $Property = new Property();
     $PoolPicture =& $Property->picture->build(array('title' => 'Pool'));
     $this->assertReference($PoolPicture, $Property->pictures[0]);
     $this->assertTrue($Property->pictures[0]->isNewRecord());
     $this->assertEqual($PoolPicture->getType(), 'Picture');
     $Property->set('description', 'Maui Estate');
     $this->assertTrue($Property->save());
     $this->assertTrue($MauiEstate = $Property->findFirstBy('description', 'Maui Estate', array('include' => 'pictures')));
     $this->assertEqual($MauiEstate->pictures[0]->get('title'), 'Pool');
     $Property = new Property(array('description' => 'Villa Altea'));
     $GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
     $this->assertReference($GardenPicture, $Property->pictures[0]);
     $this->assertTrue($GardenPicture->isNewRecord());
     $Property = new Property(array('description' => 'Villa Altea'));
     $this->assertTrue($Property->save());
     $GardenPicture =& $Property->picture->create(array('title' => 'Garden'));
     $this->assertReference($GardenPicture, $Property->pictures[0]);
     $this->assertFalse($GardenPicture->isNewRecord());
     $this->assertTrue($VillaAltea = $Property->findFirstBy('description', 'Villa Altea', array('include' => 'pictures')));
     $this->assertEqual($VillaAltea->pictures[0]->get('title'), 'Garden');
 }