Improve Link::getOppositeLinkId()
This commit is contained in:
@@ -55,8 +55,7 @@ class Link extends Base
|
|||||||
*/
|
*/
|
||||||
public function getOppositeLinkId($link_id)
|
public function getOppositeLinkId($link_id)
|
||||||
{
|
{
|
||||||
$link = $this->getById($link_id);
|
return $this->db->table(self::TABLE)->eq('id', $link_id)->findOneColumn('opposite_id') ?: $link_id;
|
||||||
return $link['opposite_id'] ?: $link_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,6 +36,18 @@ class LinkTest extends Base
|
|||||||
$this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
|
$this->assertNotEquals($link1['opposite_id'], $link2['opposite_id']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetOppositeLinkId()
|
||||||
|
{
|
||||||
|
$l = new Link($this->container);
|
||||||
|
|
||||||
|
$this->assertTrue($l->create('Link A'));
|
||||||
|
$this->assertTrue($l->create('Link B', 'Link C'));
|
||||||
|
|
||||||
|
$this->assertEquals(1, $l->getOppositeLinkId(1));
|
||||||
|
$this->assertEquals(3, $l->getOppositeLinkId(2));
|
||||||
|
$this->assertEquals(2, $l->getOppositeLinkId(3));
|
||||||
|
}
|
||||||
|
|
||||||
public function testUpdate()
|
public function testUpdate()
|
||||||
{
|
{
|
||||||
$l = new Link($this->container);
|
$l = new Link($this->container);
|
||||||
|
|||||||
Reference in New Issue
Block a user