You are here

akamai.test in Akamai 7

Same filename and directory in other branches
  1. 8 akamai.test
  2. 8.2 akamai.test
  3. 7.3 akamai.test
  4. 7.2 akamai.test

Akamai tests.

File

akamai.test
View source
<?php

/**
 * @file
 * Akamai tests.
 */

/**
 * Test basic API.
 */
class AkamaiTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Akamai Tests',
      'description' => 'Test various Akamai cache clearings with paths and aliases.',
      'group' => 'Akamai',
    );
  }
  function setUp() {
    parent::setUp('akamai');
    $user = $this
      ->drupalCreateUser(array(
      'purge akamai cache',
    ));
    $this
      ->drupalLogin($user);
    variable_set('akamai_service_class', 'RecordingCacheControlClient');
  }

  /**
   * Tests clear.
   */
  function testDirectClear() {
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'promote' => 1,
    ));
    $canonical = "node/{$node->nid}";
    $akamai = akamai_get_class();
    $akamai
      ->clear_url($canonical);
    $paths = $akamai->paths;
    $this
      ->assertEqual(1, count($paths), "Only one path cleared");
    $this
      ->assertEqual($canonical, $paths[0]);
  }

  /**
   * Tests clear with no aliases.
   */
  function testSimpleClear() {
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'promote' => 1,
    ));
    $canonical = "node/{$node->nid}";
    $response = akamai_clear_url($canonical, array(), $node);
    $paths = $response['client']->paths;
    $this
      ->assertEqual(1, count($paths), "Only one path cleared");
    $this
      ->assertEqual($canonical, $paths[0], "Correct path was cleared");
  }

  /**
   * Tests clear with 1 alias.
   */
  function testAliasClear() {
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'promote' => 1,
    ));
    $canonical = "node/{$node->nid}";
    $cleanurl = "content/pretty-title/{$node->nid}";
    $alias = array(
      'source' => $canonical,
      'alias' => $cleanurl,
    );
    path_save($alias);
    $response = akamai_clear_url($canonical, array(), $node);
    $paths = $response['client']->paths;
    $this
      ->assertEqual(2, count($paths), "Two paths cleared");
    $this
      ->assertEqual($canonical, $paths[0], "Correct canonical path was cleared");
    $this
      ->assertEqual($cleanurl, $paths[1], "Correct alias was cleared");
  }

  /**
   * Tests clear with multiple aliases.
   */
  function testMultipleAliasClear() {
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'promote' => 1,
    ));
    $canonical = "node/{$node->nid}";
    $cleanurl1 = "content/pretty-title/{$node->nid}";
    $cleanurl2 = "blog/better-title/{$node->nid}";
    $cleanurl3 = "article/another-title/{$node->nid}";
    $alias = array(
      'source' => $canonical,
      'alias' => $cleanurl1,
    );
    path_save($alias);
    $alias = array(
      'source' => $canonical,
      'alias' => $cleanurl2,
    );
    path_save($alias);
    $alias = array(
      'source' => $canonical,
      'alias' => $cleanurl3,
    );
    path_save($alias);
    $response = akamai_clear_url($canonical, array(), $node);
    $paths = $response['client']->paths;
    $this
      ->assertEqual(4, count($paths), "Four paths cleared");
    $this
      ->assertEqual($canonical, $paths[0], "Correct canonical path was cleared");
    $this
      ->assertEqual($cleanurl1, $paths[1], "Correct alias 1 path was cleared");
    $this
      ->assertEqual($cleanurl2, $paths[2], "Correct alias 2 path was cleared");
    $this
      ->assertEqual($cleanurl3, $paths[3], "Correct alias 3 path was cleared");
  }

}

/**
 * Test basic API.
 */
class AkamaiHomepageTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Akamai Homepage Clearing',
      'description' => 'Test Akamai cache clearings of the site homepage.',
      'group' => 'Akamai',
    );
  }
  function setUp() {
    parent::setUp('akamai');
    $user = $this
      ->drupalCreateUser(array(
      'purge akamai cache',
    ));
    $this
      ->drupalLogin($user);
    variable_set('akamai_service_class', 'RecordingCacheControlClient');
    $this->node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
    ));
    $this->homepage = "node/{$this->node->nid}";
    variable_set('site_frontpage', $this->homepage);
  }

  /**
   * Tests clear of homepage and rendering of block
   */
  function testHomepageClear() {
    $block = block_load('akamai', 'akamai');
    db_update('block')
      ->fields(array(
      'region' => 'footer',
      'status' => 1,
    ))
      ->condition('module', $block->module)
      ->condition('delta', $block->delta)
      ->condition('theme', $block->theme)
      ->execute();
    $this
      ->drupalGet($this->homepage);
    $this
      ->assertFieldByName('path', $this->homepage, 'The Akamai path field is set correctly');
    $this
      ->assertUniqueText(t('[frontpage]'), t('Make sure the text "[frontpage]" appears exactly once on the home page.'));
    $response = akamai_clear_url($this->homepage, array(), $this->node);
    $paths = $response['client']->paths;
    $this
      ->assertEqual(2, count($paths), "Two paths cleared");
    $this
      ->assertEqual($this->homepage, $paths[0], "Correct homepage real path was cleared");
    $this
      ->assertEqual('', $paths[1], "Correct homepage path was cleared");
  }

}

/**
 * Test basic API.
 */
class AkamaiHookTestCase extends DrupalWebTestCase {
  public static function getInfo() {
    return array(
      'name' => 'Akamai Hook Test',
      'description' => 'Test the implementation of the hooks defined by the Akamai module',
      'group' => 'Akamai',
    );
  }
  function setUp() {
    parent::setUp('akamai', 'akamai_test');
    $user = $this
      ->drupalCreateUser(array(
      'purge akamai cache',
    ));
    $this
      ->drupalLogin($user);
    variable_set('akamai_service_class', 'RecordingCacheControlClient');
  }

  /**
   * Tests clear with hook provided paths.
   */
  function testHookClear() {
    $node = $this
      ->drupalCreateNode(array(
      'type' => 'page',
      'promote' => 1,
    ));
    $canonical = "node/{$node->nid}";
    $response = akamai_clear_url($canonical, array(), $node);
    $paths = $response['client']->paths;
    $this
      ->assertEqual(2, count($paths), "Two paths cleared");
    $this
      ->assertEqual($canonical, $paths[0], "Correct canonical path was cleared");
    $this
      ->assertEqual("akamai/paths/alter/test", $paths[1], "Correct hook provided path was cleared");
  }

  /**
   * Tests clear with no paths.
   */
  function testEmptyClear() {
    $response = akamai_clear_url('clear/me');
    $this
      ->assertFalse($response, "False returned");
  }

}

Classes

Namesort descending Description
AkamaiHomepageTestCase Test basic API.
AkamaiHookTestCase Test basic API.
AkamaiTestCase Test basic API.