Files
FreshRSS/tests/app/Models/CategoryTest.php
Alexandre Alapetite 39cc1c11ec New feature: shareable user query (#6052)
* New feature: shareable user query
Share the output of a user query by RSS / HTML / OPML with other people through unique URLs.
Replaces the global admin token, which was the only option (but unsafe) to share RSS outputs with other people.
Also add a new HTML output for people without an RSS reader.

fix https://github.com/FreshRSS/FreshRSS/issues/3066#issuecomment-648977890
fix https://github.com/FreshRSS/FreshRSS/issues/3178#issuecomment-769435504

* Remove unused method

* Fix token saving

* Implement HTML view

* Update i18n for master token

* Revert i18n get_favorite

* Fix missing i18n for user queries from before this PR

* Remove irrelevant tests

* Add link to RSS version

* Fix getGet

* Fix getState

* Fix getSearch

* Alternative getSearch

* Default getOrder

* Explicit default state

* Fix test

* Add OPML sharing

* Remove many redundant SQL queries from original implementation of user queries

* Fix article tags

* Use default user settings

* Prepare public search

* Fixes

* Allow user search on article tags

* Implement user search

* Revert filter bug

* Revert wrong SQL left outer join change

* Implement checkboxes

* Safe check of OPML

* Fix label

* Remove RSS button to favour new sharing method
That sharing button was using a global admin token

* First version of HTTP 304

* Disallow some recusrivity
fix https://github.com/FreshRSS/FreshRSS/issues/6086

* Draft of nav

* Minor httpConditional

* Add support for offset for pagination

* Fix offset pagination

* Fix explicit order ASC

* Add documentation

* Help links i18n

* Note about deprecated master token

* Typo

* Doc about format
2024-02-26 09:01:03 +01:00

91 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
class CategoryTest extends PHPUnit\Framework\TestCase {
public function test__construct_whenNoParameters_createsObjectWithDefaultValues(): void {
$category = new FreshRSS_Category();
self::assertEquals(0, $category->id());
self::assertEquals('', $category->name());
}
/**
* @dataProvider provideValidNames
*/
public function test_name_whenValidValue_storesModifiedValue(string $input, string $expected): void {
$category = new FreshRSS_Category($input);
self::assertEquals($expected, $category->name());
}
/** @return array<array{string,string}> */
public function provideValidNames(): array {
return array(
array('', ''),
array('this string does not need trimming', 'this string does not need trimming'),
array(' this string needs trimming on left', 'this string needs trimming on left'),
array('this string needs trimming on right ', 'this string needs trimming on right'),
array(' this string needs trimming on both ends ', 'this string needs trimming on both ends'),
array(str_repeat('X', 512), str_repeat('X', FreshRSS_DatabaseDAO::LENGTH_INDEX_UNICODE)), // max length
);
}
public function test_feedOrdering(): void {
$feed_1 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_1->expects(self::any())
->method('name')
->willReturn('AAA');
$feed_2 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_2->expects(self::any())
->method('name')
->willReturn('ZZZ');
$feed_3 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_3->expects(self::any())
->method('name')
->willReturn('lll');
$category = new FreshRSS_Category('test', 0, [
$feed_1,
$feed_2,
$feed_3,
]);
$feeds = $category->feeds();
self::assertCount(3, $feeds);
$feed = reset($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('AAA', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('lll', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('ZZZ', $feed->name());
/** @var FreshRSS_Feed&PHPUnit\Framework\MockObject\MockObject */
$feed_4 = $this->getMockBuilder(FreshRSS_Feed::class)
->disableOriginalConstructor()
->getMock();
$feed_4->expects(self::any())
->method('name')
->willReturn('BBB');
$category->addFeed($feed_4);
$feeds = $category->feeds();
self::assertCount(4, $feeds);
$feed = reset($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('AAA', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('BBB', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('lll', $feed->name());
$feed = next($feeds) ?: FreshRSS_Feed::default();
self::assertEquals('ZZZ', $feed->name());
}
}