? ? PR-4.4-dev Pending

User tests: Successful: Unsuccessful:

avatar rajputanuj31
rajputanuj31
10 Apr 2023

add a test for single feed view.

avatar joomla-cms-bot joomla-cms-bot - change - 10 Apr 2023
Category JavaScript Unit Tests
avatar rajputanuj31 rajputanuj31 - open - 10 Apr 2023
avatar rajputanuj31 rajputanuj31 - change - 10 Apr 2023
Status New Pending
avatar rajputanuj31 rajputanuj31 - change - 10 Apr 2023
Labels Added: ? PR-4.4-dev
avatar rajputanuj31 rajputanuj31 - change - 11 Apr 2023
Labels Added: ?
avatar laoneo
laoneo - comment - 12 Apr 2023

Can you use as feed link "Cypress.config('baseUrl')+'/index.php?option=com_content&view=category&id=2&format=feed&type=rss'"? The joomla.org admin would not like us when we would fetch on every pr commit a feed. To make it work then we need to stabilize the FeedFactory, can you replace the file /libraries/src/Feed/FeedFactory.php with the following content:

<?php

/**
 * Joomla! Content Management System
 *
 * @copyright  (C) 2012 Open Source Matters, Inc. <https://www.joomla.org>
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

namespace Joomla\CMS\Feed;

use Joomla\CMS\Http\HttpFactory;
use Joomla\Registry\Registry;

// phpcs:disable PSR1.Files.SideEffects
\defined('JPATH_PLATFORM') or die;
// phpcs:enable PSR1.Files.SideEffects

/**
 * Feed factory class.
 *
 * @since  3.1.4
 */
class FeedFactory
{
    /**
     * @var    array  The list of registered parser classes for feeds.
     * @since  3.1.4
     */
    protected $parsers = ['rss' => 'Joomla\\CMS\\Feed\\Parser\\RssParser', 'feed' => 'Joomla\\CMS\\Feed\\Parser\\AtomParser'];

