function validate_fb_username($errors, $update, $user) { if (isset($_POST["fb"])) { $fb_suspect = trim($_POST["fb"]); if (!empty($fb_suspect)) { $fb_user = largo_fb_url_to_username($fb_suspect); if (preg_match('/[^a-zA-Z0-9\\.\\-]/', $fb_user)) { // it's not a valid Facebook username, because it uses an invalid character $errors->add('fb_username', '<b>' . $fb_suspect . '</b> ' . __('is an invalid Facebook username.') . '</p>' . '<p>' . __('Facebook usernames only use the uppercase and lowercase alphabet letters (a-z A-Z), the Arabic numbers (0-9), periods (.) and dashes (-)')); } if (!largo_fb_user_is_followable($fb_user)) { $errors->add('fb_username', ' <b>' . $fb_suspect . '</b> ' . __('does not allow followers on Facebook.') . '</p>' . '<p>' . __('<a href="https://www.facebook.com/help/201148673283205#How-can-I-let-people-follow-me?">Follow these instructions</a> to allow others to follow you.')); } } } }
function test_largo_fb_user_is_followable() { /** * With no input, there should be no <table> in the resulting iframe */ $result = largo_fb_user_is_followable(""); $this->assertFalse($result, "The Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably. Please fix."); unset($result); /** * With Mark Zuckerberg, we hope that he will remain followable. */ $result = largo_fb_user_is_followable("zuck"); $this->assertTrue($result, "Either Mark Zuckerberg is no longer followable, or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably. Please log into Facebook and check that https://www.facebook.com/zuck has a 'Follow' button."); unset($result); /** * With a user that does not exist, we hope that the user will continue to not exist */ $result = largo_fb_user_is_followable("abcdefghijklmnopqrstuvwxyz12"); $this->assertFalse($result, "Either https://www.facebook.com/abcdefghijklmnopqrstuvwxyz12 is user that exists and allows follows, or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably."); unset($result); /** * With an invalid username, this should return false */ $result = largo_fb_user_is_followable("%22Aardvarks+lurk%2C+OK%3F%22"); $this->assertFalse($result, "Either https://www.facebook.com/%22Aardvarks+lurk%2C+OK%3F%22 is user that exists and allows follows (not at all likely), or the Facebook follow button iframe HTML structure has changed and largo_fb_url_to_username no longer operates predictably."); unset($result); }