From 02b906549edee298e1986efd2b25e28dda726e89 Mon Sep 17 00:00:00 2001 From: Alexis Degrugillier Date: Sun, 20 Nov 2022 08:50:27 -0500 Subject: Fix feed ordering (#4841) Before, the feeds were not ordered every time there was a change in the category feed list. This behavior was causing discrepancies in the displayed list. Now, the feeds are ordered every time there is a change in the category feed list. See #4790 --- tests/app/Models/CategoryTest.php | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'tests/app/Models/CategoryTest.php') diff --git a/tests/app/Models/CategoryTest.php b/tests/app/Models/CategoryTest.php index e4a921baa..93fbdbc63 100644 --- a/tests/app/Models/CategoryTest.php +++ b/tests/app/Models/CategoryTest.php @@ -30,4 +30,54 @@ class CategoryTest extends PHPUnit\Framework\TestCase { ); } + public function test_feedOrdering() { + $feed_1 = $this->getMockBuilder(FreshRSS_Feed::class) + ->disableOriginalConstructor() + ->getMock(); + $feed_1->expects($this->any()) + ->method('name') + ->willReturn('AAA'); + + $feed_2 = $this->getMockBuilder(FreshRSS_Feed::class) + ->disableOriginalConstructor() + ->getMock(); + $feed_2->expects($this->any()) + ->method('name') + ->willReturn('ZZZ'); + + $feed_3 = $this->getMockBuilder(FreshRSS_Feed::class) + ->disableOriginalConstructor() + ->getMock(); + $feed_3->expects($this->any()) + ->method('name') + ->willReturn('lll'); + + $category = new FreshRSS_Category('test', [ + $feed_1, + $feed_2, + $feed_3, + ]); + $feeds = $category->feeds(); + + $this->assertCount(3, $feeds); + $this->assertEquals('AAA', $feeds[0]->name()); + $this->assertEquals('lll', $feeds[1]->name()); + $this->assertEquals('ZZZ', $feeds[2]->name()); + + $feed_4 = $this->getMockBuilder(FreshRSS_Feed::class) + ->disableOriginalConstructor() + ->getMock(); + $feed_4->expects($this->any()) + ->method('name') + ->willReturn('BBB'); + + $category->addFeed($feed_4); + $feeds = $category->feeds(); + + $this->assertCount(4, $feeds); + $this->assertEquals('AAA', $feeds[0]->name()); + $this->assertEquals('BBB', $feeds[1]->name()); + $this->assertEquals('lll', $feeds[2]->name()); + $this->assertEquals('ZZZ', $feeds[3]->name()); + } } -- cgit v1.2.3