summaryrefslogtreecommitdiff
path: root/modules/profile
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-05-29 11:37:33 +0000
committerDries Buytaert <dries@buytaert.net>2010-05-29 11:37:33 +0000
commitb801d14ad1fc5965250bd45085bccd09589a4bd1 (patch)
treef0798dcad0130281ce8160adc01eef2ecc05ca11 /modules/profile
parent75e847346df726ddedf789e0f5cbb813cb21e947 (diff)
downloadbrdo-b801d14ad1fc5965250bd45085bccd09589a4bd1.tar.gz
brdo-b801d14ad1fc5965250bd45085bccd09589a4bd1.tar.bz2
- Patch #591048 by Damien Tournoud: the author information block was broken. Added tests.
Diffstat (limited to 'modules/profile')
-rw-r--r--modules/profile/profile.module4
-rw-r--r--modules/profile/profile.test79
2 files changed, 69 insertions, 14 deletions
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 5aabb3d7d..9960f2845 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -179,12 +179,12 @@ function profile_block_view($delta = '') {
$output = '';
if ((arg(0) == 'node') && is_numeric(arg(1)) && (arg(2) == NULL)) {
$node = node_load(arg(1));
- $account = user_load(array('uid' => $node->uid));
+ $account = user_load($node->uid);
if ($use_fields = variable_get('profile_block_author_fields', array())) {
// Compile a list of fields to show.
$fields = array();
- $result = db_query('SELECT name, title, weight, visibility FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));
+ $result = db_query('SELECT * FROM {profile_field} WHERE visibility IN (:visibility) ORDER BY weight', array(':visibility' => array(PROFILE_PUBLIC, PROFILE_PUBLIC_LISTINGS)));
foreach ($result as $record) {
// Ensure that field is displayed only if it is among the defined block fields and, if it is private, the user has appropriate permissions.
if (isset($use_fields[$record->name]) && $use_fields[$record->name]) {
diff --git a/modules/profile/profile.test b/modules/profile/profile.test
index ce90e3e36..7216a522f 100644
--- a/modules/profile/profile.test
+++ b/modules/profile/profile.test
@@ -12,7 +12,7 @@ class ProfileTestCase extends DrupalWebTestCase {
parent::setUp('profile');
variable_set('user_register', USER_REGISTER_VISITORS);
- $this->admin_user = $this->drupalCreateUser(array('administer users', 'access user profiles'));
+ $this->admin_user = $this->drupalCreateUser(array('administer users', 'access user profiles', 'administer blocks'));
// This is the user whose profile will be edited.
$this->normal_user = $this->drupalCreateUser();
@@ -364,33 +364,88 @@ class ProfileTestAutocomplete extends ProfileTestCase {
}
}
-class ProfileBlockTestCase extends DrupalWebTestCase {
+class ProfileBlockTestCase extends ProfileTestCase {
public static function getInfo() {
return array(
'name' => 'Block availability',
- 'description' => 'Check if the author-information block is available.',
+ 'description' => 'Check if the Author Information block is available.',
'group' => 'Profile',
);
}
function setUp() {
- parent::setUp('profile');
+ parent::setUp();
+
+ // Login the admin user.
+ $this->drupalLogin($this->admin_user);
+
+ // Create two fields.
+ $category = $this->randomName();
+ $this->field1 = $this->createProfileField('textfield', $category, array('weight' => 0));
+ $this->field2 = $this->createProfileField('textfield', $category, array('weight' => 1));
- // Create and login user
- $admin_user = $this->drupalCreateUser(array('administer blocks'));
- $this->drupalLogin($admin_user);
+ // Assign values to those fields.
+ $this->value1 = $this->setProfileField($this->field1);
+ $this->value2 = $this->setProfileField($this->field2);
+
+ // Create a node authored by the normal user.
+ $this->node = $this->drupalCreateNode(array(
+ 'uid' => $this->normal_user->uid,
+ ));
}
function testAuthorInformationBlock() {
- // Set block title to confirm that the interface is availble.
- $this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array('title' => $this->randomName(8)), t('Save block'));
- $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
-
- // Set the block to a region to confirm block is availble.
+ // Set the block to a region to confirm the block is availble.
$edit = array();
$edit['profile_author-information[region]'] = 'footer';
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
$this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.'));
+
+ // Enable field 1.
+ $this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array(
+ 'profile_block_author_fields[' . $this->field1['form_name'] . ']' => TRUE,
+ ), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Visit the node and confirm that the field is displayed.
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertRaw($this->value1, t('Field 1 is displayed'));
+ $this->assertNoRaw($this->value2, t('Field 2 is not displayed'));
+
+ // Enable only field 2.
+ $this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array(
+ 'profile_block_author_fields[' . $this->field1['form_name'] . ']' => FALSE,
+ 'profile_block_author_fields[' . $this->field2['form_name'] . ']' => TRUE,
+ ), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Visit the node and confirm that the field is displayed.
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertNoRaw($this->value1, t('Field 1 is not displayed'));
+ $this->assertRaw($this->value2, t('Field 2 is displayed'));
+
+ // Enable both fields.
+ $this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array(
+ 'profile_block_author_fields[' . $this->field1['form_name'] . ']' => TRUE,
+ 'profile_block_author_fields[' . $this->field2['form_name'] . ']' => TRUE,
+ ), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Visit the node and confirm that the field is displayed.
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->assertRaw($this->value1, t('Field 1 is displayed'));
+ $this->assertRaw($this->value2, t('Field 2 is displayed'));
+
+ // Enable the link to the user profile.
+ $this->drupalPost('admin/structure/block/manage/profile/author-information/configure', array(
+ 'profile_block_author_fields[user_profile]' => TRUE,
+ ), t('Save block'));
+ $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.'));
+
+ // Visit the node and confirm that the user profile link is displayed.
+ $this->drupalGet('node/' . $this->node->nid);
+ $this->clickLink(t('View full user profile'));
+ $this->assertEqual($this->getUrl(), url('user/' . $this->normal_user->uid, array('absolute' => TRUE)));
}
}