/** * Shortcode version of `largo_render_user_list` * * @param $atts array The attributes of the shortcode. * * Example of possible attributes: * * [roster roles="author,contributor" include="292,12312" exclude="5002,2320" show_users_with_empty_desc="true"] * * @since 0.4 */ function largo_render_staff_list_shortcode($atts = array()) { $options = array(); $show_users_with_empty_desc = false; if (!empty($atts['show_users_with_empty_desc'])) { $show_users_with_empty_desc = $atts['show_users_with_empty_desc'] == 'false' ? false : true; unset($atts['show_users_with_empty_desc']); } if (!empty($atts['roles'])) { $roles = explode(',', $atts['roles']); $options['roles'] = array_map(function ($arg) { return trim($arg); }, $roles); } if (!empty($atts['exclude'])) { $exclude = explode(',', $atts['exclude']); $options['exclude'] = array_map(function ($arg) { return trim($arg); }, $exclude); } if (!empty($atts['include'])) { $exclude = explode(',', $atts['include']); $options['include'] = array_map(function ($arg) { return trim($arg); }, $exclude); } $defaults = array('roles' => array('author')); $args = array_merge($defaults, $options); largo_render_user_list(largo_get_user_list($args), $show_users_with_empty_desc); }
/** * 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() { /* * 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."); }