/** * @covers ::initialize */ public function testInitialize() { $repo = Location::getRepo(); $this->assertInstanceOf('Harp\\MP\\BelongsTo', $repo->getRel('parent')); $this->assertInstanceOf('Harp\\MP\\HasMany', $repo->getRel('children')); $location = new Location(); $this->assertFalse($location->validate()); $this->assertEquals('name must be present', $location->getErrors()->humanize()); $location->name = 'test'; $this->assertTrue($location->validate()); }
public function testSave() { $everywhere = Location::find(1); $bulgaria = Location::findByName('Bulgaria'); $children = $everywhere->getChildren()->add($bulgaria); Location::save($everywhere); $this->assertQueries(['SELECT Location.class, Location.* FROM Location WHERE (id = 1) LIMIT 1', 'SELECT Location.class, Location.* FROM Location WHERE (name = "Bulgaria") LIMIT 1', 'SELECT Location.class, Location.* FROM Location WHERE (parentId IN (1))', 'SELECT Location.class, Location.* FROM Location WHERE (path LIKE "1/3/10%")', 'UPDATE Location SET parentId = CASE id WHEN 10 THEN 1 ELSE parentId END, path = CASE id WHEN 11 THEN "1/10" ELSE path END WHERE (id IN (10, 11))']); }
/** * @covers ::isCountry * @covers ::getRepo */ public function testCity() { $germany = Location::find(5); $this->assertInstanceOf('Harp\\Locations\\Country', $germany); $this->assertFalse($germany->isRegion()); $this->assertFalse($germany->isCity()); $this->assertTrue($germany->isCountry()); }
/** * @covers ::isRegion * @covers ::getRepo */ public function testCity() { $eu = Location::find(2); $this->assertInstanceOf('Harp\\Locations\\Region', $eu); $this->assertTrue($eu->isRegion()); $this->assertFalse($eu->isCity()); $this->assertFalse($eu->isCountry()); }
/** * @covers ::isCity * @covers ::getRepo */ public function testCity() { $sofia = Location::find(11); $this->assertInstanceOf('Harp\\Locations\\City', $sofia); $this->assertFalse($sofia->isRegion()); $this->assertTrue($sofia->isCity()); $this->assertFalse($sofia->isCountry()); }
public static function initialize(Config $config) { parent::initialize($config); $config->addAsserts([new Assert\Present('code'), new Assert\LengthEquals('code', 2)]); }
/** * @param Location $location * @return boolean */ public function contains(Location $location) { return $this->id == $location->id or $location->isDescendantOf($this); }
public static function initialize(Config $config) { parent::initialize($config); }