changeset: 160:6c0b897c137f tag: tip user: root@drupal-kez date: Mon Jan 04 14:18:45 2010 +0100 files: usr/src/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorDbFetcher.php usr/src/ShindigIntegrator/shindig_integrator/tests/address.test description: support for opensocial.Address field in ShindigIntegratorDbFetcher::getPeople diff -r 48ea1d7f3eaf -r 6c0b897c137f usr/src/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorDbFetcher.php --- a/usr/src/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorDbFetcher.php Thu Dec 31 15:14:10 2009 +0100 +++ b/usr/src/ShindigIntegrator/shindig_integrator/shindig_files/ShindigIntegratorDbFetcher.php Mon Jan 04 14:18:45 2010 +0100 @@ -8,6 +8,8 @@ * This module contains core shindig server */ +global $TEST_ENABLED; +if (! $TEST_ENABLED ) { include(Config::get('settings_php')); include_once(Config::get('include_path')."/database.inc"); include_once(Config::get('include_path')."/bootstrap.inc"); @@ -22,6 +24,7 @@ global $active_db; $active_db = db_connect($db_url); +} class ShindigIntegratorDbFetcher { private $db; @@ -96,7 +99,7 @@ foreach($ids as $id) { $user =array(); - $res = db_query("SELECT * FROM profile_values INNER JOIN profile_fields ON profile_values.fid = profile_fields.fid WHERE uid =%d", $id); + $res = db_query("SELECT * FROM {profile_values} INNER JOIN {profile_fields} ON {profile_values}.fid = {profile_fields}.fid WHERE uid =%d", $id); if ($res) { while ($row = db_fetch_array($res)) { @@ -108,11 +111,15 @@ $name = new Name($user['profile_fname'] . ' ' . $user['profile_lname']); $name->setGivenName($user['profile_fname']); $name->setFamilyName($user['profile_lname']); + $address = new Address("UNSTRUCTUREDADDRESS"); + $address->setLocality($user['profile_city']); + $address->setCountry($user['profile_country']); $person = new Person($user['uid'], $name); + $person->setAddresses(array($address)); $person->setNickname($user['profile_nickname']); $person->setProfileUrl($this->url_prefix . 'user/' . $user['uid']); - $person->setDisplayName($user['profile_fname'] . ' ' . $user['profile_lname']); - $res = db_query("SELECT picture FROM users WHERE uid = %d",$id); + $person->setDisplayName($user['profile_fname'] . ' ' . $user['profile_lname']); + $res = db_query("SELECT picture FROM {users} WHERE uid = %d",$id); $row = db_fetch_array($res); $person->setThumbnailUrl(! empty($row['picture']) ? $this->url_prefix.$row['picture'] : ''); if ($user['profile_gender'] == 'Female') { @@ -376,4 +383,3 @@ } ?> - diff -r 48ea1d7f3eaf -r 6c0b897c137f usr/src/ShindigIntegrator/shindig_integrator/tests/address.test --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usr/src/ShindigIntegrator/shindig_integrator/tests/address.test Mon Jan 04 14:18:45 2010 +0100 @@ -0,0 +1,84 @@ + t('ShindigIntegrator Address test'), + 'description' => t('Test ShindigIntegrator Address support.'), + 'group' => t('ShindigIntegrator'), + ); + } + + function setUp() { + parent::setUp('profile', 'shindig_integrator'); + db_query("INSERT IGNORE INTO `{profile_fields}` + VALUES (1,'First name','profile_fname','','Personal information','','textfield',-4,0,0,4,0,''), + (2,'Last name','profile_lname','','Personal information','','textfield',-3,0,0,4,0,''), + (9,'Nickname','profile_nickname','','Personal information','','textfield',-10,1,0,2,0,''), + (4,'Date of Birth','profile_dob','','Personal information','','date',-8,0,0,2,0,''), + (5,'City','profile_city','','Personal information','','textfield',-7,0,0,2,0,''), + (10,'Country','profile_country','','Personal information','','selection',-6,0,0,2,0,'France\r\nGermany'), + (7,'Interested in','profile_interest','','Personal information','','textfield',-5,0,0,4,0,''), + (8,'Gender','profile_gender','','Personal information','','selection',-9,0,0,2,0,'Male\r\nFemale\r\nDon\'t Display\r\n')"); + } + + function test_no_address() { + $user = $this->drupalCreateUser(array('administer users')); + $profile = array(); + $profile["profile_fname"] = "foo_fname"; + $profile["profile_lname"] = "foo_lname"; + $profile["profile_nickname"] = "foo_nickname"; + $profile["profile_interest"] = "foo_interest"; + $profile["profile_gender"] = "foo_gender"; + profile_save_profile($profile, $user, "Personal information"); + $uids = array(); + $uids[] = $user->uid; + $fetcher = ShindigIntegratorDbFetcher::get(); + $peoples = $fetcher->getPeople($uids, null, null); + $person = $peoples[$user->uid]; + $addresses = $person->getAddresses(); + $address = $addresses[0]; + $this->assertEqual('', $address->getLocality(), 'person address locality should be null'); + $this->assertEqual('', $address->getCountry(), 'person address country should be null'); + } + + + function test_address() { + $user = $this->drupalCreateUser(array('administer users')); + $profile = array(); + $profile["profile_fname"] = "foo_fname"; + $profile["profile_lname"] = "foo_lname"; + $profile["profile_nickname"] = "foo_nickname"; + $profile["profile_city"] = "foo_city"; + $profile["profile_country"] = "foo_country"; + $profile["profile_interest"] = "foo_interest"; + $profile["profile_gender"] = "foo_gender"; + profile_save_profile($profile, $user, "Personal information", FALSE); + $uids = array(); + $uids[] = $user->uid; + $fetcher = ShindigIntegratorDbFetcher::get(); + $peoples = $fetcher->getPeople($uids, null, null); + $person = $peoples[$user->uid]; + $addresses = $person->getAddresses(); + $address = $addresses[0]; + $this->assertEqual('foo_city', $address->getLocality(), 'person address localily should be set'); + $this->assertEqual('foo_country', $address->getCountry(), 'person address country should be set'); + } +} \ No newline at end of file