diff --git a/amp.admin.inc b/amp.admin.inc index 1e4a3eb..098dfd2 100644 --- a/amp.admin.inc +++ b/amp.admin.inc @@ -48,8 +48,8 @@ function amp_admin_form($form, &$form_state) { '#default_value' => variable_get('amp_url_format', 'query_string'), '#options' => array( 'query_string' => 'Query string (www.example.com/article?amp)', - 'suffix' => 'Path suffix (www.example.com/article/amp)', 'prefix' => 'Path prefix (www.example.com/amp/article)', + 'suffix' => 'Path suffix (www.example.com/article/amp)', ), '#description' => t('Choose how your amp urls look.'), ); @@ -186,14 +186,14 @@ function amp_admin_form($form, &$form_state) { /** * Submit handler for the amp_admin_form * Clears the Drupal cache if the AMP Library warnings display checkbox value is changed - * + * * @param type $form * @param type $form_state */ function amp_admin_form_submit($form, &$form_state) { if (variable_get('amp_library_warnings_display', false) !== $form_state['values']['amp_library_warnings_display']) { cache_clear_all(); - drupal_set_message(t('AMP Library debugging checkbox changed. Cleared cache.')); + drupal_set_message(t('AMP Library debugging checkbox changed. Cleared cache.')); } } diff --git a/amp.test b/amp.test index 57cb864..7006a86 100644 --- a/amp.test +++ b/amp.test @@ -125,6 +125,8 @@ class AmpTestUrlFormats extends DrupalWebTestCase { * Test the url with query string ?amp. */ public function testAmpUrlFormatQueryString() { + global $base_url; + // Login as an admin user. $this->drupalLogin($this->admin_user); @@ -145,6 +147,16 @@ class AmpTestUrlFormats extends DrupalWebTestCase { ]; $this->drupalPost(NULL, $edit, t('Save')); + // Check link rel on full display. + $this->drupalGet('foo'); + $this->assertResponse(200); + $this->assertRaw('link rel="amphtml" href="' . $base_url . '/foo?amp"'); + + // Same check as above, using node/nid. + $this->drupalGet('node/1'); + $this->assertResponse(200); + $this->assertRaw('link rel="amphtml" href="' . $base_url . '/foo?amp"'); + // Check AMP page with prefix path 'amp' should 404. $this->drupalGet('amp/foo'); $this->assertResponse(404); @@ -157,6 +169,7 @@ class AmpTestUrlFormats extends DrupalWebTestCase { $this->drupalGet('foo', array('query' => array('amp' => NULL))); $this->assertResponse(200); $this->assertRaw('assertRaw('link rel="canonical" href="' . $base_url . '/foo"'); // Check admin UI is not an amp page. $this->drupalGet('node/1/edit', array('query' => array('amp' => NULL))); @@ -167,6 +180,8 @@ class AmpTestUrlFormats extends DrupalWebTestCase { * Test the url with prefix path 'amp'. */ public function testAmpUrlFormatPrefix() { + global $base_url; + // Login as an admin user. $this->drupalLogin($this->admin_user); @@ -188,30 +203,45 @@ class AmpTestUrlFormats extends DrupalWebTestCase { ]; $this->drupalPost(NULL, $edit, t('Save')); + // Check link rel on full display. + $this->drupalGet('foo'); + $this->assertResponse(200); + $this->assertRaw('link rel="amphtml" href="' . $base_url . '/amp/foo"'); + + // Same check as above, using node/nid. + $this->drupalGet('node/1'); + $this->assertResponse(200); + $this->assertRaw('link rel="amphtml" href="' . $base_url . '/amp/foo"'); + // Check AMP page with prefix path 'amp' should work. $this->drupalGet('amp/foo'); $this->assertResponse(200); $this->assertRaw('assertRaw('link rel="canonical" href="' . $base_url . '/foo"'); // Check AMP page with suffix path 'amp' should 404. $this->drupalGet('foo/amp'); $this->assertResponse(404); - // Check AMP page with query string ?amp should show a normal page. + // Check AMP page with query string ?amp should show full display. $this->drupalGet('foo', array('query' => array('amp' => NULL))); $this->assertResponse(200); $this->assertNoRaw('assertRaw('link rel="amphtml" href="' . $base_url . '/amp/foo"'); - // This should show a normal page. + // This should show full display. $this->drupalGet('foo'); $this->assertResponse(200); $this->assertNoRaw('assertRaw('link rel="amphtml" href="' . $base_url . '/amp/foo"'); } /** * Test the url with suffix path 'amp'. */ public function testAmpUrlFormatSuffix() { + global $base_url; + // Login as an admin user. $this->drupalLogin($this->admin_user); @@ -233,6 +263,16 @@ class AmpTestUrlFormats extends DrupalWebTestCase { ]; $this->drupalPost(NULL, $edit, t('Save')); + // Check link rel on full display. + $this->drupalGet('foo'); + $this->assertResponse(200); + $this->assertRaw('link rel="amphtml" href="' . $base_url . '/foo/amp"'); + + // Same check as above, using node/nid. + $this->drupalGet('node/1'); + $this->assertResponse(200); + $this->assertRaw('link rel="amphtml" href="' . $base_url . '/foo/amp"'); + // Check AMP page with prefix path 'amp' should 404. $this->drupalGet('amp/foo'); $this->assertResponse(404); @@ -241,16 +281,19 @@ class AmpTestUrlFormats extends DrupalWebTestCase { $this->drupalGet('foo/amp'); $this->assertResponse(200); $this->assertRaw('assertRaw('link rel="canonical" href="' . $base_url . '/foo"'); - // Check AMP page with query string ?amp should show a normal page. + // Check AMP page with query string ?amp should show full display. $this->drupalGet('foo', array('query' => array('amp' => NULL))); $this->assertResponse(200); $this->assertNoRaw('assertRaw('link rel="amphtml" href="' . $base_url . '/foo/amp"'); - // This should show a normal page. + // This should show full display. $this->drupalGet('foo'); $this->assertResponse(200); $this->assertNoRaw('assertRaw('link rel="amphtml" href="' . $base_url . '/foo/amp"'); } }