Skip to content

Commit 4157f29

Browse files
committed
Update Model __isset and add tests
1 parent 4bd9f6f commit 4157f29

2 files changed

Lines changed: 68 additions & 1 deletion

File tree

system/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1643,7 +1643,7 @@ public function __get(string $name)
16431643
*/
16441644
public function __isset(string $name): bool
16451645
{
1646-
if (in_array($name, ['primaryKey', 'table', 'returnType', 'DBGroup']))
1646+
if (property_exists($this, $name))
16471647
{
16481648
return true;
16491649
}

tests/system/Database/Live/ModelTest.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,4 +1735,71 @@ public function testSoftDeleteWithTableJoinsFirst()
17351735
// Just making sure it didn't throw ambiguous deleted error
17361736
$this->assertEquals(1, $results->id);
17371737
}
1738+
1739+
//--------------------------------------------------------------------
1740+
1741+
public function testMagicIssetTrue()
1742+
{
1743+
$model = new UserModel();
1744+
1745+
$this->assertTrue(isset($model->table));
1746+
}
1747+
1748+
public function testMagicIssetFalse()
1749+
{
1750+
$model = new UserModel();
1751+
1752+
$this->assertFalse(isset($model->foobar));
1753+
}
1754+
1755+
public function testMagicIssetWithNewProperty()
1756+
{
1757+
$model = new UserModel();
1758+
1759+
$model->flavor = 'chocolate';
1760+
1761+
$this->assertTrue(isset($model->flavor));
1762+
}
1763+
1764+
public function testMagicIssetFromDb()
1765+
{
1766+
$model = new UserModel();
1767+
1768+
$this->assertTrue(isset($model->DBPrefix));
1769+
}
1770+
1771+
public function testMagicIssetFromBuilder()
1772+
{
1773+
$model = new UserModel();
1774+
1775+
$this->assertTrue(isset($model->canLimitDeletes));
1776+
}
1777+
1778+
public function testMagicGet()
1779+
{
1780+
$model = new UserModel();
1781+
1782+
$this->assertEquals('user', $model->table);
1783+
}
1784+
1785+
public function testMagicGetMissing()
1786+
{
1787+
$model = new UserModel();
1788+
1789+
$this->assertNull($model->foobar);
1790+
}
1791+
1792+
public function testMagicGetFromDB()
1793+
{
1794+
$model = new UserModel();
1795+
1796+
$this->assertEquals('utf8', $model->charset);
1797+
}
1798+
1799+
public function testMagicGetFromBuilder()
1800+
{
1801+
$model = new UserModel();
1802+
1803+
$this->assertIsBool($model->canLimitDeletes);
1804+
}
17381805
}

0 commit comments

Comments
 (0)