FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
294
sites/all/modules/contrib/fields/location/tests/cow.test
Normal file
294
sites/all/modules/contrib/fields/location/tests/cow.test
Normal file
@@ -0,0 +1,294 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Location saving test.
|
||||
*/
|
||||
|
||||
require_once drupal_get_path('module', 'location') . '/tests/location_testcase.php';
|
||||
|
||||
class CowInstanceTest extends LocationTestCase {
|
||||
/**
|
||||
* A global administrative user.
|
||||
*/
|
||||
var $admin_user;
|
||||
|
||||
/**
|
||||
* A global normal user.
|
||||
*/
|
||||
var $normal_user;
|
||||
|
||||
/**
|
||||
* Simple content type using defaults.
|
||||
*/
|
||||
var $content_type;
|
||||
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Location Copy on Write checks'),
|
||||
'description' => t('Test corner cases of the copy on write mechanism.'),
|
||||
'group' => t('Location'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('location', 'location_node', 'devel');
|
||||
$web_admin = $this->drupalCreateUser(array('administer nodes', 'submit latitude/longitude', 'administer site configuration', 'access administration pages', 'administer content types'));
|
||||
$this->drupalLogin($web_admin);
|
||||
}
|
||||
|
||||
function testCreateLocation() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$this->assertEqual($location1_name, $node2->locations[0]['name'], t('Testing basic save/load'));
|
||||
}
|
||||
|
||||
function testLocpickOnly() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
'locpick' => array(
|
||||
'user_latitude' => '44.25',
|
||||
'user_longitude' => '-10.25',
|
||||
),
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
$this->pass(var_export($node2->locations, TRUE));
|
||||
$this->assertEqual($node2->locations[0]['latitude'], 44.25, t('Testing coordinate-only save/load'));
|
||||
}
|
||||
|
||||
function testMultipleLocationOnSingleNode() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings, array('multiple' => array('max' => 3, 'add' => 3)));
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
$location2_name = $this->randomName();
|
||||
$location3_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
1 => array(
|
||||
'name' => $location2_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
2 => array(
|
||||
'name' => $location3_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$this->assertEqual($location1_name, $node2->locations[0]['name'], t('Testing multi location 1/3'));
|
||||
$this->assertEqual($location2_name, $node2->locations[1]['name'], t('Testing multi location 2/3'));
|
||||
$this->assertEqual($location3_name, $node2->locations[2]['name'], t('Testing multi location 3/3'));
|
||||
$this->assertNotEqual($node2->locations[0]['lid'], $node2->locations[1]['lid'], t('Ensuring location id uniqueness'));
|
||||
$this->assertNotEqual($node2->locations[1]['lid'], $node2->locations[2]['lid'], t('Ensuring location id uniqueness'));
|
||||
$this->assertNotEqual($node2->locations[2]['lid'], $node2->locations[0]['lid'], t('Ensuring location id uniqueness'));
|
||||
}
|
||||
|
||||
function testSharedLocation() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
// Get the full location
|
||||
$location = $node->locations[0];
|
||||
|
||||
$node2 = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
'0' => $location,
|
||||
),
|
||||
));
|
||||
|
||||
// Reload second node.
|
||||
$node2 = node_load($node2->nid, NULL, TRUE);
|
||||
|
||||
$this->assertNotEqual($node->nid, $node2->nid, t('Ensuring nodes are seperate'));
|
||||
$this->assertEqual($node->locations[0]['lid'], $node2->locations[0]['lid'], t('Testing shared location'));
|
||||
|
||||
$this->deleteNode($node->nid);
|
||||
|
||||
// Force another reload.
|
||||
$node2 = node_load($node2->nid, NULL, TRUE);
|
||||
|
||||
$this->assertEqual($node2->locations[0]['lid'], $location['lid'], t('Ensuring shared location is not prematurely garbage collected'));
|
||||
|
||||
$this->deleteNode($node2->nid);
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $location['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->fail(t('Ensuring shared location is garbage collected'));
|
||||
}
|
||||
else {
|
||||
$this->pass(t('Ensuring shared location is garbage collected'));
|
||||
}
|
||||
}
|
||||
|
||||
function testNodeRevisionCOW() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings, array('multiple' => array('max' => 3, 'add' => 3)));
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
$location2_name = $this->randomName();
|
||||
$location3_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array( // First
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
1 => array( // Second
|
||||
'name' => $location2_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$changes = array(
|
||||
'revision' => TRUE,
|
||||
'log' => $this->randomName(20),
|
||||
'locations' => array(
|
||||
0 => array( // Delete First
|
||||
'delete_location' => TRUE,
|
||||
),
|
||||
2 => array( // Third
|
||||
'name' => $location3_name,
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->flattenPostData($changes);
|
||||
$this->drupalPost('node/'. $node->nid .'/edit', $changes, 'Save');
|
||||
|
||||
// Reload the node again.
|
||||
$node1 = node_load($node->nid, $node->vid, TRUE);
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
// Ensure locations are in a consistent order.
|
||||
$this->reorderLocations($node);
|
||||
$this->reorderLocations($node1);
|
||||
$this->reorderLocations($node2);
|
||||
|
||||
$this->assertEqual(count($node1->locations), 2, t('Ensuring second revision did not affect first revision'));
|
||||
$this->assertEqual($node->locations[0]['lid'], $node1->locations[0]['lid'], t('Ensuring second revision did not affect first revision'));
|
||||
$this->assertEqual($node->locations[1]['lid'], $node1->locations[1]['lid'], t('Ensuring second revision did not affect first revision'));
|
||||
|
||||
$this->assertEqual(count($node2->locations), 2, t('Ensuring second revision does not have stealth locations'));
|
||||
|
||||
// Delete first revision.
|
||||
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node1->nid, $node1->vid);
|
||||
node_invoke_nodeapi($node1, 'delete revision');
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->locations[0]['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->fail(t('Ensuring location on deleted revision is garbage collected'));
|
||||
}
|
||||
else {
|
||||
$this->pass(t('Ensuring location on deleted revision is garbage collected'));
|
||||
}
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->locations[1]['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->pass(t('Ensuring shared location on deleted revision is NOT garbage collected'));
|
||||
}
|
||||
else {
|
||||
$this->fail(t('Ensuring shared location on deleted revision is NOT garbage collected'));
|
||||
}
|
||||
}
|
||||
|
||||
function testCOWConservation() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$changes = array(
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
// Update name.
|
||||
'name' => $location1_name .'_CHANGE',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->flattenPostData($changes);
|
||||
$this->drupalPost('node/'. $node->nid .'/edit', $changes, 'Save');
|
||||
|
||||
// Reload the node again.
|
||||
$node1 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
// Ensure locations are in a consistent order.
|
||||
$this->reorderLocations($node);
|
||||
$this->reorderLocations($node1);
|
||||
|
||||
$this->assertEqual($node->locations[0]['lid'], $node1->locations[0]['lid'], t('Ensuring LIDs are conserved'));
|
||||
|
||||
}
|
||||
}
|
49
sites/all/modules/contrib/fields/location/tests/earth.test
Normal file
49
sites/all/modules/contrib/fields/location/tests/earth.test
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for earth.inc functionality.
|
||||
*/
|
||||
|
||||
require_once drupal_get_path('module', 'location') .'/earth.inc';
|
||||
require_once drupal_get_path('module', 'location') .'/tests/location_testcase.php';
|
||||
|
||||
class LocationEarthTest extends LocationTestCase {
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Location earth.inc tests'),
|
||||
'description' => t('Test earth.inc calculations.'),
|
||||
'group' => t('Location'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('location');
|
||||
}
|
||||
|
||||
function testXYZ() {
|
||||
$expected = array(5076436.1926031, 3086400.2318368, 2312685.5571307);
|
||||
$result = earth_xyz(31.299, 21.4);
|
||||
$this->assertArrayEpsilon($result, $expected, 0.01);
|
||||
|
||||
// Taj Mahal
|
||||
$expected = array(1179389.7524227, 605469.92806515, 6217918.5984722);
|
||||
$result = earth_xyz(27.174858, 78.042383);
|
||||
$this->assertArrayEpsilon($result, $expected, 0.01, 'Taj Mahal');
|
||||
|
||||
// Four Corners
|
||||
$expected = array(-1667195.89356, -1256280.4293852, -6006637.16009);
|
||||
$result = earth_xyz(36.999084, -109.045223);
|
||||
$this->assertArrayEpsilon($result, $expected, 0.01, 'Four Corners');
|
||||
|
||||
// North Magnetic Pole
|
||||
$expected = array(-335727.75631839, -2620765.1318567, -5785664.2896111);
|
||||
$result = earth_xyz(82.7, -114.4);
|
||||
$this->assertArrayEpsilon($result, $expected, 0.01, 'North Magnetic Pole');
|
||||
|
||||
// Wall Drug
|
||||
$expected = array(-976074.77491191, -942362.77881868, -6211268.2459008);
|
||||
$result = earth_xyz(43.993266, -102.241794);
|
||||
$this->assertArrayEpsilon($result, $expected, 0.01, 'Wall Drug');
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* API keys to use for geocoding tests.
|
||||
*/
|
||||
|
||||
// You need to copy your API keys to this file so simpletest can access them.
|
||||
// This is a requirement for testing because test instances do not have access
|
||||
// to the testing host's variables.
|
||||
|
||||
define('TESTING_APIKEY_GOOGLE_MAPS', '');
|
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Location saving test.
|
||||
*/
|
||||
|
||||
require_once drupal_get_path('module', 'location') . '/tests/location_testcase.php';
|
||||
require_once drupal_get_path('module', 'location') . '/tests/geocoder_api_keys.inc';
|
||||
|
||||
class LocationGoogleGeocoderTest extends LocationTestCase {
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Location Google Geocoder tests'),
|
||||
'description' => t('Test address mangling for the google geocoder.'),
|
||||
'group' => t('Location'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('location', 'location_node', 'devel');
|
||||
variable_set('location_geocode_google_apikey', TESTING_APIKEY_GOOGLE_MAPS);
|
||||
$web_admin = $this->drupalCreateUser(array('administer nodes', 'submit latitude/longitude', 'administer site configuration', 'access administration pages', 'administer content types'));
|
||||
$this->drupalLogin($web_admin);
|
||||
}
|
||||
|
||||
function testUSA() {
|
||||
// Initialize the geocoder.
|
||||
$settings = array(
|
||||
'location_geocode_us' => 'google',
|
||||
);
|
||||
$this->drupalPost('admin/settings/location/geocoding', $settings, 'Save configuration');
|
||||
$this->refreshVariables();
|
||||
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'locations' => array(
|
||||
0 => array(
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
'street' => '1600 Amphitheatre Parkway',
|
||||
'city' => 'Mountain View',
|
||||
'province' => 'CA',
|
||||
'postal_code' => '94043',
|
||||
'country' => 'us',
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$location = $node2->locations[0];
|
||||
|
||||
$this->assertEqual($location['source'], LOCATION_LATLON_GEOCODED_EXACT);
|
||||
|
||||
$expected = array(37.421972, -122.084143);
|
||||
$result = array($location['latitude'], $location['longitude']);
|
||||
$this->assertArrayEpsilon($result, $expected, 0.01, 'Google Headquarters');
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,437 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Tests for location_cck.module.
|
||||
*/
|
||||
|
||||
require_once drupal_get_path('module', 'location') . '/tests/location_testcase.php';
|
||||
|
||||
class LocationCCKTest extends LocationTestCase {
|
||||
/**
|
||||
* A global administrative user.
|
||||
*/
|
||||
var $admin_user;
|
||||
|
||||
/**
|
||||
* A global normal user.
|
||||
*/
|
||||
var $normal_user;
|
||||
|
||||
/**
|
||||
* A default content type.
|
||||
*/
|
||||
var $content_type;
|
||||
|
||||
function getInfo() {
|
||||
return array(
|
||||
'name' => t('Location CCK checks'),
|
||||
'description' => t('Test corner cases of the CCK Location module.'),
|
||||
'group' => t('Location'),
|
||||
);
|
||||
}
|
||||
|
||||
function setUp() {
|
||||
parent::setUp('location', 'content', 'location_cck', 'devel');
|
||||
$this->admin_user = $this->drupalCreateUser(array('administer nodes', 'submit latitude/longitude', 'administer site configuration', 'access administration pages', 'administer content types'));
|
||||
$this->normal_user = $this->drupalCreateUser(array('access content'));
|
||||
|
||||
$this->drupalLogin($this->admin_user);
|
||||
}
|
||||
|
||||
function addLocationContentType(&$settings, $add = array()) {
|
||||
|
||||
$field_name = 'loctest';
|
||||
|
||||
// Let the caller mess with some relevant cck stuff.
|
||||
$required = isset($add['cck_required']) ? $add['cck_required'] : FALSE;
|
||||
$multiple = isset($add['cck_multiple']) ? $add['cck_multiple'] : 0;
|
||||
unset($add['cck_required']);
|
||||
unset($add['cck_multiple']);
|
||||
|
||||
// find a non-existent random type name.
|
||||
do {
|
||||
$name = strtolower($this->randomName(3, 'type_'));
|
||||
} while (node_get_types('type', $name));
|
||||
|
||||
$form = array(
|
||||
'name' => $name,
|
||||
'type' => $name,
|
||||
);
|
||||
|
||||
$this->flattenPostData($form);
|
||||
//$add = array('location_settings' => $add);
|
||||
//$this->flattenPostData($add);
|
||||
//$settings = array_merge($settings, $add);
|
||||
$this->drupalPost('admin/content/types/add', $form, 'Save content type');
|
||||
$this->refreshVariables();
|
||||
|
||||
$form = array(
|
||||
'_add_new_field' => array(
|
||||
'label' => 'Location',
|
||||
'weight' => 10,
|
||||
// 'hidden_name' => '_add_new_field',
|
||||
'field_name' => $field_name,
|
||||
'type' => 'location',
|
||||
'widget_type' => 'location',
|
||||
),
|
||||
);
|
||||
$this->flattenPostData($form);
|
||||
$this->drupalPost('admin/content/node-type/'. str_replace('_', '-', $name) .'/fields', $form, 'Save');
|
||||
|
||||
$this->refreshVariables();
|
||||
drupal_get_schema(NULL, TRUE);
|
||||
|
||||
// Get the (settable) defaults.
|
||||
$defaults = $this->getLocationFieldDefaults();
|
||||
|
||||
$form = array(
|
||||
'required' => $required,
|
||||
'multiple' => $multiple,
|
||||
'location_settings' => array(
|
||||
'form' => array(
|
||||
'fields' => $defaults,
|
||||
),
|
||||
// 'display'
|
||||
),
|
||||
);
|
||||
|
||||
$this->flattenPostData($form);
|
||||
$add = array('location_settings' => $add);
|
||||
$this->flattenPostData($add);
|
||||
|
||||
$this->drupalPost(NULL, $form, 'Save field settings');
|
||||
|
||||
// @@@ This is stupid, but I don't know the api for pulling this stuff up.
|
||||
// @@@ _content_type_info() perhaps?
|
||||
$result = db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = 'field_%s' AND type = 'location'", $field_name);
|
||||
$row = db_fetch_object($result);
|
||||
$settings = array();
|
||||
$settings = unserialize($row->global_settings);
|
||||
$settings = $settings['location_settings'];
|
||||
|
||||
$this->refreshVariables();
|
||||
|
||||
// Reset the schema again, if it was a multiple value field added,
|
||||
// schema has a new table to worry about.
|
||||
drupal_get_schema(NULL, TRUE);
|
||||
|
||||
// Reset the content type info in the context of the test framework.
|
||||
// This took me way too long to figure out.
|
||||
_content_type_info(TRUE);
|
||||
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a location via cck.
|
||||
*/
|
||||
function testCreateLocation() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
array(
|
||||
'name' => $location1_name,
|
||||
'street' => '48072 289th St.',
|
||||
'province' => 'SD',
|
||||
'country' => 'us',
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
cache_clear_all();
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
$location = $node2->field_loctest[0];
|
||||
|
||||
$this->assertEqual($location1_name, $location['name'], t('Testing basic save/load'));
|
||||
|
||||
}
|
||||
|
||||
function testLocpickOnly() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
array(
|
||||
'locpick' => array(
|
||||
'user_latitude' => '44.25',
|
||||
'user_longitude' => '-10.25',
|
||||
),
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
$this->pass(var_export($node2->locations, TRUE));
|
||||
$this->assertEqual($node2->field_loctest[0]['latitude'], 44.25, t('Testing coordinate-only save/load'));
|
||||
}
|
||||
|
||||
function testMultipleLocationOnSingleNode() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings, array('cck_multiple' => 10));
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
$location2_name = $this->randomName();
|
||||
$location3_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
array(
|
||||
'name' => $location1_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
array(
|
||||
'name' => $location2_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
array(
|
||||
'name' => $location3_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$this->assertEqual($location1_name, $node2->field_loctest[0]['name'], t('Testing multi location 1/3'));
|
||||
$this->assertEqual($location2_name, $node2->field_loctest[1]['name'], t('Testing multi location 2/3'));
|
||||
$this->assertEqual($location3_name, $node2->field_loctest[2]['name'], t('Testing multi location 3/3'));
|
||||
$this->assertNotEqual($node2->field_loctest[0]['lid'], $node2->field_loctest[1]['lid'], t('Ensuring location id uniqueness'));
|
||||
$this->assertNotEqual($node2->field_loctest[1]['lid'], $node2->field_loctest[2]['lid'], t('Ensuring location id uniqueness'));
|
||||
$this->assertNotEqual($node2->field_loctest[2]['lid'], $node2->field_loctest[0]['lid'], t('Ensuring location id uniqueness'));
|
||||
}
|
||||
|
||||
function testSharedLocation() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
array(
|
||||
'name' => $location1_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
// Get the full location
|
||||
$location = $node->field_loctest[0];
|
||||
|
||||
$node2 = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
0 => $location,
|
||||
),
|
||||
));
|
||||
|
||||
// Reload second node.
|
||||
$node2 = node_load($node2->nid, NULL, TRUE);
|
||||
|
||||
$this->assertNotEqual($node->nid, $node2->nid, t('Ensuring nodes are seperate'));
|
||||
$this->pass(var_export($node, TRUE));
|
||||
$this->pass(var_export($node2, TRUE));
|
||||
$this->assertEqual($node->field_loctest[0]['lid'], $node2->field_loctest[0]['lid'], t('Testing shared location'));
|
||||
|
||||
$this->deleteNode($node->nid);
|
||||
|
||||
// Force another reload.
|
||||
$node2 = node_load($node2->nid, NULL, TRUE);
|
||||
|
||||
$this->assertEqual($node2->field_loctest[0]['lid'], $location['lid'], t('Ensuring shared location is not prematurely garbage collected'));
|
||||
|
||||
$this->deleteNode($node2->nid);
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $location['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->fail(t('Ensuring shared location is garbage collected'));
|
||||
}
|
||||
else {
|
||||
$this->pass(t('Ensuring shared location is garbage collected'));
|
||||
}
|
||||
}
|
||||
|
||||
function testNodeRevisionCOW() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings, array('cck_multiple' => 10));
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
$location2_name = $this->randomName();
|
||||
$location3_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
0 => array( // First
|
||||
'name' => $location1_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
1 => array( // Second
|
||||
'name' => $location2_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$changes = array(
|
||||
'revision' => TRUE,
|
||||
'log' => $this->randomName(20),
|
||||
'field_loctest' => array(
|
||||
0 => array( // Delete First
|
||||
'delete_location' => TRUE,
|
||||
),
|
||||
2 => array( // Third
|
||||
'name' => $location3_name,
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->flattenPostData($changes);
|
||||
$this->drupalPost('node/'. $node->nid .'/edit', $changes, 'Save');
|
||||
|
||||
// Reload the node again.
|
||||
$node1 = node_load($node->nid, $node->vid, TRUE);
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
// Ensure locations are in a consistent order.
|
||||
$this->reorderLocations($node, 'field_loctest');
|
||||
$this->reorderLocations($node1, 'field_loctest');
|
||||
$this->reorderLocations($node2, 'field_loctest');
|
||||
|
||||
$this->assertEqual(count($node1->field_loctest), 2, t('Ensuring second revision did not affect first revision'));
|
||||
|
||||
$this->pass(count($node1->field_loctest));
|
||||
$this->assertEqual($node->field_loctest[0]['lid'], $node1->field_loctest[0]['lid'], t('Ensuring second revision did not affect first revision'));
|
||||
$this->assertEqual($node->field_loctest[1]['lid'], $node1->field_loctest[1]['lid'], t('Ensuring second revision did not affect first revision'));
|
||||
|
||||
$this->assertEqual(count($node2->field_loctest), 2, t('Ensuring second revision does not have stealth locations'));
|
||||
|
||||
// Delete first revision.
|
||||
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node1->nid, $node1->vid);
|
||||
node_invoke_nodeapi($node1, 'delete revision');
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[0]['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->fail(t('Ensuring location on deleted revision is garbage collected'));
|
||||
}
|
||||
else {
|
||||
$this->pass(t('Ensuring location on deleted revision is garbage collected'));
|
||||
}
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[1]['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->pass(t('Ensuring shared location on deleted revision is NOT garbage collected'));
|
||||
}
|
||||
else {
|
||||
$this->fail(t('Ensuring shared location on deleted revision is NOT garbage collected'));
|
||||
}
|
||||
}
|
||||
|
||||
function testNodeRevisionCleanup() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
array( // First
|
||||
'name' => $location1_name,
|
||||
// 'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$changes = array(
|
||||
'revision' => TRUE,
|
||||
'log' => $this->randomName(20),
|
||||
// 'field_loctest' => array(
|
||||
// $node->field_loctest[0],
|
||||
// ),
|
||||
);
|
||||
$this->flattenPostData($changes);
|
||||
$this->drupalPost('node/'. $node->nid .'/edit', $changes, 'Save');
|
||||
|
||||
// Reload the node again.
|
||||
$node1 = node_load($node->nid, $node->vid, TRUE);
|
||||
$node2 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$this->deleteNode($node->nid);
|
||||
|
||||
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[0]['lid']);
|
||||
if ($row = db_fetch_object($result)) {
|
||||
$this->fail(t('Ensuring all revisions are cleaned up when a multiple revision node is deleted'));
|
||||
}
|
||||
else {
|
||||
$this->pass(t('Ensuring all revisions are cleaned up when a multiple revision node is deleted'));
|
||||
}
|
||||
}
|
||||
|
||||
function testCOWConservation() {
|
||||
$settings = array();
|
||||
$location_type = $this->addLocationContentType($settings);
|
||||
|
||||
$location1_name = $this->randomName();
|
||||
|
||||
$node = $this->drupalCreateNode(array(
|
||||
'type' => $location_type,
|
||||
'field_loctest' => array(
|
||||
0 => array(
|
||||
'name' => $location1_name,
|
||||
'location_settings' => $settings,
|
||||
),
|
||||
),
|
||||
));
|
||||
|
||||
// Reload the node.
|
||||
$node = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
$changes = array(
|
||||
'field_loctest' => array(
|
||||
0 => array(
|
||||
// Update name.
|
||||
'name' => $location1_name .'_CHANGE',
|
||||
),
|
||||
),
|
||||
);
|
||||
$this->flattenPostData($changes);
|
||||
$this->drupalPost('node/'. $node->nid .'/edit', $changes, 'Save');
|
||||
|
||||
// Reload the node again.
|
||||
$node1 = node_load($node->nid, NULL, TRUE);
|
||||
|
||||
// Ensure locations are in a consistent order.
|
||||
$this->reorderLocations($node, 'field_loctest');
|
||||
$this->reorderLocations($node1, 'field_loctest');
|
||||
|
||||
$this->assertEqual($node->field_loctest[0]['lid'], $node1->field_loctest[0]['lid'], t('Ensuring LIDs are conserved'));
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Common functions for Location tests.
|
||||
*/
|
||||
|
||||
class LocationTestCase extends DrupalWebTestCase {
|
||||
|
||||
/**
|
||||
* Custom assertion -- will check each element of an array against a reference value.
|
||||
*/
|
||||
function assertArrayEpsilon($result, $expected, $epsilon, $message = '', $group = 'Other') {
|
||||
foreach ($expected as $k => $test) {
|
||||
$lower = $test - $epsilon;
|
||||
$upper = $test + $epsilon;
|
||||
if ($result[$k] < $lower || $result[$k] > $upper) {
|
||||
$this->_assert('fail', $message ? $message : t('Value deviates by @amt, which is more than @maxdev.', array('@amt' => abs($test - $result[$k]), '@maxdev' => $epsilon)), $group);
|
||||
}
|
||||
else {
|
||||
$this->_assert('pass', $message ? $message : t('Value within expected margin.'), $group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a set of location field defaults.
|
||||
* This will also enable collection on all parts of the location field.
|
||||
*/
|
||||
function getLocationFieldDefaults() {
|
||||
// Get the (settable) defaults.
|
||||
$defaults = array();
|
||||
$d = location_invoke_locationapi($location, 'defaults');
|
||||
$fields = location_field_names();
|
||||
foreach ($fields as $k => $v) {
|
||||
if (!isset($d[$k]['nodiff'])) {
|
||||
$defaults[$k] = $d[$k];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($defaults as $k => $v) {
|
||||
// Change collection to allow.
|
||||
$defaults[$k]['collect'] = 1;
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flatten a post settings array because drupalPost isn't smart enough to.
|
||||
*/
|
||||
function flattenPostData(&$edit) {
|
||||
do {
|
||||
$edit_flattened = TRUE;
|
||||
foreach ($edit as $k => $v) {
|
||||
if (is_array($v)) {
|
||||
$edit_flattened = FALSE;
|
||||
foreach ($v as $kk => $vv) {
|
||||
$edit["{$k}[{$kk}]"] = $vv;
|
||||
}
|
||||
unset($edit[$k]);
|
||||
}
|
||||
}
|
||||
} while (!$edit_flattened);
|
||||
}
|
||||
|
||||
function addLocationContentType(&$settings, $add = array()) {
|
||||
// find a non-existent random type name.
|
||||
do {
|
||||
$name = strtolower($this->randomName(3, 'type_'));
|
||||
} while (node_get_types('type', $name));
|
||||
|
||||
// Get the (settable) defaults.
|
||||
$defaults = $this->getLocationFieldDefaults();
|
||||
|
||||
$settings = array(
|
||||
'name' => $name,
|
||||
'type' => $name,
|
||||
'location_settings' => array(
|
||||
'multiple' => array(
|
||||
'max' => 1,
|
||||
'add' => 1,
|
||||
),
|
||||
'form' => array(
|
||||
'fields' => $defaults,
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
//$settings['location_settings'] = array_merge_recursive($settings['location_settings'], $add);
|
||||
$this->flattenPostData($settings);
|
||||
$add = array('location_settings' => $add);
|
||||
$this->flattenPostData($add);
|
||||
$settings = array_merge($settings, $add);
|
||||
$this->drupalPost('admin/content/types/add', $settings, 'Save content type');
|
||||
$this->refreshVariables();
|
||||
$settings = variable_get('location_settings_node_'. $name, array());
|
||||
return $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a node.
|
||||
*/
|
||||
function deleteNode($nid) {
|
||||
// Implemention taken from node_delete, with some assumptions regarding
|
||||
// function_exists removed.
|
||||
|
||||
$node = node_load($nid);
|
||||
db_query('DELETE FROM {node} WHERE nid = %d', $node->nid);
|
||||
db_query('DELETE FROM {node_revisions} WHERE nid = %d', $node->nid);
|
||||
|
||||
// Call the node-specific callback (if any):
|
||||
node_invoke($node, 'delete');
|
||||
node_invoke_nodeapi($node, 'delete');
|
||||
|
||||
// Clear the page and block caches.
|
||||
cache_clear_all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Order locations in a node by LID for testing repeatability purposes.
|
||||
*/
|
||||
function reorderLocations(&$node, $field = 'locations') {
|
||||
$locations = array();
|
||||
foreach ($node->{$field} as $location) {
|
||||
if ($location['lid']) {
|
||||
$locations[$location['lid']] = $location;
|
||||
}
|
||||
}
|
||||
ksort($locations);
|
||||
$node->{$field} = array();
|
||||
foreach ($locations as $location) {
|
||||
$node->{$field}[] = $location;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a node based on default settings. This uses the internal simpletest
|
||||
* browser, meaning the node will be owned by the current simpletest _browser user.
|
||||
*
|
||||
* Code modified from #212304.
|
||||
* This is mainly for testing for differences between node_save() and
|
||||
* submitting a node/add/* form.
|
||||
*
|
||||
* @param values
|
||||
* An associative array of values to change from the defaults, keys are
|
||||
* node properties, for example 'body' => 'Hello, world!'.
|
||||
* @return object Created node object.
|
||||
*/
|
||||
function drupalCreateNodeViaForm($values = array()) {
|
||||
$defaults = array(
|
||||
'type' => 'page',
|
||||
'title' => $this->randomName(8),
|
||||
);
|
||||
|
||||
$edit = ($values + $defaults);
|
||||
|
||||
if (empty($edit['body'])) {
|
||||
$content_type = db_fetch_array(db_query("select name, has_body from {node_type} where type='%s'", $edit['type']));
|
||||
|
||||
if ($content_type['has_body']) {
|
||||
$edit['body'] = $this->randomName(32);
|
||||
}
|
||||
}
|
||||
$type = $edit['type'];
|
||||
unset($edit['type']); // Only used in URL.
|
||||
$this->flattenPostData($edit); // Added by me.
|
||||
$this->drupalPost('node/add/'. str_replace('_', '-', $type), $edit, t('Save'));
|
||||
|
||||
$node = node_load(array('title' => $edit['title']));
|
||||
$this->assertRaw(t('@type %title has been created.', array('@type' => node_get_types('name', $node), '%title' => $edit['title'])), t('Node created successfully.'));
|
||||
|
||||
return $node;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user