<commit_before><?php
/**
 * Copyright 2010, Cake Development Corporation (http://cakedc.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses('UsersController', 'Users.Controller');
App::uses('User', 'Users.User');
App::uses('AuthComponent', 'Controller/Component');
App::uses('CookieComponent', 'Controller/Component');
App::uses('SessionComponent', 'Controller/Component');
App::uses('Security', 'Utility');

/**
 * TestUsersController
 *
 * @package users
 * @subpackage users.tests.controllers
 */
class TestUsersController extends UsersController {

/**
 * Name
 *
 * @var string
 */
	public $name = 'Users';

/**
 * 
 */
	public $uses = array('Users.User');

/**
 * beforeFilter Callback
 *
 * @return void
 */
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->authorize = array('Controller');
		$this->Auth->fields = array('username' => 'email', 'password' => 'password');
		$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => false, 'plugin' => 'users');
		$this->Auth->loginRedirect = $this->Session->read('Auth.redirect');
		$this->Auth->logoutRedirect = '/';
		$this->Auth->authError = __d('users', 'Sorry, but you need to login to access this location.', true);
		$this->Auth->autoRedirect = true;
		$this->Auth->userModel = 'User';
		$this->Auth->userScope = array(
			'OR' => array(
				'AND' =>
					array('User.active' => 1, 'User.email_authenticated' => 1)));
	}

/**
 * Public interface to _setCookie
 */
	public function setCookie($options = array()) {
		parent::_setCookie($options);
	}

/**
 * Auto render
 *
 * @var boolean
 */
	public $autoRender = false;

/**
 * Redirect URL
 *
 * @var mixed
 */
	public $redirectUrl = null;

/**
 * Override controller method for testing
 */
	public function redirect($url, $status = null, $exit = true) {
		$this->redirectUrl = $url;
	}

/**
 * Override controller method for testing
 */
	public function render($action = null, $layout = null, $file = null) {
		$this->renderedView = $action;
	}
}

class UsersControllerTestCase extends CakeTestCase {

/**
 * Instance of the controller
 *
 * @var mixed
 */
	public $Users = null;

/**
 * Fixtures
 *
 * @var array
 */
	public $fixtures = array(
		'plugin.users.user',
		'plugin.users.detail',
		'plugin.users.identity');

/**
 * Sampletdata used for post data
 *
 * @var array
 */
	public $usersData = array(
		'admin' => array(
			'email' => '<EMAIL>',
			'username' => 'adminuser',
			'password' => '<PASSWORD>'),
		'validUser' => array(
			'email' => '<EMAIL>',
			'username' => 'testuser',
			'password' => '<PASSWORD>',
			'redirect' => '/user/slugname'),
		'invalidUser' => array(
			'email' => '<EMAIL>',
			'username' => 'invalidUser',
			'password' => '<PASSWORD>!'),
	);

/**
 * Start test
 *
 * @return void
 */
	public function startTest() {
		Configure::write('App.UserClass', null);
		$this->Users = new TestUsersController(new CakeRequest());
		$this->Users->constructClasses();
		$this->Users->request->params = array(
			'pass' => array(),
			'named' => array(),
			'controller' => 'users',
			'admin' => false,
			'plugin' => 'users',
			'url' => array());
		$this->Users->Email->delivery = 'debug';
	}

/**
 * Test controller instance
 *
 * @return void
 */
	public function testUsersControllerInstance() {
		$this->assertInstanceOf('UsersController', $this->Users);
	}

/**
 * Test the user login
 *
 * @return void
 */
	public function testUserLogin() {
		$this->Users->request->params['action'] = 'login';
 		$this->Users->startupProcess();

		$this->__setPost(array('User' => $this->usersData['admin']));
		$this->Users->request->url = '/users/users/login';
 		$this->Users->startupProcess();

		$this->Users->login();
		$result = $this->Users->Session->read('Message.flash.message');
		$expected = __d('users', 'adminuser you have successfully logged in', true);
		$this->assertEqual($result, $expected);

		$this->assertEqual(Router::normalize($this->Users->redirectUrl), Router::normalize(Router::url($this->Users->Auth->loginRedirect)));
	}
	
