View source
<?php
require_once drupal_get_path('module', 'location') . '/tests/location_testcase.test';
class LocationCCK2Test extends LocationTestCase {
public $admin_user;
public $normal_user;
public $content_type;
public static $name;
public static $field_name;
public static function getInfo() {
return array(
'name' => t('Location CCK2 checks'),
'description' => t('Yet One Test corner cases of the CCK Location module.'),
'group' => t('Location', array(), array(
'context' => 'geolocation',
)),
);
}
public function setUp() {
parent::setUp('location', 'location_cck', 'field_ui');
$this->admin_user = $this
->drupalCreateUser(array_keys(module_invoke_all('permission')));
$this->normal_user = $this
->drupalCreateUser(array(
'access content',
));
$this
->drupalLogin($this->admin_user);
}
protected function getTestContentName() {
if (!self::$name) {
$this
->addLocationContentType2();
}
return self::$name;
}
protected function getTestFieldName() {
if (!self::$field_name) {
$this
->addLocationContentType2();
}
return self::$field_name;
}
protected function addLocationContentType2(&$settings, $add = array()) {
if (!self::$name) {
self::$name = strtolower($this
->randomName(8));
$form = array(
'name' => self::$name,
'type' => self::$name,
);
$this
->drupalPost('admin/structure/types/add', $form, 'Save content type');
$this
->assertText(t('The content type ' . self::$name . ' has been added'));
unset($form);
if (!self::$field_name) {
self::$field_name = strtolower($this
->randomName(8));
$form = array(
'fields[_add_new_field][label]' => self::$field_name,
'fields[_add_new_field][field_name]' => self::$field_name,
'fields[_add_new_field][type]' => 'location',
'fields[_add_new_field][widget_type]' => 'location',
);
$this
->drupalPost('admin/structure/types/manage/' . self::$name . '/fields', $form, t('Save'));
unset($form);
$form = array();
$this
->drupalPost(NULL, $form, t('Save field settings'));
unset($form);
$this
->assertText(t('Updated field ' . self::$field_name . ' field settings.'));
$form = array(
'field_' . self::$field_name . '[und][0][name]' => 'Kyiv',
'field_' . self::$field_name . '[und][0][country]' => 'ua',
'field_' . self::$field_name . '[und][0][locpick][user_latitude]' => 50,
'field_' . self::$field_name . '[und][0][locpick][user_longitude]' => 30,
);
$this
->drupalPost(NULL, $form, t('Save settings'));
unset($form);
$this
->assertText(t('Saved ' . self::$field_name . ' configuration.'));
}
}
}
public function testCCK2() {
$settings = array();
$this
->addLocationContentType2($settings, array());
$this
->assertTrue($this
->getTestContentName(), t('Content type' . $this
->getTestContentName() . ' created'));
$node2 = $this
->drupalCreateNode(array(
'type' => $this
->getTestContentName(),
));
$fieldname = 'field_' . $this
->getTestFieldName();
$fielddata = $node2->{$fieldname};
$this
->pass('<pre>' . print_r($node2->{$fieldname}, TRUE) . '</pre>', 'Debug');
$this
->assertEqual('ua', $fielddata['und'][0]['country']);
$this
->assertEqual(50, $fielddata['und'][0]['latitude']);
$this
->assertEqual(30, $fielddata['und'][0]['longitude']);
$this
->assertEqual('Kyiv', $fielddata['und'][0]['name']);
}
}