summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--db/entity.php14
-rw-r--r--db/item.php4
-rw-r--r--tests/db/EntityTest.php9
-rw-r--r--tests/db/ItemTest.php5
4 files changed, 30 insertions, 2 deletions
diff --git a/db/entity.php b/db/entity.php
index 165c7a476..a13bcce34 100644
--- a/db/entity.php
+++ b/db/entity.php
@@ -27,11 +27,14 @@ namespace OCA\News\Db;
abstract class Entity {
- public $id;
+ public $id;
+
+ private $tableName;
private $updatedFields;
- public function __construct(){
+ public function __construct($tableName){
$this->updatedFields = array();
+ $this->tableName = '*dbprefix*' . $tableName;
}
@@ -146,4 +149,11 @@ abstract class Entity {
}
+ /**
+ * @return string the table name
+ */
+ public function getTableName(){
+ return $this->tableName;
+ }
+
} \ No newline at end of file
diff --git a/db/item.php b/db/item.php
index d7546bcd2..403f35b35 100644
--- a/db/item.php
+++ b/db/item.php
@@ -41,6 +41,10 @@ class Item extends Entity {
public $status;
public $feedTitle;
+ public function __construct(){
+ parent::__construct('news_items');
+ }
+
public function setRead() {
$this->markFieldUpdated('status');
$this->status &= ~StatusFlag::UNREAD;
diff --git a/tests/db/EntityTest.php b/tests/db/EntityTest.php
index 3ad5c8d1e..e7e44e332 100644
--- a/tests/db/EntityTest.php
+++ b/tests/db/EntityTest.php
@@ -31,6 +31,10 @@ require_once(__DIR__ . "/../classloader.php");
class TestEntity extends Entity {
public $name;
public $email;
+
+ public function __construct(){
+ parent::__construct('entity');
+ }
};
@@ -123,4 +127,9 @@ class EntityTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($entity2, $this->entity);
}
+
+ public function testEntityShouldSetTableName(){
+ $this->assertEquals('*dbprefix*entity', $this->entity->getTableName());
+ }
+
} \ No newline at end of file
diff --git a/tests/db/ItemTest.php b/tests/db/ItemTest.php
index 792085733..872b464c3 100644
--- a/tests/db/ItemTest.php
+++ b/tests/db/ItemTest.php
@@ -65,4 +65,9 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($this->item->isUnstarred());
}
+
+ public function testTableName(){
+ $this->assertEquals('*dbprefix*news_items', $this->item->getTableName());
+ }
+
} \ No newline at end of file