summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/database.xml14
-rw-r--r--appinfo/version2
-rw-r--r--db/entity.php48
-rw-r--r--db/item.php116
-rw-r--r--tests/db/EntityTest.php19
-rw-r--r--tests/db/ItemTest.php75
6 files changed, 209 insertions, 65 deletions
diff --git a/appinfo/database.xml b/appinfo/database.xml
index 1b8bb93dd..9a24e0582 100644
--- a/appinfo/database.xml
+++ b/appinfo/database.xml
@@ -40,14 +40,14 @@
</field>
<index>
- <name>parent_id_index</name>
+ <name>news_folders_parent_id_index</name>
<field>
<name>parent_id</name>
</field>
</index>
<index>
- <name>user_id_index</name>
+ <name>news_folders_user_id_index</name>
<field>
<name>user_id</name>
</field>
@@ -115,21 +115,21 @@
</field>
<index>
- <name>user_id_index</name>
+ <name>news_feeds_user_id_index</name>
<field>
<name>user_id</name>
</field>
</index>
<index>
- <name>folder_id_index</name>
+ <name>news_feeds_folder_id_index</name>
<field>
<name>folder_id</name>
</field>
</index>
<index>
- <name>url_hash_index</name>
+ <name>news_feeds_url_hash_index</name>
<field>
<name>url_hash</name>
</field>
@@ -204,14 +204,14 @@
</field>
<index>
- <name>feed_id_index</name>
+ <name>news_items_feed_id_index</name>
<field>
<name>feed_id</name>
</field>
</index>
<index>
- <name>item_guid</name>
+ <name>news_items_item_guid</name>
<field>
<name>guid_hash</name>
</field>
diff --git a/appinfo/version b/appinfo/version
index 120096f1f..b293f64d6 100644
--- a/appinfo/version
+++ b/appinfo/version
@@ -1 +1 @@
-7.7 \ No newline at end of file
+8.0 \ No newline at end of file
diff --git a/db/entity.php b/db/entity.php
index 9adab3b7f..58c42cca7 100644
--- a/db/entity.php
+++ b/db/entity.php
@@ -27,10 +27,56 @@ namespace OCA\News\Db;
abstract class Entity {
- public function fromRow($row){
+ public $id;
+
+ private $updatedFields;
+
+
+ public function __construct(){
+ $this->updatedFields = array();
+ }
+
+
+ /**
+ * Each time a setter is called, push the part after set
+ * into an array: for instance setId will save Id in the
+ * updated fields array so it can be easily used to create the
+ * getter method
+ */
+ public function __call($methodName, $args){
+ if(startsWith($methodName, 'set')){
+ $setterPart = substr($methodName, 2);
+ array_push($this->updatedFields, $setterPart);
+ }
+ }
+
+
+ /**
+ * @return array array of updated fields for update query
+ */
+ public function getUpdatedFields(){
+ return $this->updatedFields;
+ }
+
+
+ /**
+ * Maps the keys of the row array to the attributes
+ * @param array $row the row to map onto the entity
+ */
+ public function fromRow(array $row){
foreach($row as $key => $value){
$this->$key = $value;
}
}
+
+ public function setId($id){
+ $this->id = $id;
+ }
+
+
+ public function getId(){
+ return $this->id;
+ }
+
} \ No newline at end of file
diff --git a/db/item.php b/db/item.php
index 7d07b337b..ee25ab122 100644
--- a/db/item.php
+++ b/db/item.php
@@ -12,16 +12,69 @@
namespace OCA\News\Db;
+
class Item extends Entity {
+ public $url;
+ public $feed_id;
+ public $guid;
+ public $status;
+ public $title;
+ public $feedTitle;
+
+
+ public function setUrl($url) {
+ $this->url = $url;
+ }
+
+ public function getUrl() {
+ return $this->url;
+ }
+
+ public function setFeedId($feed_id) {
+ $this->feed_id = $feed_id;
+ }
+
+ public function getFeedId() {
+ return $this->feed_id;
+ }
+
+ public function setGUID($guid) {
+ $this->guid = $guid;
+ }
+
+ public function getGUID() {
+ return $this->guid;
+ }
+
+ public function setStatus($status) {
+ $this->status = $status;
+ }
+
+ public function getStatus() {
+ return $this->status;
+ }
+
+ public function getTitle() {
+ return $this->title;
+ }
+
+ public function setTitle($title) {
+ $this->title = $title;
+ }
+
+ public function getFeedTitle() {
+ return $this->feedTitle;
+ }
+
+ public function setFeedTitle($feedtitle) {
+ $this->feedTitle = $feedtitle;
+ }
+
}
-/**
- * This class models an item.
- *
- * It encapsulate a SimplePie_Item object and adds a status flag to it
- */
+
/*class Item {
@@ -50,29 +103,9 @@ class Item extends Entity {
}
}
- public function getFeedId() {
- return $this->feedId;
- }
-
- public function setFeedId($feedId) {
- $this->feedId = $feedId;
- }
-
- public function getGuid() {
- return $this->guid;
- }
- public function setGuid($guid) {
- $this->guid = $guid;
- }
- public function getId() {
- return $this->id;
- }
-
- public function setId($id) {
- $this->id = $id;
- }
+
public function setRead() {
$this->status &= ~StatusFlag::UNREAD;
@@ -97,38 +130,9 @@ class Item extends Entity {
public function isImportant() {
return ($this->status & StatusFlag::IMPORTANT);
}
-
- public function getStatus() {
- return $this->status;
- }
-
- public function setStatus($status) {
- $this->status = $status;
- }
-
- public function getTitle() {
- return $this->title;
- }
-
- public function setTitle($title) {
- $this->title = $title;
- }
- public function getFeedTitle() {
- return $this->feedTitle;
- }
- public function setFeedTitle($feedtitle) {
- $this->feedTitle = $feedtitle;
- }
-
- public function getUrl() {
- return $this->url;
- }
-
- public function setUrl($url) {
- $this->url = $url;
- }
+
public function getBody() {
return $this->body;
diff --git a/tests/db/EntityTest.php b/tests/db/EntityTest.php
index 8d5705c74..3e778d4fe 100644
--- a/tests/db/EntityTest.php
+++ b/tests/db/EntityTest.php
@@ -33,6 +33,7 @@ class TestEntity extends Entity {
public $email;
};
+
class EntityTest extends \PHPUnit_Framework_TestCase {
protected function setUp(){
@@ -53,4 +54,22 @@ class EntityTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($row['email'], $entity->email);
}
+
+ public function testGetSetId(){
+ $id = 3;
+ $entity = new TestEntity();
+ $entity->setId(3);
+
+ $this->assertEquals($id, $entity->getId());
+ }
+
+
+ public function testSetterMarksFieldUpdated(){
+ $id = 3;
+ $entity = new TestEntity();
+ $entity->setId(3);
+
+ $this->assertContains('id', $entity->getUpdatedFields());
+ }
+
} \ No newline at end of file
diff --git a/tests/db/ItemTest.php b/tests/db/ItemTest.php
new file mode 100644
index 000000000..35eb2bec4
--- /dev/null
+++ b/tests/db/ItemTest.php
@@ -0,0 +1,75 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Db;
+
+require_once(__DIR__ . "/../classloader.php");
+
+
+class ItemTest extends \PHPUnit_Framework_TestCase {
+
+
+ protected function assertSetterGetter($name){
+ $value = 'value';
+
+ $item = new Item();
+ $setMethod = 'set' . $name;
+ $getMethod = 'get' . $name;
+ $item->$setMethod($value);
+
+ $this->assertEquals($value, $item->$getMethod());
+ }
+
+
+ public function testGetUrl(){
+ $this->assertSetterGetter('Url');
+ }
+
+
+ public function testSetFeedId(){
+ $this->assertSetterGetter('FeedId');
+ }
+
+
+ public function testSetGUID(){
+ $this->assertSetterGetter('GUID');
+ }
+
+
+ public function testSetStatus(){
+ $this->assertSetterGetter('Status');
+ }
+
+
+ public function testSetTitle(){
+ $this->assertSetterGetter('Title');
+ }
+
+
+ public function testSetFeedTitle(){
+ $this->assertSetterGetter('FeedTitle');
+ }
+
+} \ No newline at end of file