summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwebchick2013-09-15 06:49:08 (GMT)
committerwebchick2013-09-15 06:49:08 (GMT)
commitde06734189f057bc136ec93f878bc330733815c4 (patch)
tree59801dbd8fc83c3a667024a199494f49d754eaeb
parent29f50ae3cb8dc8863071434606fe931c081da441 (diff)
Issue #1987598 by disasm, mparker17, Niklas Fiekas, rabellamy | vijaycs85: Convert aggregator_test_feed() and aggregator_test_redirect() to a new style controller.
-rw-r--r--core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module74
-rw-r--r--core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml17
-rw-r--r--core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php80
3 files changed, 97 insertions, 74 deletions
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..b3d9bbc 100644
--- a/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module
+++ b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.module
@@ -1,75 +1 @@
<?php
-
-use Drupal\Component\Utility\Crypt;
-use Symfony\Component\HttpFoundation\RedirectResponse;
-
-/**
- * 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",
- 'page callback' => 'aggregator_test_redirect',
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- );
- return $items;
-}
-
-/**
- * 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() {
- return new RedirectResponse(url('aggregator/test-feed', array('absolute' => TRUE)), 301);
-}
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..dff02c6
--- /dev/null
+++ b/core/modules/aggregator/tests/modules/aggregator_test/aggregator_test.routing.yml
@@ -0,0 +1,17 @@
+aggregator_test_feed:
+ pattern: '/aggregator/test-feed/{use_last_modified}/{use_etag}'
+ defaults:
+ _controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::testFeed'
+ _title: 'Test feed static last modified date'
+ use_last_modified: FALSE
+ use_etag: FALSE
+ requirements:
+ _permission: 'access content'
+
+aggregator_redirect:
+ pattern: '/aggregator/redirect'
+ defaults:
+ _controller: '\Drupal\aggregator_test\Controller\AggregatorTestRssController::testRedirect'
+ _title: 'Test feed with a redirect'
+ 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..6c2b1cd
--- /dev/null
+++ b/core/modules/aggregator/tests/modules/aggregator_test/lib/Drupal/aggregator_test/Controller/AggregatorTestRssController.php
@@ -0,0 +1,80 @@
+<?php
+/**
+ * @file
+ * Contains \Drupal\aggregator_test\Controller\AggregatorTestRssController.
+ */
+
+namespace Drupal\aggregator_test\Controller;
+
+use Drupal\Core\Controller\ControllerBase;
+use Drupal\Component\Utility\Crypt;
+use Symfony\Component\HttpFoundation\Response;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Controller for the aggregator_test module.
+ */
+class AggregatorTestRssController extends ControllerBase {
+
+ /**
+ * 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.
+ * @param Request $request
+ * Information about the current HTTP request.
+ *
+ * @return \Symfony\Component\HttpFoundation\Response
+ * A feed that forces cache validation.
+ */
+ public function testFeed($use_last_modified, $use_etag, Request $request) {
+ $response = new Response();
+
+ $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) {
+ $response->headers->set('Last-Modified', gmdate(DATE_RFC1123, $last_modified));
+ }
+ if ($use_etag) {
+ $response->headers->set('ETag', $etag);
+ }
+ // Return 304 not modified if either last modified or etag match.
+ if ($last_modified == $if_modified_since || $etag == $if_none_match) {
+ $response->setStatusCode(304);
+ return $response;
+ }
+
+ // The following headers force validation of cache.
+ $response->headers->set('Expires', 'Sun, 19 Nov 1978 05:00:00 GMT');
+ $response->headers->set('Cache-Control', 'must-revalidate');
+ $response->headers->set('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);
+
+ $response->setContent($feed);
+ return $response;
+ }
+
+ /**
+ * Generates a rest redirect to the test feed.
+ *
+ * @return \Symfony\Component\HttpFoundation\RedirectResponse
+ * A response that redirects users to the test feed.
+ */
+ public function testRedirect() {
+ return $this->redirect('aggregator_test_feed', array(), 301);
+ }
+
+}