summaryrefslogtreecommitdiffstats
path: root/tests/unit/utility/ConfigTest.php
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-09 01:44:12 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-09 22:52:26 +0200
commit21bd539847f33c3889c4f58f14afd672f54a410a (patch)
treed6ff27e38727197b60d1c2c47968b7f64d4f5c2f /tests/unit/utility/ConfigTest.php
parentfcef0800a24818305e8a52761b05f87e13206689 (diff)
ported to owncloud internal appframework classes, confused with how to start the app and define deps
Diffstat (limited to 'tests/unit/utility/ConfigTest.php')
-rw-r--r--tests/unit/utility/ConfigTest.php4
1 files changed, 2 insertions, 2 deletions
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
index 479acabb5..8ef688844 100644
--- a/tests/unit/utility/ConfigTest.php
+++ b/tests/unit/utility/ConfigTest.php
@@ -28,7 +28,7 @@ namespace OCA\News\Utility;
require_once(__DIR__ . "/../../classloader.php");
-class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
+class ConfigFetcherTest extends \OCA\News\Utility\TestUtility {
private $fileSystem;
private $config;
@@ -36,7 +36,7 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
public function setUp() {
$this->api = $this->getMockBuilder(
- '\OCA\AppFramework\Core\API')
+ '\OCA\News\Core\API')
->disableOriginalConstructor()
->getMock();
$this->fileSystem = $this->getMock('FileSystem', array(
8' href='#n168'>168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
/**
 * Nextcloud - News
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Bernhard Posselt <dev@bernhard-posselt.com>
 * @copyright Bernhard Posselt 2014
 */
app.factory('ItemResource', function (Resource, $http, BASE_URL, ITEM_BATCH_SIZE) {
    'use strict';

    var ItemResource = function ($http, BASE_URL, ITEM_BATCH_SIZE) {
        Resource.call(this, $http, BASE_URL);
        this.batchSize = ITEM_BATCH_SIZE;
        this.clear();
    };

    ItemResource.prototype = Object.create(Resource.prototype);

    ItemResource.prototype.clear = function () {
        this.starredCount = 0;
        this.lowestId = 0;
        this.highestId = 0;
        this.fingerprints = {};
        Resource.prototype.clear.call(this);
    };

    ItemResource.prototype.receive = function (value, channel) {
        switch (channel) {
            case 'newestItemId':
                this.newestItemId = value;
                break;

            case 'starred':
                this.starredCount = value;
                break;

            default:
                var self = this;
                var importValues = [];
                value.forEach(function (item) {
                    // initialize lowest and highest id
                    if (self.lowestId === 0) {
                        self.lowestId = item.id;
                    }
                    if (self.highestId === 0) {
                        self.highestId = item.id;
                    }

                    if (item.id > self.highestId) {
                        self.highestId = item.id;
                    }
                    if (item.id < self.lowestId) {
                        self.lowestId = item.id;
                    }

                    // filter out duplicates
                    if (self.fingerprints[item.fingerprint] === undefined) {
                        self.fingerprints[item.fingerprint] = true;
                        importValues.push(item);
                    }
                });

                Resource.prototype.receive.call(this, importValues, channel);
        }
    };


    ItemResource.prototype.getNewestItemId = function () {
        return this.newestItemId;
    };


    ItemResource.prototype.getStarredCount = function () {
        return this.starredCount;
    };


    ItemResource.prototype.star = function (itemId, isStarred) {
        if (isStarred === undefined) {
            isStarred = true;
        }

        var it = this.get(itemId);
        var url = this.BASE_URL +
            '/items/' + it.feedId + '/' + it.guidHash + '/star';

        it.starred = isStarred;

        if (isStarred) {
            this.starredCount += 1;
        } else {
            this.starredCount -= 1;
        }

        return this.http({
            url: url,
            method: 'POST',
            data: {
                isStarred: isStarred
            }
        });
    };


    ItemResource.prototype.toggleStar = function (itemId) {
        if (this.get(itemId).starred) {
            this.star(itemId, false);
        } else {
            this.star(itemId, true);
        }
    };


    ItemResource.prototype.markItemRead = function (itemId, isRead) {
        if (isRead === undefined) {
            isRead = true;
        }

        this.get(itemId).unread = !isRead;

        return this.http({
            url: this.BASE_URL + '/items/' + itemId + '/read',
            method: 'POST',
            data: {
                isRead: isRead
            }
        });
    };


    ItemResource.prototype.markItemsRead = function (itemIds) {
        var self = this;

        itemIds.forEach(function (itemId) {
            self.get(itemId).unread = false;
        });

        return this.http({
            url: this.BASE_URL + '/items/read/multiple',
            method: 'POST',
            data: {
                itemIds: itemIds
            }
        });
    };


    ItemResource.prototype.markFeedRead = function (feedId, read) {
        if (read === undefined) {
            read = true;
        }

        var items = this.values.filter(function (element) {
            return element.feedId === feedId;
        });

        items.forEach(function (item) {
            item.unread = !read;
        });

        return this.http.post(this.BASE_URL + '/feeds/' + feedId + '/read', {
            highestItemId: this.getNewestItemId()
        });
    };


    ItemResource.prototype.markRead = function () {
        this.values.forEach(function (item) {
            item.unread = false;
        });

        return this.http({
            url: this.BASE_URL + '/items/read',
            method: 'POST',
            data: {
                highestItemId: this.getNewestItemId()
            }
        });
    };


    ItemResource.prototype.autoPage = function (type, id, oldestFirst, showAll, search) {
        var offset;

        if (oldestFirst) {
            offset = this.highestId;
        } else {
            offset = this.lowestId;
        }

        return this.http({
            url: this.BASE_URL + '/items',
            method: 'GET',
            params: {
                type: type,
                id: id,
                offset: offset,
                limit: this.batchSize,
                oldestFirst: oldestFirst,
                showAll: showAll,
                search: search
            }
        });
    };


    ItemResource.prototype.importArticles = function (json) {
        return this.http({
            url: this.BASE_URL + '/feeds/import/articles',
            method: 'POST',
            data: {
                json: json
            }
        }).then(function (response) {
            return response.data;
        });
    };


    return new ItemResource($http, BASE_URL, ITEM_BATCH_SIZE);
});