Example #1
0
 /**
  * @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());
 }
Example #2
0
 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))']);
 }
Example #3
0
 /**
  * @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());
 }
Example #4
0
 /**
  * @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());
 }
Example #5
0
 /**
  * @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());
 }
Example #6
0
 public static function initialize(Config $config)
 {
     parent::initialize($config);
     $config->addAsserts([new Assert\Present('code'), new Assert\LengthEquals('code', 2)]);
 }
Example #7
0
 /**
  * @param  Location $location
  * @return boolean
  */
 public function contains(Location $location)
 {
     return $this->id == $location->id or $location->isDescendantOf($this);
 }
Example #8
0
 public static function initialize(Config $config)
 {
     parent::initialize($config);
 }