summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorDevlin Junker <devlin.junker@gmail.com>2023-10-22 13:57:14 -0700
committerDevlin Junker <devlin.junker@gmail.com>2023-10-22 14:03:52 -0700
commit3e35d781cf712efa1473b4495a48299326b52c0c (patch)
tree9643b2e75ee3139bb6c5abb102d6f69937a5169e /tests
parent94f04d4a20cbbadb7d8ad835bc7ae3dc1c4256fd (diff)
parentd423ca520ca9c61233c33717d604e3183f0f486c (diff)
Merge remote-tracking branch 'nextcloud/master' into master-merge
Signed-off-by: Devlin Junker <devlin.junker@gmail.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Fetcher/FeedFetcherTest.php30
-rw-r--r--tests/Unit/Service/UpdaterTest.php14
-rw-r--r--tests/command/update.bats21
-rw-r--r--tests/updater/update.bats27
4 files changed, 77 insertions, 15 deletions
diff --git a/tests/Unit/Fetcher/FeedFetcherTest.php b/tests/Unit/Fetcher/FeedFetcherTest.php
index 1814a8271..d73edc1ef 100644
--- a/tests/Unit/Fetcher/FeedFetcherTest.php
+++ b/tests/Unit/Fetcher/FeedFetcherTest.php
@@ -28,11 +28,13 @@ use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
use OCA\News\Scraper\Scraper;
use OCA\News\Fetcher\FeedFetcher;
-use GuzzleHttp\Client;
+use OCA\News\Config\FetcherConfig;
use OCA\News\Utility\Time;
+use OCA\News\Utility\Cache;
use OCP\IL10N;
use OCP\ITempManager;
+
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
@@ -83,11 +85,6 @@ class FeedFetcherTest extends TestCase
private $l10n;
/**
- * @var MockObject|ITempManager
- */
- private $ITempManager;
-
- /**
* @var MockObject|ItemInterface
*/
private $item_mock;
@@ -108,9 +105,14 @@ class FeedFetcherTest extends TestCase
private $scraper;
/**
- * @var MockObject|Client
+ * @var MockObject|FetcherConfig
*/
- private $client;
+ private $fetcherConfig;
+
+ /**
+ * @var MockObject|Cache
+ */
+ private $cache;
//metadata
/**
@@ -158,9 +160,6 @@ class FeedFetcherTest extends TestCase
$this->l10n = $this->getMockBuilder(IL10N::class)
->disableOriginalConstructor()
->getMock();
- $this->ITempManager = $this->getMockBuilder(ITempManager::class)
- ->disableOriginalConstructor()
- ->getMock();
$this->reader = $this->getMockBuilder(FeedIo::class)
->disableOriginalConstructor()
->getMock();
@@ -194,7 +193,10 @@ class FeedFetcherTest extends TestCase
$this->scraper = $this->getMockBuilder(Scraper::class)
->disableOriginalConstructor()
->getMock();
- $this->client = $this->getMockBuilder(Client::class)
+ $this->fetcherConfig = $this->getMockBuilder(FetcherConfig::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->cache = $this->getMockBuilder(Cache::class)
->disableOriginalConstructor()
->getMock();
$this->fetcher = new FeedFetcher(
@@ -202,10 +204,10 @@ class FeedFetcherTest extends TestCase
$this->favicon,
$this->scraper,
$this->l10n,
- $this->ITempManager,
$timeFactory,
$this->logger,
- $this->client
+ $this->fetcherConfig,
+ $this->cache
);
$this->url = 'http://tests/';
diff --git a/tests/Unit/Service/UpdaterTest.php b/tests/Unit/Service/UpdaterTest.php
index b4be0a7cc..3d5ca2252 100644
--- a/tests/Unit/Service/UpdaterTest.php
+++ b/tests/Unit/Service/UpdaterTest.php
@@ -18,6 +18,8 @@ use OCA\News\Service\FolderServiceV2;
use OCA\News\Service\ItemServiceV2;
use OCA\News\Service\UpdaterService;
use PHPUnit\Framework\TestCase;
+use OCP\BackgroundJob\IJobList;
+use OCP\BackgroundJob\IJob;
class UpdaterTest extends TestCase
{
@@ -42,6 +44,11 @@ class UpdaterTest extends TestCase
*/
private $updater;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|IJobList
+ */
+ private $jobList;
+
protected function setUp(): void
{
$this->folderService = $this->getMockBuilder(FolderServiceV2::class)
@@ -53,10 +60,14 @@ class UpdaterTest extends TestCase
$this->itemService = $this->getMockBuilder(ItemServiceV2::class)
->disableOriginalConstructor()
->getMock();
+ $this->jobList = $this->getMockBuilder(IJobList::class)
+ ->disableOriginalConstructor()
+ ->getMock();
$this->updater = new UpdaterService(
$this->folderService,
$this->feedService,
- $this->itemService
+ $this->itemService,
+ $this->jobList
);
}
@@ -83,4 +94,5 @@ class UpdaterTest extends TestCase
->method('fetchAll');
$this->updater->update();
}
+
} \ No newline at end of file
diff --git a/tests/command/update.bats b/tests/command/update.bats
new file mode 100644
index 000000000..d94c1cd28
--- /dev/null
+++ b/tests/command/update.bats
@@ -0,0 +1,21 @@
+#!/usr/bin/env bats
+
+# This only works with NC 26
+
+load "helpers/settings"
+load "../test_helper/bats-support/load"
+load "../test_helper/bats-assert/load"
+
+TESTSUITE="Update"
+
+@test "[$TESTSUITE] Job status" {
+ run ./occ news:updater:job
+
+ assert_success
+}
+
+@test "[$TESTSUITE] Job reset" {
+ run ./occ news:updater:job --reset
+
+ assert_success
+} \ No newline at end of file
diff --git a/tests/updater/update.bats b/tests/updater/update.bats
index ba978dbb0..e55661bc1 100644
--- a/tests/updater/update.bats
+++ b/tests/updater/update.bats
@@ -85,6 +85,33 @@ teardown() {
assert_output --partial "${ID_LIST1[*]}"
}
+@test "[$TESTSUITE] Test feed with 'outdated' items https://github.com/nextcloud/news/issues/2236 " {
+ # Create Feed, for the first fetch a timestamp today -1 year is used.
+ FEEDID=$(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} POST ${BASE_URLv1}/feeds url=$TEST_FEED | grep -Po '"id":\K([0-9]+)')
+
+ sleep 2
+
+ # Get Items
+ ID_LIST1=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+
+ # Generate Feed with older items (-o yes)
+ php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 15 -s 9 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml -o yes
+
+ # Trigger Update
+ http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/feeds/update userId=${user} feedId=$FEEDID
+
+ sleep 2
+
+ # Get Items again
+ ID_LIST2=($(http --ignore-stdin -b -a ${user}:${APP_PASSWORD} GET ${BASE_URLv1}/items | grep -Po '"id":\K([0-9]+)' | tr '\n' ' '))
+
+ output="${ID_LIST2[*]}"
+
+ # Check that they are not equal but that they match partially.
+ assert_not_equal "${ID_LIST1[*]}" "${ID_LIST2[*]}"
+ assert_output --partial "${ID_LIST1[*]}"
+}
+
@test "[$TESTSUITE] Test purge with small feed" {
# Generate Feed with 210 items.
php ${BATS_TEST_DIRNAME}/../test_helper/php-feed-generator/feed-generator.php -a 50 -s 0 -f ${BATS_TEST_DIRNAME}/../test_helper/feeds/test.xml