    /**
     * Method to load a URI into the feed reader for parsing.
     *
     * @param   string  $uri  The URI of the feed to load. Idn uris must be passed already converted to punycode.
     *
     * @return  Feed
     *
     * @since   3.1.4
     * @throws  \InvalidArgumentException
     * @throws  \RuntimeException
     */
    public function getFeed($uri)
    {
        // Create the XMLReader object.
        $reader = new \XMLReader();

        // Open the URI within the stream reader.
        if (!@$reader->open($uri, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
           $this->readFeed($uri, $reader);
        }

        // Get the feed
        $type = $this->getType($reader);

        // Open can succeed but the feed is empty, so we read the whole feed
        if (empty($type)) {
            $this->readFeed($uri, $reader);
            $type = $this->getType($reader);
        }

        // Setup the appropriate feed parser for the feed.
        $parser = $this->_fetchFeedParser($type, $reader);

        return $parser->parse();
    }

    /**
     * Method to register a FeedParser class for a given root tag name.
     *
     * @param   string   $tagName    The root tag name for which to register the parser class.
     * @param   string   $className  The FeedParser class name to register for a root tag name.
     * @param   boolean  $overwrite  True to overwrite the parser class if one is already registered.
     *
     * @return  FeedFactory
     *
     * @since   3.1.4
     * @throws  \InvalidArgumentException
     */
    public function registerParser($tagName, $className, $overwrite = false)
    {
        // Verify that the class exists.
        if (!class_exists($className)) {
            throw new \InvalidArgumentException('The feed parser class ' . $className . ' does not exist.');
        }

        // Validate that the tag name is valid.
        if (!preg_match('/\A(?!XML)[a-z][\w0-9-]*/i', $tagName)) {
            throw new \InvalidArgumentException('The tag name ' . $tagName . ' is not valid.');
        }

        // Register the given parser class for the tag name if nothing registered or the overwrite flag set.
        if (empty($this->parsers[$tagName]) || (bool) $overwrite) {
            $this->parsers[(string) $tagName] = (string) $className;
        }

        return $this;
    }

    /**
     * Method to get the registered Parsers
     *
     * @return array
     *
     * @since   4.0.0
     */
    public function getParsers()
    {
        return $this->parsers;
    }

    /**
     * Method to return a new JFeedParser object based on the registered parsers and a given type.
     *
     * @param   string      $type    The name of parser to return.
     * @param   \XMLReader  $reader  The XMLReader instance for the feed.
     *
     * @return  FeedParser
     *
     * @since   3.1.4
     * @throws  \LogicException
     */
    private function _fetchFeedParser($type, \XMLReader $reader)
    {
        // Look for a registered parser for the feed type.
        if (empty($this->parsers[$type])) {
            throw new \LogicException('No registered feed parser for type ' . $type . '.');
        }

        return new $this->parsers[$type]($reader);
    }

    /**
     * Detects the type of the feed, returns an empty string when it can't be detected.
     *
     * @param   \XMLReader  $reader  The XMLReader instance
     *
     * @return  string
     *
     * @since   __DEPLOY_VERSION__
     * @throws  \RuntimeException
     */
    private function getType(\XMLReader $reader): string
    {
        try {
            // Skip ahead to the root node.
            while ($reader->read()) {
                if ($reader->nodeType == \XMLReader::ELEMENT) {
                    break;
                }
            }

            return $reader->name;
        } catch (\Exception $e) {
            throw new \RuntimeException('Error reading feed.', $e->getCode(), $e);
        }
    }

    /**
     * Reads the feed through the HttpFactory into th XMLReader.
     *
     * @param   string      $uri     The uri
     * @param   \XMLReader  $reader  The XMLReader instance
     *
     * @return  void
     *
     * @since   __DEPLOY_VERSION__
     * @throws  \RuntimeException
     */
    private function readFeed($uri, \XMLReader $reader): void
    {
         // Retry with HttpFactory that allow using CURL and Sockets as alternative method when available

        // Adding a valid user agent string, otherwise some feed-servers returning an error
        $options = new Registry();
        $options->set('userAgent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:41.0) Gecko/20100101 Firefox/41.0');

        try {
            $response = HttpFactory::getHttp($options)->get($uri);
        } catch (\RuntimeException $e) {
            throw new \RuntimeException('Unable to open the feed.', $e->getCode(), $e);
        }

        if ($response->code != 200) {
            throw new \RuntimeException('Unable to open the feed.');
        }

        // Set the value to the XMLReader parser
        if (!$reader->XML($response->body, null, LIBXML_NOERROR | LIBXML_ERR_NONE | LIBXML_NOWARNING)) {
            throw new \RuntimeException('Unable to parse the feed.');
        }
    }
}
avatar laoneo
laoneo - comment - 12 Apr 2023

Can you rename the file to Newsfeed.cy.js

avatar brianteeman
brianteeman - comment - 12 Apr 2023

The joomla.org admin would not like us when we would fetch on every pr commit a feed.

Would it not be better to test with a real external rss feed as the source. I am sure there must be some that exist for this purpose. If not then use the feed from a popular news site.

avatar laoneo
laoneo - comment - 12 Apr 2023

I guess this would lead us sooner or later to a ban as the two tests are currently running on 6 different setups within the same drone run. This on every pr commit. And whenever possible try to avoid outside connections in system tests as there will also be connection issues. But it brings me to another idea, to place a temporary feed file instead of using our own feed.

avatar laoneo
laoneo - comment - 12 Apr 2023

A new idea, can you put the following content into the file /tests/System/data/com_newsfeeds/joomla.org.xml:

<?xml version="1.0" encoding="utf-8"?>
<!-- generator="Joomla! - Open Source Content Management" -->
<?xml-stylesheet href="/plugins/system/jce/css/content.css?badb4208be409b1335b815dde676300e" type="text/css"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Joomla! Official News</title>
		<description><![CDATA[Joomla! - the dynamic portal engine and content management system]]></description>
		<link>https://www.joomla.org/announcements.html</link>
		<lastBuildDate>Wed, 12 Apr 2023 19:48:43 +0000</lastBuildDate>
		<generator>Joomla! - Open Source Content Management</generator>
		<atom:link rel="self" type="application/rss+xml" href="https://www.joomla.org/announcements.feed?type=rss"/>
		<language>en-gb</language>
		<managingEditor>noreply@joomla.org (Joomla!)</managingEditor>
		<item>
			<title>Joomla 4.3.0 Release Candidate 3 - test the final package</title>
			<link>https://www.joomla.org/announcements/release-news/5883-joomla-4-3-0-release-candidate-3-test-the-final-package.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5883-joomla-4-3-0-release-candidate-3-test-the-final-package.html</guid>
			<description><![CDATA[
<p class="lead">The Joomla Project is pleased to announce the availability of Joomla 4.3.0 Release Candidate 3 for testing.</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Wed, 12 Apr 2023 06:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.3.0 Release Candidate 2 - test the final package</title>
			<link>https://www.joomla.org/announcements/release-news/5881-joomla-4-3-0-release-candidate-2-test-the-final-package.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5881-joomla-4-3-0-release-candidate-2-test-the-final-package.html</guid>
			<description><![CDATA[
<p class="lead">The Joomla Project is pleased to announce the availability of Joomla 4.3.0 Release Candidate 2 for testing.</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Sun, 02 Apr 2023 06:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.3.0 Release Candidate 1 - test the final package</title>
			<link>https://www.joomla.org/announcements/release-news/5880-joomla-4-3-0-release-candidate-1-test-the-final-package.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5880-joomla-4-3-0-release-candidate-1-test-the-final-package.html</guid>
			<description><![CDATA[
<p class="lead">The Joomla Project is pleased to announce the availability of Joomla 4.3.0 Release Candidate 1 for testing.</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Mon, 20 Mar 2023 06:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.2.9 Bug Fix Release</title>
			<link>https://www.joomla.org/announcements/release-news/5879-joomla-4-2-9-bug-fix-release.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5879-joomla-4-2-9-bug-fix-release.html</guid>
			<description><![CDATA[
<p class="lead">Joomla! 4.2.9 is now available. This is a Bug Fix release for the 4.x series of Joomla!</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Tue, 14 Mar 2023 06:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.2.8 Security Release</title>
			<link>https://www.joomla.org/announcements/release-news/5878-joomla-4-2-8-security-release.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5878-joomla-4-2-8-security-release.html</guid>
			<description><![CDATA[
<p class="lead">Joomla! 4.2.8 is now available. This is a security release for the 4.x series of Joomla! which addresses a critical security vulnerability in the web services API. We strongly recommend that you update your sites immediately.</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Thu, 16 Feb 2023 07:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla! 4.2.8 - Important Security Announcement - Patch Available Soon</title>
			<link>https://www.joomla.org/announcements/release-news/5877-joomla-4-2-8-important-security-announcement-patch-available-soon.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5877-joomla-4-2-8-important-security-announcement-patch-available-soon.html</guid>
			<description><![CDATA[
<p class="lead">A Joomla 4.2.8 release containing a security fix will be published on Thursday, 16th February at approximately 16:00 UTC</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Mon, 13 Feb 2023 17:00:00 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.2.7 Security and Bug Fix Release</title>
			<link>https://www.joomla.org/announcements/release-news/5876-joomla-4-2-7-security-and-bug-fix-release.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5876-joomla-4-2-7-security-and-bug-fix-release.html</guid>
			<description><![CDATA[
<p class="lead">Joomla 4.2.7 is now available. This is a security and bug fix release for the 4.x series of Joomla.</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Tue, 31 Jan 2023 07:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.2.6 Bug Fix Release </title>
			<link>https://www.joomla.org/announcements/release-news/5875-joomla-4-2-6-bug-fix-release.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5875-joomla-4-2-6-bug-fix-release.html</guid>
			<description><![CDATA[
<p class="lead">Joomla 4.2.6 is now available. This is a bug fix release for the 4.x series of Joomla.</p>
]]></description>
			<author>feed@example.com (Joomla)</author>
			<category>Project Release News</category>
			<pubDate>Tue, 13 Dec 2022 07:56:30 +0000</pubDate>
		</item>
		<item>
			<title>Joomla 4.2.5 Security and Bug Fix release</title>
			<link>https://www.joomla.org/announcements/release-news/5873-joomla-4-2-5-security-and-bug-fix-release.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5873-joomla-4-2-5-security-and-bug-fix-release.html</guid>
			<description><![CDATA[
<p class="lead">Joomla 4.2.5 is now available. This is a security and bug fix release for the 4.x series of Joomla which addresses 1 security vulnerability.</p>
]]></description>
			<author>feed@example.com (The Joomla! Project)</author>
			<category>Project Release News</category>
			<pubDate>Tue, 08 Nov 2022 06:00:00 +0000</pubDate>
		</item>
		<item>
			<title>Sunset on GLIP as Joomla welcomes Mattermost</title>
			<link>https://www.joomla.org/announcements/release-news/5874-sunset-on-glip-as-joomla-welcomes-mattermost.html</link>
			<guid isPermaLink="true">https://www.joomla.org/announcements/release-news/5874-sunset-on-glip-as-joomla-welcomes-mattermost.html</guid>
			<description><![CDATA[
<p class="lead" style="margin: 10px 0;">We all have a new home for our daily communication.</p>
]]></description>
			<author>feed@example.com (Operations Department)</author>
			<category>Project Release News</category>
			<pubDate>Mon, 07 Nov 2022 06:59:32 +0000</pubDate>
		</item>
	</channel>
</rss>

This is a copy from the official Joomla feed, but locally saved. Like that we can add multiple feeds from different sites and store them locally.

avatar laoneo
laoneo - comment - 12 Apr 2023

Can you rename the file to NewsFeed.cy.js?

avatar rajputanuj31
rajputanuj31 - comment - 13 Apr 2023

what link should I have to use???

avatar laoneo
laoneo - comment - 13 Apr 2023

I'v added it already to your code. Like that you can add more files into the data directory and adapt the foreach array with the new names.

avatar laoneo laoneo - change - 13 Apr 2023
Status Pending Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2023-04-13 11:19:29
Closed_By laoneo
avatar laoneo laoneo - close - 13 Apr 2023
avatar laoneo laoneo - merge - 13 Apr 2023
avatar laoneo
laoneo - comment - 13 Apr 2023

Thanks!

Add a Comment

Login with GitHub to post a comment