<commit_before><?php
namespace wcf\system\user\notification;
use wcf\data\language\Language;
use wcf\data\user\notification\event\UserNotificationEvent;
use wcf\data\user\notification\UserNotification;
use wcf\data\user\User;
use wcf\data\user\UserAction;
use wcf\data\user\UserProfile;
use wcf\data\user\UserProfileList;
use wcf\system\cache\builder\ICacheBuilder;
use wcf\system\email\mime\RecipientAwareTextMimePart;
use wcf\system\email\Email;
use wcf\system\email\UserMailbox;
use wcf\system\exception\ImplementationException;
use wcf\system\language\LanguageFactory;
use wcf\system\user\notification\event\ITestableUserNotificationEvent;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
use wcf\util\MathUtil;
use wcf\util\PasswordUtil;
use wcf\util\StringUtil;

/**
 * Handles testable user notifications.
 * 
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH, <NAME>
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\User\Notification
 * @since	3.1
 */
class TestableUserNotificationEventHandler extends SingletonFactory {
	/**
	 * list of user profiles used as authors
	 * @var	UserProfile[]
	 */
	protected $authors;
	
	/**
	 * notification recipients grouped by language id and based upon the current
	 * user
	 * @var	UserProfile[]
	 */
	protected $recipients = [];
	
	/**
	 * maximum number of authors
	 */
	const MAX_AUTHOR_COUNT = 5;
	
	/**
	 * maximum number of guests
	 */
	const MAX_GUEST_COUNT = 2;
	
	/**
	 * Returns non-persistent user profiles used as authors.
	 * 
	 * @return	UserProfile[]
	 */
	public function getAuthors() {
		if ($this->authors === null) {
			$this->authors = [];
			
			$userProfileList = new UserProfileList();
			$userProfileList->getConditionBuilder()->add('userID <> ?', [$this->getRecipient()->userID]);
			$userProfileList->sqlLimit = self::MAX_AUTHOR_COUNT;
			
			$count = $userProfileList->countObjects();
			
			while ($count < self::MAX_AUTHOR_COUNT) {
				$username = substr(StringUtil::getRandomID(), 0, 10);
				
				(new UserAction([], 'create', [
					'data' => [
						'email' => $username . '@example.com',
						'password' => PasswordUtil::<PASSWORD>(),
						'registrationDate' => TIME_NOW - 24 * 3600 * MathUtil::getRandomValue(10, 1000),
						'username' => $username
					]
				]))->executeAction()['returnValues'];
				
				$count++;
			}<commit_msg>Fix `languageID` for newly created authors of test notifications<commit_after><?php
namespace wcf\system\user\notification;
use wcf\data\language\Language;
use wcf\data\user\notification\event\UserNotificationEvent;
use wcf\data\user\notification\UserNotification;
use wcf\data\user\User;
use wcf\data\user\UserAction;
use wcf\data\user\UserProfile;
use wcf\data\user\UserProfileList;
use wcf\system\cache\builder\ICacheBuilder;
use wcf\system\email\mime\RecipientAwareTextMimePart;
use wcf\system\email\Email;
use wcf\system\email\UserMailbox;
use wcf\system\exception\ImplementationException;
use wcf\system\language\LanguageFactory;
use wcf\system\user\notification\event\ITestableUserNotificationEvent;
use wcf\system\SingletonFactory;
use wcf\system\WCF;
use wcf\util\MathUtil;
use wcf\util\PasswordUtil;
use wcf\util\StringUtil;

/**
 * Handles testable user notifications.
 * 
 * @author	<NAME>
 * @copyright	2001-2017 WoltLab GmbH, <NAME>
 * @license	GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
 * @package	WoltLabSuite\Core\System\User\Notification
 * @since	3.1
 */
class TestableUserNotificationEventHandler extends SingletonFactory {
	/**
	 * list of user profiles used as authors
	 * @var	UserProfile[]
	 */
	protected $authors;
	
	/**
	 * notification recipients grouped by language id and based upon the current
	 * user
	 * @var	UserProfile[]
	 */
	protected $recipients = [];
	
	/**
	 * maximum number of authors
	 */
	const MAX_AUTHOR_COUNT = 5;
	
	/**
	 * maximum number of guests
	 */
	const MAX_GUEST_COUNT = 2;
	
	/**
	 * Returns non-persistent user profiles used as authors.
	 * 
	 * @return	UserProfile[]
	 */
	public function getAuthors() {
		if ($this->authors === null) {
			$this->authors = [];
			
			$userProfileList = new UserProfileList();
			$userProfileList->getConditionBuilder()->add('userID <> ?', [$this->getRecipient()->userID]);
			$userProfileList->sqlLimit = self::MAX_AUTHOR_COUNT;
			
			$count = $userProfileList->countObjects();
			
			$languages = LanguageFactory::getInstance()->getLanguages();
			
			while ($count < self::MAX_AUTHOR_COUNT) {
				$username = substr(StringUtil::getRandomID(), 0, 10);
				
				(new UserAction([], 'create', [
					'data' => [
						'email' => $username . '@example.com',
						'languageID' => $languages[array_rand($languages)]->languageID,
						'password' => PasswordUtil::getRandomPassword(),
						'registrationDate' => TIME_NOW - 24 * 3600 * MathUtil::getRandomValue(10, 1000),
						'username' => $username
					]
				]))->executeAction()['returnValues'];
				
				$count++;
			}
{'fraction_non_alphanumeric': 0.13949780789159028, 'fraction_numerical': 0.010761259465922678, 'mean_word_length': 4.131901840490798, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4560752', 'n_tokens_mistral': 1837, 'n_tokens_neox': 1555, 'n_words': 330}