| 1 |
<?php |
<?php |
| 2 |
// $Id: location_cck.test,v 1.1 2009/07/29 19:25:03 bdragon Exp $ |
// $Id: location_cck.test,v 1.1.2.2 2009/07/29 19:26:45 bdragon Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 19 |
*/ |
*/ |
| 20 |
var $normal_user; |
var $normal_user; |
| 21 |
|
|
| 22 |
|
/** |
| 23 |
|
* A default content type. |
| 24 |
|
*/ |
| 25 |
|
var $content_type; |
| 26 |
|
|
| 27 |
function getInfo() { |
function getInfo() { |
| 28 |
return array( |
return array( |
| 29 |
'name' => t('Location CCK checks'), |
'name' => t('Location CCK checks'), |
| 40 |
$this->drupalLogin($this->admin_user); |
$this->drupalLogin($this->admin_user); |
| 41 |
} |
} |
| 42 |
|
|
|
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; |
|
|
} |
|
|
|
|
| 43 |
function addLocationContentType(&$settings, $add = array()) { |
function addLocationContentType(&$settings, $add = array()) { |
| 44 |
|
|
| 45 |
$field_name = 'loctest'; |
$field_name = 'loctest'; |
| 84 |
drupal_get_schema(NULL, TRUE); |
drupal_get_schema(NULL, TRUE); |
| 85 |
|
|
| 86 |
// Get the (settable) defaults. |
// Get the (settable) defaults. |
| 87 |
$defaults = array(); |
$defaults = $this->getLocationFieldDefaults(); |
|
$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; |
|
|
} |
|
| 88 |
|
|
| 89 |
$form = array( |
$form = array( |
| 90 |
'required' => $required, |
'required' => $required, |
| 113 |
|
|
| 114 |
$this->refreshVariables(); |
$this->refreshVariables(); |
| 115 |
|
|
| 116 |
|
// Reset the schema again, if it was a multiple value field added, |
| 117 |
|
// schema has a new table to worry about. |
| 118 |
|
drupal_get_schema(NULL, TRUE); |
| 119 |
|
|
| 120 |
// Reset the content type info in the context of the test framework. |
// Reset the content type info in the context of the test framework. |
| 121 |
// This took me way too long to figure out. |
// This took me way too long to figure out. |
| 122 |
_content_type_info(TRUE); |
_content_type_info(TRUE); |
| 154 |
$this->assertEqual($location1_name, $location['name'], t('Testing basic save/load')); |
$this->assertEqual($location1_name, $location['name'], t('Testing basic save/load')); |
| 155 |
|
|
| 156 |
} |
} |
| 157 |
/* |
|
| 158 |
function testLocpickOnly() { |
function testLocpickOnly() { |
| 159 |
$settings = array(); |
$settings = array(); |
| 160 |
$location_type = $this->addLocationContentType($settings); |
$location_type = $this->addLocationContentType($settings); |
| 163 |
|
|
| 164 |
$node = $this->drupalCreateNode(array( |
$node = $this->drupalCreateNode(array( |
| 165 |
'type' => $location_type, |
'type' => $location_type, |
| 166 |
'locations' => array( |
'field_loctest' => array( |
| 167 |
0 => array( |
array( |
| 168 |
'locpick' => array( |
'locpick' => array( |
| 169 |
'user_latitude' => '44.25', |
'user_latitude' => '44.25', |
| 170 |
'user_longitude' => '-10.25', |
'user_longitude' => '-10.25', |
| 171 |
), |
), |
| 172 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 173 |
), |
), |
| 174 |
), |
), |
| 175 |
)); |
)); |
| 177 |
// Reload the node. |
// Reload the node. |
| 178 |
$node2 = node_load($node->nid, NULL, TRUE); |
$node2 = node_load($node->nid, NULL, TRUE); |
| 179 |
$this->pass(var_export($node2->locations, TRUE)); |
$this->pass(var_export($node2->locations, TRUE)); |
| 180 |
$this->assertEqual($node2->locations[0]['latitude'], 44.25, t('Testing coordinate-only save/load')); |
$this->assertEqual($node2->field_loctest[0]['latitude'], 44.25, t('Testing coordinate-only save/load')); |
|
// crash(); |
|
| 181 |
} |
} |
| 182 |
|
|
| 183 |
function testMultipleLocationOnSingleNode() { |
function testMultipleLocationOnSingleNode() { |
| 184 |
$settings = array(); |
$settings = array(); |
| 185 |
$location_type = $this->addLocationContentType($settings, array('multiple' => array('max' => 3, 'add' => 3))); |
$location_type = $this->addLocationContentType($settings, array('cck_multiple' => 10)); |
| 186 |
|
|
| 187 |
$location1_name = $this->randomName(); |
$location1_name = $this->randomName(); |
| 188 |
$location2_name = $this->randomName(); |
$location2_name = $this->randomName(); |
| 190 |
|
|
| 191 |
$node = $this->drupalCreateNode(array( |
$node = $this->drupalCreateNode(array( |
| 192 |
'type' => $location_type, |
'type' => $location_type, |
| 193 |
'locations' => array( |
'field_loctest' => array( |
| 194 |
0 => array( |
array( |
| 195 |
'name' => $location1_name, |
'name' => $location1_name, |
| 196 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 197 |
), |
), |
| 198 |
1 => array( |
array( |
| 199 |
'name' => $location2_name, |
'name' => $location2_name, |
| 200 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 201 |
), |
), |
| 202 |
2 => array( |
array( |
| 203 |
'name' => $location3_name, |
'name' => $location3_name, |
| 204 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 205 |
), |
), |
| 206 |
), |
), |
| 207 |
)); |
)); |
| 209 |
// Reload the node. |
// Reload the node. |
| 210 |
$node2 = node_load($node->nid, NULL, TRUE); |
$node2 = node_load($node->nid, NULL, TRUE); |
| 211 |
|
|
| 212 |
$this->assertEqual($location1_name, $node2->locations[0]['name'], t('Testing multi location 1/3')); |
$this->assertEqual($location1_name, $node2->field_loctest[0]['name'], t('Testing multi location 1/3')); |
| 213 |
$this->assertEqual($location2_name, $node2->locations[1]['name'], t('Testing multi location 2/3')); |
$this->assertEqual($location2_name, $node2->field_loctest[1]['name'], t('Testing multi location 2/3')); |
| 214 |
$this->assertEqual($location3_name, $node2->locations[2]['name'], t('Testing multi location 3/3')); |
$this->assertEqual($location3_name, $node2->field_loctest[2]['name'], t('Testing multi location 3/3')); |
| 215 |
$this->assertNotEqual($node2->locations[0]['lid'], $node2->locations[1]['lid'], t('Ensuring location id uniqueness')); |
$this->assertNotEqual($node2->field_loctest[0]['lid'], $node2->field_loctest[1]['lid'], t('Ensuring location id uniqueness')); |
| 216 |
$this->assertNotEqual($node2->locations[1]['lid'], $node2->locations[2]['lid'], t('Ensuring location id uniqueness')); |
$this->assertNotEqual($node2->field_loctest[1]['lid'], $node2->field_loctest[2]['lid'], t('Ensuring location id uniqueness')); |
| 217 |
$this->assertNotEqual($node2->locations[2]['lid'], $node2->locations[0]['lid'], t('Ensuring location id uniqueness')); |
$this->assertNotEqual($node2->field_loctest[2]['lid'], $node2->field_loctest[0]['lid'], t('Ensuring location id uniqueness')); |
| 218 |
} |
} |
| 219 |
|
|
| 220 |
function testSharedLocation() { |
function testSharedLocation() { |
| 225 |
|
|
| 226 |
$node = $this->drupalCreateNode(array( |
$node = $this->drupalCreateNode(array( |
| 227 |
'type' => $location_type, |
'type' => $location_type, |
| 228 |
'locations' => array( |
'field_loctest' => array( |
| 229 |
0 => array( |
array( |
| 230 |
'name' => $location1_name, |
'name' => $location1_name, |
| 231 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 232 |
), |
), |
| 233 |
), |
), |
| 234 |
)); |
)); |
| 237 |
$node = node_load($node->nid, NULL, TRUE); |
$node = node_load($node->nid, NULL, TRUE); |
| 238 |
|
|
| 239 |
// Get the full location |
// Get the full location |
| 240 |
$location = $node->locations[0]; |
$location = $node->field_loctest[0]; |
| 241 |
|
|
| 242 |
$node2 = $this->drupalCreateNode(array( |
$node2 = $this->drupalCreateNode(array( |
| 243 |
'type' => $location_type, |
'type' => $location_type, |
| 244 |
'locations' => array( |
'field_loctest' => array( |
| 245 |
'0' => $location, |
0 => $location, |
| 246 |
), |
), |
| 247 |
)); |
)); |
| 248 |
|
|
| 250 |
$node2 = node_load($node2->nid, NULL, TRUE); |
$node2 = node_load($node2->nid, NULL, TRUE); |
| 251 |
|
|
| 252 |
$this->assertNotEqual($node->nid, $node2->nid, t('Ensuring nodes are seperate')); |
$this->assertNotEqual($node->nid, $node2->nid, t('Ensuring nodes are seperate')); |
| 253 |
$this->assertEqual($node->locations[0]['lid'], $node2->locations[0]['lid'], t('Testing shared location')); |
$this->pass(var_export($node, TRUE)); |
| 254 |
|
$this->pass(var_export($node2, TRUE)); |
| 255 |
|
$this->assertEqual($node->field_loctest[0]['lid'], $node2->field_loctest[0]['lid'], t('Testing shared location')); |
| 256 |
|
|
| 257 |
$this->deleteNode($node->nid); |
$this->deleteNode($node->nid); |
| 258 |
|
|
| 259 |
// Force another reload. |
// Force another reload. |
| 260 |
$node2 = node_load($node2->nid, NULL, TRUE); |
$node2 = node_load($node2->nid, NULL, TRUE); |
| 261 |
|
|
| 262 |
$this->assertEqual($node2->locations[0]['lid'], $location['lid'], t('Ensuring shared location is not prematurely garbage collected')); |
$this->assertEqual($node2->field_loctest[0]['lid'], $location['lid'], t('Ensuring shared location is not prematurely garbage collected')); |
| 263 |
|
|
| 264 |
$this->deleteNode($node2->nid); |
$this->deleteNode($node2->nid); |
| 265 |
|
|
| 274 |
|
|
| 275 |
function testNodeRevisionCOW() { |
function testNodeRevisionCOW() { |
| 276 |
$settings = array(); |
$settings = array(); |
| 277 |
$location_type = $this->addLocationContentType($settings, array('multiple' => array('max' => 3, 'add' => 3))); |
$location_type = $this->addLocationContentType($settings, array('cck_multiple' => 10)); |
| 278 |
|
|
| 279 |
$location1_name = $this->randomName(); |
$location1_name = $this->randomName(); |
| 280 |
$location2_name = $this->randomName(); |
$location2_name = $this->randomName(); |
| 282 |
|
|
| 283 |
$node = $this->drupalCreateNode(array( |
$node = $this->drupalCreateNode(array( |
| 284 |
'type' => $location_type, |
'type' => $location_type, |
| 285 |
'locations' => array( |
'field_loctest' => array( |
| 286 |
0 => array( // First |
0 => array( // First |
| 287 |
'name' => $location1_name, |
'name' => $location1_name, |
| 288 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 289 |
), |
), |
| 290 |
1 => array( // Second |
1 => array( // Second |
| 291 |
'name' => $location2_name, |
'name' => $location2_name, |
| 292 |
'location_settings' => $settings, |
// 'location_settings' => $settings, |
| 293 |
), |
), |
| 294 |
), |
), |
| 295 |
)); |
)); |
| 300 |
$changes = array( |
$changes = array( |
| 301 |
'revision' => TRUE, |
'revision' => TRUE, |
| 302 |
'log' => $this->randomName(20), |
'log' => $this->randomName(20), |
| 303 |
'locations' => array( |
'field_loctest' => array( |
| 304 |
0 => array( // Delete First |
0 => array( // Delete First |
| 305 |
'delete_location' => TRUE, |
'delete_location' => TRUE, |
| 306 |
), |
), |
| 317 |
$node2 = node_load($node->nid, NULL, TRUE); |
$node2 = node_load($node->nid, NULL, TRUE); |
| 318 |
|
|
| 319 |
// Ensure locations are in a consistent order. |
// Ensure locations are in a consistent order. |
| 320 |
$this->reorderLocations($node); |
$this->reorderLocations($node, 'field_loctest'); |
| 321 |
$this->reorderLocations($node1); |
$this->reorderLocations($node1, 'field_loctest'); |
| 322 |
$this->reorderLocations($node2); |
$this->reorderLocations($node2, 'field_loctest'); |
|
|
|
|
$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')); |
|
| 323 |
|
|
| 324 |
$this->assertEqual(count($node2->locations), 2, t('Ensuring second revision does not have stealth locations')); |
$this->assertEqual(count($node1->field_loctest), 2, t('Ensuring second revision did not affect first revision')); |
| 325 |
|
|
| 326 |
|
$this->pass(count($node1->field_loctest)); |
| 327 |
|
$this->assertEqual($node->field_loctest[0]['lid'], $node1->field_loctest[0]['lid'], t('Ensuring second revision did not affect first revision')); |
| 328 |
|
$this->assertEqual($node->field_loctest[1]['lid'], $node1->field_loctest[1]['lid'], t('Ensuring second revision did not affect first revision')); |
| 329 |
|
|
| 330 |
|
$this->assertEqual(count($node2->field_loctest), 2, t('Ensuring second revision does not have stealth locations')); |
| 331 |
|
|
| 332 |
// Delete first revision. |
// Delete first revision. |
| 333 |
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node1->nid, $node1->vid); |
db_query("DELETE FROM {node_revisions} WHERE nid = %d AND vid = %d", $node1->nid, $node1->vid); |
| 334 |
node_invoke_nodeapi($node1, 'delete revision'); |
node_invoke_nodeapi($node1, 'delete revision'); |
| 335 |
|
|
| 336 |
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->locations[0]['lid']); |
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[0]['lid']); |
| 337 |
if ($row = db_fetch_object($result)) { |
if ($row = db_fetch_object($result)) { |
| 338 |
$this->fail(t('Ensuring location on deleted revision is garbage collected')); |
$this->fail(t('Ensuring location on deleted revision is garbage collected')); |
| 339 |
} |
} |
| 341 |
$this->pass(t('Ensuring location on deleted revision is garbage collected')); |
$this->pass(t('Ensuring location on deleted revision is garbage collected')); |
| 342 |
} |
} |
| 343 |
|
|
| 344 |
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->locations[1]['lid']); |
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[1]['lid']); |
| 345 |
if ($row = db_fetch_object($result)) { |
if ($row = db_fetch_object($result)) { |
| 346 |
$this->pass(t('Ensuring shared location on deleted revision is NOT garbage collected')); |
$this->pass(t('Ensuring shared location on deleted revision is NOT garbage collected')); |
| 347 |
} |
} |
| 350 |
} |
} |
| 351 |
} |
} |
| 352 |
|
|
| 353 |
|
function testNodeRevisionCleanup() { |
| 354 |
|
$settings = array(); |
| 355 |
|
$location_type = $this->addLocationContentType($settings); |
| 356 |
|
|
| 357 |
|
$location1_name = $this->randomName(); |
| 358 |
|
|
| 359 |
|
$node = $this->drupalCreateNode(array( |
| 360 |
|
'type' => $location_type, |
| 361 |
|
'field_loctest' => array( |
| 362 |
|
array( // First |
| 363 |
|
'name' => $location1_name, |
| 364 |
|
// 'location_settings' => $settings, |
| 365 |
|
), |
| 366 |
|
), |
| 367 |
|
)); |
| 368 |
|
|
| 369 |
|
// Reload the node. |
| 370 |
|
$node = node_load($node->nid, NULL, TRUE); |
| 371 |
|
|
| 372 |
|
$changes = array( |
| 373 |
|
'revision' => TRUE, |
| 374 |
|
'log' => $this->randomName(20), |
| 375 |
|
// 'field_loctest' => array( |
| 376 |
|
// $node->field_loctest[0], |
| 377 |
|
// ), |
| 378 |
|
); |
| 379 |
|
$this->flattenPostData($changes); |
| 380 |
|
$this->drupalPost('node/'. $node->nid .'/edit', $changes, 'Save'); |
| 381 |
|
|
| 382 |
|
// Reload the node again. |
| 383 |
|
$node1 = node_load($node->nid, $node->vid, TRUE); |
| 384 |
|
$node2 = node_load($node->nid, NULL, TRUE); |
| 385 |
|
|
| 386 |
|
$this->deleteNode($node->nid); |
| 387 |
|
|
| 388 |
|
$result = db_query('SELECT * FROM {location} WHERE lid = %d', $node1->field_loctest[0]['lid']); |
| 389 |
|
if ($row = db_fetch_object($result)) { |
| 390 |
|
$this->fail(t('Ensuring all revisions are cleaned up when a multiple revision node is deleted')); |
| 391 |
|
} |
| 392 |
|
else { |
| 393 |
|
$this->pass(t('Ensuring all revisions are cleaned up when a multiple revision node is deleted')); |
| 394 |
|
} |
| 395 |
|
} |
| 396 |
|
|
| 397 |
function testCOWConservation() { |
function testCOWConservation() { |
| 398 |
$settings = array(); |
$settings = array(); |
| 399 |
$location_type = $this->addLocationContentType($settings, array('multiple' => array('max' => 3, 'add' => 3))); |
$location_type = $this->addLocationContentType($settings); |
| 400 |
|
|
| 401 |
$location1_name = $this->randomName(); |
$location1_name = $this->randomName(); |
| 402 |
|
|
| 403 |
$node = $this->drupalCreateNode(array( |
$node = $this->drupalCreateNode(array( |
| 404 |
'type' => $location_type, |
'type' => $location_type, |
| 405 |
'locations' => array( |
'field_loctest' => array( |
| 406 |
0 => array( // First |
0 => array( |
| 407 |
'name' => $location1_name, |
'name' => $location1_name, |
| 408 |
'location_settings' => $settings, |
'location_settings' => $settings, |
| 409 |
), |
), |
| 414 |
$node = node_load($node->nid, NULL, TRUE); |
$node = node_load($node->nid, NULL, TRUE); |
| 415 |
|
|
| 416 |
$changes = array( |
$changes = array( |
| 417 |
'locations' => array( |
'field_loctest' => array( |
| 418 |
0 => array( // Delete First |
0 => array( |
| 419 |
|
// Update name. |
| 420 |
'name' => $location1_name .'_CHANGE', |
'name' => $location1_name .'_CHANGE', |
| 421 |
), |
), |
| 422 |
), |
), |
| 428 |
$node1 = node_load($node->nid, NULL, TRUE); |
$node1 = node_load($node->nid, NULL, TRUE); |
| 429 |
|
|
| 430 |
// Ensure locations are in a consistent order. |
// Ensure locations are in a consistent order. |
| 431 |
$this->reorderLocations($node); |
$this->reorderLocations($node, 'field_loctest'); |
| 432 |
$this->reorderLocations($node1); |
$this->reorderLocations($node1, 'field_loctest'); |
| 433 |
|
|
| 434 |
$this->assertEqual($node->locations[0]['lid'], $node1->locations[0]['lid'], t('Ensuring LIDs are conserved')); |
$this->assertEqual($node->field_loctest[0]['lid'], $node1->field_loctest[0]['lid'], t('Ensuring LIDs are conserved')); |
| 435 |
|
|
| 436 |
} |
} |
| 437 |
*/ |
|
| 438 |
} |
} |