Skip to content

Commit

Permalink
Merge pull request #754 from INN/IW-32-staff-roster-avatars-master
Browse files Browse the repository at this point in the history
Bugfix for IW-32, staff roster avatars master
  • Loading branch information
rnagle committed Jun 23, 2015
2 parents e1ddf96 + e04ff44 commit 70063c2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 3 deletions.
5 changes: 3 additions & 2 deletions inc/users.php
Expand Up @@ -300,10 +300,11 @@ function largo_render_user_list($users, $show_users_with_empty_desc=false) {
echo '<div class="user-list">';
foreach ($users as $user) {
$desc = trim($user->description);
if (empty($desc) && empty($show_users_with_empty_desc))
if (empty($desc) && ($show_users_with_empty_desc == false))
continue;

if (get_user_meta($user->ID, 'hide', true))
$hide = get_user_meta($user->ID, 'hide', true);
if ($hide == 'on')
continue;

$ctx = array('author_obj' => $user);
Expand Down
78 changes: 77 additions & 1 deletion tests/inc/test-users.php
Expand Up @@ -105,8 +105,84 @@ function test_largo_get_user_list() {
unset($ids);
}

/**
* Test the function largo_render_user_list
*
* Be aware: This may fail if partials/author-bio-description.php changes.
*/
function test_largo_render_user_list() {
$this->markTestIncomplete('This test has not been implemented yet.');
/*
* Test that a user without a description gets no output
*/
$user1 = $this->factory->user->create();
$arg1[] = get_user_by('id', $user1);

ob_start();
largo_render_user_list($arg1);
$out1 = ob_get_clean();
$this->assertEquals('<div class="user-list"></div>', $out1);

/*
* Test that a user with a description gets output
*/
$user2 = $this->factory->user->create();
update_user_meta($user2, 'description', 'foobar');
$arg2[] = get_user_by('id', $user2);

ob_start();
largo_render_user_list($arg2);
$out2 = ob_get_clean();
$this->assertRegExp('/author-box/', $out2);
$this->assertRegExp('/foobar/', $out2);

/*
* Test that a user with an avatar has output including the avatar
*/
$user3 = $this->factory->user->create();
$attachment = $this->factory->post->create(array('post_type' => 'attachment'));
update_user_meta($user3, 'description', 'foobar');
update_user_meta($user3, 'largo_avatar', $attachment);
$arg3[] = get_user_by('id', $user3);

ob_start();
largo_render_user_list($arg3);
$out3 = ob_get_clean();
$this->assertRegExp('/author-box/', $out3);
$this->assertRegExp('/foobar/', $out3);
$this->assertRegExp('/src/', $out3);

/*
* Test it with all the users
*/
$arg4[] = get_user_by('id', $user1);
$arg4[] = get_user_by('id', $user2);
$arg4[] = get_user_by('id', $user3);

ob_start();
largo_render_user_list($arg4);
$out4 = ob_get_clean();

$this->assertEquals( 2, preg_match_all('/author-box/', $out4, $matches), "There were not 2 authors with descriptions rendered.");
$this->assertEquals( 1, preg_match_all('/src=/', $out4, $matches), "There was not 1 author with an avatar image rendered.");

/*
* Test it with a user that is set to hide.
*/
$user4 = $this->factory->user->create();
$att4 = $this->factory->post->create(array('post_type' => 'attachment'));
update_user_meta($user4, 'description', 'foobar');
update_user_meta($user4, 'hide', 'on');
update_user_meta($user4, 'largo_avatar', $att4);
$arg4[] = get_user_by('id', $user4);

ob_start();
largo_render_user_list($arg4);
$out5 = ob_get_clean();

// Using same numbers here because the hidden user should not change these numbers.
$this->assertEquals( 2, preg_match_all('/author-box/', $out5, $matches), "There were not 2 authors with descriptions rendered.");
$this->assertEquals( 1, preg_match_all('/src=/', $out5, $matches), "There was not 1 author with an avatar image rendered.");

}

function test_largo_render_staff_list_shortcode() {
Expand Down

0 comments on commit 70063c2

Please sign in to comment.