	public function testFailedUserLogin() {
		$this->Users->request->params['action'] = 'login';
		$this->__setPost(array('User' => $this->usersData['invalidUser']));
 		$this->Users->startupProcess();<commit_msg>Added doc block for new test<commit_after><?php
/**
 * Copyright 2010, Cake Development Corporation (http://cakedc.com)
 *
 * Licensed under The MIT License
 * Redistributions of files must retain the above copyright notice.
 *
 * @copyright Copyright 2010, Cake Development Corporation (http://cakedc.com)
 * @license MIT License (http://www.opensource.org/licenses/mit-license.php)
 */

App::uses('UsersController', 'Users.Controller');
App::uses('User', 'Users.User');
App::uses('AuthComponent', 'Controller/Component');
App::uses('CookieComponent', 'Controller/Component');
App::uses('SessionComponent', 'Controller/Component');
App::uses('Security', 'Utility');

/**
 * TestUsersController
 *
 * @package users
 * @subpackage users.tests.controllers
 */
class TestUsersController extends UsersController {

/**
 * Name
 *
 * @var string
 */
	public $name = 'Users';

/**
 * 
 */
	public $uses = array('Users.User');

/**
 * beforeFilter Callback
 *
 * @return void
 */
	public function beforeFilter() {
		parent::beforeFilter();
		$this->Auth->authorize = array('Controller');
		$this->Auth->fields = array('username' => 'email', 'password' => 'password');
		$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login', 'prefix' => 'admin', 'admin' => false, 'plugin' => 'users');
		$this->Auth->loginRedirect = $this->Session->read('Auth.redirect');
		$this->Auth->logoutRedirect = '/';
		$this->Auth->authError = __d('users', 'Sorry, but you need to login to access this location.', true);
		$this->Auth->autoRedirect = true;
		$this->Auth->userModel = 'User';
		$this->Auth->userScope = array(
			'OR' => array(
				'AND' =>
					array('User.active' => 1, 'User.email_authenticated' => 1)));
	}

/**
 * Public interface to _setCookie
 */
	public function setCookie($options = array()) {
		parent::_setCookie($options);
	}

/**
 * Auto render
 *
 * @var boolean
 */
	public $autoRender = false;

/**
 * Redirect URL
 *
 * @var mixed
 */
	public $redirectUrl = null;

/**
 * Override controller method for testing
 */
	public function redirect($url, $status = null, $exit = true) {
		$this->redirectUrl = $url;
	}

/**
 * Override controller method for testing
 */
	public function render($action = null, $layout = null, $file = null) {
		$this->renderedView = $action;
	}
}

class UsersControllerTestCase extends CakeTestCase {

/**
 * Instance of the controller
 *
 * @var mixed
 */
	public $Users = null;

/**
 * Fixtures
 *
 * @var array
 */
	public $fixtures = array(
		'plugin.users.user',
		'plugin.users.detail',
		'plugin.users.identity');

/**
 * Sampletdata used for post data
 *
 * @var array
 */
	public $usersData = array(
		'admin' => array(
			'email' => '<EMAIL>',
			'username' => 'adminuser',
			'password' => '<PASSWORD>'),
		'validUser' => array(
			'email' => '<EMAIL>',
			'username' => 'testuser',
			'password' => '<PASSWORD>',
			'redirect' => '/user/slugname'),
		'invalidUser' => array(
			'email' => '<EMAIL>',
			'username' => 'invalidUser',
			'password' => '<PASSWORD>!'),
	);

/**
 * Start test
 *
 * @return void
 */
	public function startTest() {
		Configure::write('App.UserClass', null);
		$this->Users = new TestUsersController(new CakeRequest());
		$this->Users->constructClasses();
		$this->Users->request->params = array(
			'pass' => array(),
			'named' => array(),
			'controller' => 'users',
			'admin' => false,
			'plugin' => 'users',
			'url' => array());
		$this->Users->Email->delivery = 'debug';
	}

/**
 * Test controller instance
 *
 * @return void
 */
	public function testUsersControllerInstance() {
		$this->assertInstanceOf('UsersController', $this->Users);
	}

/**
 * Test the user login
 *
 * @return void
 */
	public function testUserLogin() {
		$this->Users->request->params['action'] = 'login';
 		$this->Users->startupProcess();

		$this->__setPost(array('User' => $this->usersData['admin']));
		$this->Users->request->url = '/users/users/login';
 		$this->Users->startupProcess();

		$this->Users->login();
		$result = $this->Users->Session->read('Message.flash.message');
		$expected = __d('users', 'adminuser you have successfully logged in', true);
		$this->assertEqual($result, $expected);

		$this->assertEqual(Router::normalize($this->Users->redirectUrl), Router::normalize(Router::url($this->Users->Auth->loginRedirect)));
	}

/**
 * testFailedUserLogin
 *
 * @return void
 */
	public function testFailedUserLogin() {
		$this->Users->request->params['action'] = 'login';
		$this->__setPost(array('User' => $this->usersData['invalidUser']));
 		$this->Users->startupProcess();
{'fraction_non_alphanumeric': 0.20112409080890456, 'fraction_numerical': 0.002204099625303064, 'mean_word_length': 4.266976204294835, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 207, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6429224', 'n_tokens_mistral': 3046, 'n_tokens_neox': 2861, 'n_words': 623}