Skip to content

Instantly share code, notes, and snippets.

@rabellamy
Created August 16, 2013 02:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rabellamy/6246609 to your computer and use it in GitHub Desktop.
Save rabellamy/6246609 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<rss version="0.91">
<channel>
<title>Example</title>
<link>http://example.com</link>
<description>Example updates</description>
<language>en-us</language>
<copyright>Copyright 2000, Example team.</copyright>
<managingEditor>editor@example.com</managingEditor>
<webMaster>webmaster@example.com</webMaster>
<image>
<title>Example</title>
<url>http://example.com/images/druplicon.png</url>
<link>http://example.com</link>
<width>88</width>
<height>100</height>
<description>Example updates</description>
</image>
<item>
<title>First example feed item title</title>
<link>http://example.com/example-turns-one</link>
<description>First example feed item description.</description>
</item>
<item>
<title>Second example feed item title. This title is extremely long so that it exceeds the 255 character limit for titles in feed item storage. In fact it's so long that this sentence isn't long enough so I'm rambling a bit to make it longer, nearly there now. Ah now it's long enough so I'll shut up.</title>
<link>http://example.com/example-turns-two</link>
<description>Second example feed item description.</description>
</item>
<item>
<title>Long link feed item title.</title>
<link>http://example.com/tomorrow/and/tomorrow/and/tomorrow/creeps/in/this/petty/pace/from/day/to/day/to/the/last/syllable/of/recorded/time/and/all/our/yesterdays/have/lighted/fools/the/way/to/dusty/death/out/out/brief/candle/life/is/but/a/walking/shadow/a/poor/player/that/struts/and/frets/his/hour/upon/the/stage/and/is/heard/no/more/it/is/a/tale/told/by/an/idiot/full/of/sound/and/fury/signifying/nothing</link>
<description>Long link feed item description.</description>
</item>
<item>
<title>Long author feed item title.</title>
<link>http://example.com/long/author</link>
<author>I wanted to get out and walk eastward toward the park through the soft twilight, but each time I tried to go I became entangled in some wild, strident argument which pulled me back, as if with ropes, into my chair. Yet high over the city our line of yellow windows must have contributed their share of human secrecy to the casual watcher in the darkening streets, and I was him too, looking up and wondering. I was within and without, simultaneously enchanted and repelled by the inexhaustible variety of life.</author>
<description>Long author feed item description.</description>
</item>
</channel>
</rss>
diff --git a/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml
index 97e91d4..58017c9 100644
--- a/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml
+++ b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml
@@ -1,7 +1,10 @@
aggregator_test_feed:
- pattern: 'aggregator/test-feed'
+# pattern: '/aggregator/test-feed/{use_last_modified}/{use_etag}'
+ pattern: '/aggregator/test-feed'
defaults:
_controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::feed'
+# use_last_modified: 'FALSE'
+# use_etag: 'FALSE'
requirements:
_permission: 'access content'
diff --git a/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php
index 1cdc1da..698d6a0 100644
--- a/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php
+++ b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php
@@ -8,10 +8,16 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Component\Utility\Crypt;
+use Drupal\Core\Controller\ControllerInterface;
class AggregatorTestRssController implements ControllerInterface {
+ public static function create(ContainerInterface $container) {
+ return new static();
+ }
+
/**
* Generates a test feed and simulates last-modified and etags.
*
@@ -20,7 +26,7 @@ class AggregatorTestRssController implements ControllerInterface {
* @param $use_etag
* Set TRUE to send an etag.
*/
- public function feed($use_last_modified = FALSE, $use_etag = FALSE, Request $request) {
+ public function feed(Request $request, $use_last_modified = FALSE, $use_etag = FALSE) {
$last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
$etag = Crypt::hashBase64($last_modified);
@@ -47,7 +53,7 @@ public function feed($use_last_modified = FALSE, $use_etag = FALSE, Request $req
drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
// Read actual feed from file.
- $file_name = __DIR__ . '/aggregator_test_rss091.xml';
+ $file_name = drupal_get_path('module', 'aggregator_test') . '/aggregator_test_rss091.xml';
$handle = fopen($file_name, 'r');
$feed = fread($handle, filesize($file_name));
fclose($handle);
diff --git a/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module
index 4427a3a..af33189 100644
--- a/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module
+++ b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module
@@ -7,13 +7,6 @@
* Implements hook_menu().
*/
function aggregator_test_menu() {
- $items['aggregator/test-feed'] = array(
- 'title' => 'Test feed static last modified date',
- 'description' => "A cached test feed with a static last modified date.",
- 'page callback' => 'aggregator_test_feed',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
$items['aggregator/redirect'] = array(
'title' => 'Test feed with a redirect',
'description' => "A feed that redirects to another one",
@@ -25,49 +18,6 @@ function aggregator_test_menu() {
}
/**
- * Page callback. Generates a test feed and simulates last-modified and etags.
- *
- * @param $use_last_modified
- * Set TRUE to send a last modified header.
- * @param $use_etag
- * Set TRUE to send an etag.
- */
-function aggregator_test_feed($use_last_modified = FALSE, $use_etag = FALSE) {
- $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
- $etag = Crypt::hashBase64($last_modified);
-
- $if_modified_since = strtotime(Drupal::request()->server->get('HTTP_IF_MODIFIED_SINCE'));
- $if_none_match = stripslashes(Drupal::request()->server->get('HTTP_IF_NONE_MATCH'));
-
- // Send appropriate response. We respond with a 304 not modified on either
- // etag or on last modified.
- if ($use_last_modified) {
- drupal_add_http_header('Last-Modified', gmdate(DATE_RFC1123, $last_modified));
- }
- if ($use_etag) {
- drupal_add_http_header('ETag', $etag);
- }
- // Return 304 not modified if either last modified or etag match.
- if ($last_modified == $if_modified_since || $etag == $if_none_match) {
- drupal_add_http_header('Status', '304 Not Modified');
- return;
- }
-
- // The following headers force validation of cache:
- drupal_add_http_header('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
- drupal_add_http_header('Cache-Control', 'must-revalidate');
- drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
-
- // Read actual feed from file.
- $file_name = __DIR__ . '/aggregator_test_rss091.xml';
- $handle = fopen($file_name, 'r');
- $feed = fread($handle, filesize($file_name));
- fclose($handle);
-
- print $feed;
-}
-
-/**
* Page callback that redirects to another feed.
*/
function aggregator_test_redirect() {
diff --git a/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml
new file mode 100644
index 0000000..58017c9
--- /dev/null
+++ b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml
@@ -0,0 +1,10 @@
+aggregator_test_feed:
+# pattern: '/aggregator/test-feed/{use_last_modified}/{use_etag}'
+ pattern: '/aggregator/test-feed'
+ defaults:
+ _controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::feed'
+# use_last_modified: 'FALSE'
+# use_etag: 'FALSE'
+ requirements:
+ _permission: 'access content'
+
diff --git a/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php
new file mode 100644
index 0000000..698d6a0
--- /dev/null
+++ b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php
@@ -0,0 +1,65 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\aggregator_test\Controller\AggregatorTestRssController.
+ */
+
+namespace Drupal\aggregator_test\Controller;
+
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+use Drupal\Component\Utility\Crypt;
+use Drupal\Core\Controller\ControllerInterface;
+
+class AggregatorTestRssController implements ControllerInterface {
+
+ public static function create(ContainerInterface $container) {
+ return new static();
+ }
+
+ /**
+ * Generates a test feed and simulates last-modified and etags.
+ *
+ * @param $use_last_modified
+ * Set TRUE to send a last modified header.
+ * @param $use_etag
+ * Set TRUE to send an etag.
+ */
+ public function feed(Request $request, $use_last_modified = FALSE, $use_etag = FALSE) {
+ $last_modified = strtotime('Sun, 19 Nov 1978 05:00:00 GMT');
+ $etag = Crypt::hashBase64($last_modified);
+
+ $if_modified_since = strtotime($request->server->get('HTTP_IF_MODIFIED_SINCE'));
+ $if_none_match = stripslashes($request->server->get('HTTP_IF_NONE_MATCH'));
+
+ // Send appropriate response. We respond with a 304 not modified on either
+ // etag or on last modified.
+ if ($use_last_modified) {
+ drupal_add_http_header('Last-Modified', gmdate(DATE_RFC1123, $last_modified));
+ }
+ if ($use_etag) {
+ drupal_add_http_header('ETag', $etag);
+ }
+ // Return 304 not modified if either last modified or etag match.
+ if ($last_modified == $if_modified_since || $etag == $if_none_match) {
+ drupal_add_http_header('Status', '304 Not Modified');
+ return;
+ }
+
+ // The following headers force validation of cache:
+ drupal_add_http_header('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
+ drupal_add_http_header('Cache-Control', 'must-revalidate');
+ drupal_add_http_header('Content-Type', 'application/rss+xml; charset=utf-8');
+
+ // Read actual feed from file.
+ $file_name = drupal_get_path('module', 'aggregator_test') . '/aggregator_test_rss091.xml';
+ $handle = fopen($file_name, 'r');
+ $feed = fread($handle, filesize($file_name));
+ fclose($handle);
+
+ return new Response($feed);
+
+ }
+
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment