I am following this link https://github.com/omerkamcili/ci_google_calendar_api
for integrating google calendar in Codeigniter. I have
got all the credentials. But when i run this application
it returned me to http://hostname/auth/login every time
it logins to the application. When i debug it the token is not generated.
Model :Googlecalendar.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Googlecalendar extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->library('googleplus');
$this->calendar = new Google_Service_Calendar($this->googleplus->client());
}
public function isLogin()
{
$token = $this->session
->userdata('google_calendar_access_token');
if ($token) {
$this->googleplus
->client
->setAccessToken($token);
}
if ($this->googleplus->isAccessTokenExpired()) {
return false;
}
return $token;
}
public function loginUrl()
{
return $this->googleplus
->loginUrl();
}
public function login($code)
{
$login = $this->googleplus
->client
->authenticate($code);
if ($login) {
$token = $this->googleplus
->client
->getAccessToken();
$this->session
->set_userdata('google_calendar_access_token', $token);
return true;
}
}
public function getUserInfo()
{
return $this->googleplus->getUser();
}
public function getEvents($calendarId = 'primary', $timeMin = false, $timeMax = false, $maxResults = 10)
{
if ( ! $timeMin) {
$timeMin = date("c", strtotime(date('Y-m-d ').' 00:00:00'));
} else {
$timeMin = date("c", strtotime($timeMin));
}
if ( ! $timeMax) {
$timeMax = date("c", strtotime(date('Y-m-d ').' 23:59:59'));
} else {
$timeMax = date("c", strtotime($timeMax));
}
$optParams = array(
'maxResults' => $maxResults,
'orderBy' => 'startTime',
'singleEvents' => true,
'timeMin' => $timeMin,
'timeMax' => $timeMax,
'timeZone' => 'Europe/Istanbul',
);
$results = $this->googlecalendar->calendar->events->listEvents($calendarId, $optParams);
$data = array();
foreach ($results->getItems() as $item) {
$start = date('d-m-Y H:i', strtotime($item->getStart()->dateTime));
array_push(
$data,
array(
'id' => $item->getId(),
'summary' => $item->getSummary(),
'description' => $item->getDescription(),
'creator' => $item->getCreator(),
'start' => $item->getStart()->dateTime,
'end' => $item->getEnd()->dateTime,
)
);
}
return $data;
}
public function addEvent($calendarId = 'primary', $data)
{
//date format is => 2016-06-18T17:00:00+03:00
$event = new Google_Service_Calendar_Event(
array(
'summary' => $data['summary'],
'description' => $data['description'],
'start' => array(
'dateTime' => $data['start'],
'timeZone' => 'Europe/Istanbul',
),
'end' => array(
'dateTime' => $data['start'],
'timeZone' => 'Europe/Istanbul',
),
'attendees' => array(
array('email' => 'omerkamcili#gmail.com'),
),
)
);
return $this->calendar->events->insert($calendarId, $event);
}
}
Model: Auth.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Auth extends CI_Model
{
public function __construct()
{
parent::__construct();
$this->load->model('googlecalendar');
$this->load->library('session');
if ( ! $this->googlecalendar->isLogin()) {
$this->session->sess_destroy();
redirect('/auth/login', 'refresh');
}
}
}
If you are encountering problems when resolving particular names, and want to verify whether the problem is with Google Public DNS, please try resolve the domain first at: https://dns.google.com. If the result does not pinpoint the problem, you can run the following diagnostic procedure. Check this documentation for more details.
Related
I am facing issue when i try to broadcast my video in
When I use 'startVideo' its working fine for me.
But my 'connectVideo' giving me issue, I have pasted code below. I have attached error screenshot also.
In my first function 'startVideo' I wrote code to start video its taking my webcam video, through second function 'connectVideo' i just want share/broadcast my video with my user.
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use OpenTok\OpenTok;
use OpenTok\MediaMode;
use OpenTok\ArchiveMode;
use OpenTok\Role;
use OpenTok\Session;
use OpenTok\Broadcast;
use OpenTok\Layout;
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('welcome_message');
}
public function startVideo()
{
$opentok = new OpenTok($this->config->item('opentok_key'), $this->config->item('opentok_secret'));
$sessionOptions = array(
'archiveMode' => ArchiveMode::ALWAYS,
'mediaMode' => MediaMode::ROUTED
);
$session = $opentok->createSession($sessionOptions);
$iSessionId = $session->getSessionId();
date_default_timezone_set('Asia/Kolkata');
$created_date = date("Y-m-d H:i:s");
$data = array(
'apiKey' => $this->config->item('opentok_key'),
'sessionId' => $iSessionId,
'token' => $session->generateToken(),
'created_date' => $created_date
);
$archiveOptions = array(
'name' => 'Important Presentation', // default: null
'hasAudio' => true, // default: true
'hasVideo' => true, // default: true
// 'outputMode' => OutputMode::COMPOSED, // default: OutputMode::COMPOSED
'resolution' => '1280x720' // default: '640x480'
);
$this->load->view('video_11', $data);
}
public function connectVideo() // connect to a session
{
$opentok = new OpenTok($this->config->item('opentok_key'), $this->config->item('opentok_secret'));
$session = $opentok->createSession();
$sessionOptions = array(
'archiveMode' => ArchiveMode::ALWAYS,
'mediaMode' => MediaMode::ROUTED
);
$session = $opentok->createSession($sessionOptions);
$sessionId = $session->getSessionId();
$options = array(
'layout' => Layout::getBestFit(),
'maxDuration' => 5400,
'resolution' => '1280x720'
);
$broadcast = $opentok->startBroadcast($sessionId, $options);
// Store the broadcast ID in the database for later use
$broadcastId = $broadcast->id;
$token = 'T1==T1==cGFydG5lcl9pZD00NjQ5MTcwMiZzaWc9Y2MxYzkxYzNmYTkzNmNiNmQ0NDZiNWEzNzVhYjExYTliYTZkOTdlYzpzZXNzaW9uX2lkPTFfTVg0ME5qUTVNVGN3TW41LU1UWXhOVE00TXpJMU16WXdPWDVIWjB0WVp6SlJWRlJhVUV4c2FrczVOa0ZOZGk5SUwwOS1RWDQmY3JlYXRlX3RpbWU9MTYxNTM4MzI1MyZyb2xlPXB1Ymxpc2hlciZub25jZT0xNjE1MzgzMjUzLjY5ODUxOTY3MzAxNjU4';
$data = array(
'apiKey' => $this->config->item('opentok_key'),
'sessionId' => $session,
'token' => $token
);
$this->load->view('video_22', $data);
}
}
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/Q1qBY.png
i'm trying to develop a PrestaShop module with controllers i placed, for example in:
/modules/mymodule/controllers/admin/myControlController.php
class MyControlController extends ModuleAdminController {
public function __construct() {
$this->module = 'mymodule';
$this->bootstrap = true;
$this->context = Context::getContext();
$token = Tools::getAdminTokenLite('AdminModules');
$currentIndex='index.php?controller=AdminModules&token='.$token.'&configure=mymodule&tab_module=administration&module_name=mymodule';
Tools::redirectAdmin($currentIndex);
parent::__construct();
}
public function showForm() {
die("hello");
}}
Controller works (construct method is called) if i call it form url
http://myshop.com/adminxxx/index.php?controller=MyControl&token=9faf638aa961468c8563ffb030b3c4a8
But i can't access methods of controller from main class of module:
ModuleAdminController::getController('MyControl')->showForm();
I received "Class not found" ever
Is that the correct method to access a control from outside?
Thanks!
If you want to show anything that concern a form you should use renderForm().
Your should try parent::showForm(); or $this->showForm();.
Here is an example of controller that can work :
require_once _PS_MODULE_DIR_.'modulename/models/ModuleNameLog.php';
require_once _PS_MODULE_DIR_.'modulename/modulename.php';
class AdminModuleNameLogController extends ModuleAdminController
{
protected $_defaultOrderBy = 'id_modulenamelog';
protected $_defaultOrderWay = 'DESC';
public function __construct()
{
$this->table = 'modulenamelog';
$this->className = 'ModuleNameLog';
$this->context = Context::getContext();
$this->lang = false;
$this->bootstrap = true;
$this->actions_available = array();
$this->actions = array();
$this->show_toolbar = false;
$this->toolbar_btn['new'] = array();
$this->tabAccess['add'] = '0';
$this->allow_export = true;
$this->requiredDatabase = true;
$this->page_header_toolbar_title = $this->l('Example Module Name logs');
$this->_select = 'SUM(a.quantity) as total_quantity';
$this->_group = ' GROUP BY a.id_product, a.id_product_attribute ';
$this->fields_list = array(
'id_product' => array(
'title' => $this->l('Product'),
'align' => 'center',
'callback' => 'getProductName',
),
'id_product_attribute' => array(
'title' => $this->l('Combination'),
'align' => 'center',
'callback' => 'getAttributeName',
),
'total_quantity' => array(
'title' => $this->l('Total Quantity'),
'align' => 'center',
),
);
$this->mod = new ModuleName();
$this->mod->cleanLogs();
$this->context = Context::getContext();
parent::__construct();
}
public function getProductName($id)
{
if (!empty($id)) {
$product = new Product($id, true, $this->context->cookie->id_lang);
return $product->name;
}
}
public function getAttributeName($id)
{
if (!empty($id)) {
$combination = new Combination($id);
$names = $combination->getAttributesName($this->context->cookie->id_lang);
$str = array();
if (!empty($names)) {
foreach ($names as $value) {
$str[] = $value['name'];
}
}
return implode(' - ', $str);
} else {
return '-';
}
}
public function postProcess()
{
if (Tools::isSubmit('purge_id')) {
// Do something here
$id = (int) Tools::getValue('purge_id');
Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModuleNameLog').'&conf=4');
}
parent::postProcess();
}
public function renderList()
{
$carts = Db::getInstance()->executeS('SELECT ct.*, cs.`firstname`, cs.`lastname` FROM '._DB_PREFIX_.'cart ct LEFT JOIN '._DB_PREFIX_.'customer cs ON ct.id_customer = cs.id_customer WHERE 1 ORDER BY id_cart DESC LIMIT 0,2000');
$tpl = $this->context->smarty->createTemplate(_PS_MODULE_DIR_.'modulename/views/templates/admin/preform.tpl');
$tpl->assign(array(
'carts' => $carts,
));
$html = $tpl->fetch();
return $html.parent::renderList();
}
public function renderForm()
{
if (!$this->loadObject(true)) {
return;
}
$obj = $this->loadObject(true);
if (isset($obj->id)) {
$this->display = 'edit';
} else {
$this->display = 'add';
}
$array_submit = array(
array(
'type' => 'select',
'label' => $this->l('Cart :'),
'name' => 'id_cart',
'options' => array(
'query' => Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'cart WHERE id_cart > 0 ORDER BY id_cart DESC LIMIT 0,500'),
'id' => 'id_cart',
'name' => 'id_cart',
),
),
array(
'type' => 'text',
'label' => $this->l('Quantity translation here'),
'hint' => $this->l('Description and translation here'),
'name' => 'quantity',
),
);
$this->fields_form[0]['form'] = array(
'tinymce' => false,
'legend' => array(
'title' => $this->l('Form title'),
),
'input' => $array_submit,
'submit' => array(
'title' => $this->l('Save'),
'class' => 'btn btn-default',
),
);
$this->multiple_fieldsets = true;
return parent::renderForm();
}
}
I'm trying to test a method which is using a service, and apparently it's not possible to test it like a normal method.
Does someone know what to do ?
I have this code for the moment :
namespace PlatformBundle\Tests;
use PlatformBundle\Controller\PaymentController;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class PaymentControllerTest extends WebTestCase
{
private $payment;
public function __construct() { parent::__construct(); $this->payment = new PaymentController(); }
public function testSendEmail()
{
$param = array(
'info' => array(
'email' => 'test#test.com', 'name' => 'test', 'fare' => 'test', 'id' => 'test'
)
);
$this->assertEquals(true, $this->invokeMethod($this->payment, 'sendEmail', $param));
}
/**
* Call protected/private method of a class.
*
* #param object &$object Instantiated object that we will run method on.
* #param string $methodName Method name to call
* #param array $parameters Array of parameters to pass into method.
*
* #return mixed Method return.
*/
public function invokeMethod(&$object, $methodName, array $parameters = array())
{
$reflection = new \ReflectionClass(get_class($object));
$method = $reflection->getMethod($methodName);
$method->setAccessible(true);
return $method->invokeArgs($object, $parameters);
}
}
The controller where the method sendEmail is :
<?php
namespace PlatformBundle\Controller;
use PlatformBundle\Entity\Customer;
use PlatformBundle\Entity\Promocode;
use PlatformBundle\Entity\Transfer;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
class PaymentController extends Controller
{
public function checkoutAction(Request $req)
{
if (! $req->isMethod('POST')) throw new AccessDeniedHttpException();
$info = $req->request->all();
$this->container->get('platform.formSecurity')->testAllInformation($info);
$this->saveCustomerIntoDb($info);
$info['payed'] = false;
$session = $req->getSession();
$session->set('info', $info);
$info['date'] = $this->container->get('platform.useful')->reverseDateFormat($info['date']);
return $this->render('PlatformBundle:Payment:checkout.html.twig', array(
'isIndex' => false,
'info' => $info,
'stripe' => $this->stripeConfig()
));
}
public function cancelAction(Request $req)
{
$req->getSession()->invalidate();
return $this->render('PlatformBundle:Payment:cancel.html.twig', array('isIndex' => false));
}
public function successAction(Request $req)
{
$session = $req->getSession();
$info = $session->get('info');
if ($info['payed']) {
$req->getSession()->invalidate();
if ($info === null) throw new Exception('Please contact us to make sure that the payment has been done and that your order has been taken into account.');
$this->saveTransferIntoDb($info);
$customer = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Customer')->findOneBy(array(
'email' => $info['email']
));
$transfer = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Transfer')->findOneBy(
array('customer' => $customer->getId()),
array('id' => 'desc'),
1
);
$info['id'] = $transfer->getId();
$info['date'] = $this->container->get('platform.useful')->reverseDateFormat($info['date']);
$this->sendEmail($info);
// if 5 payments done, send a promocode
if (is_int($customer->getPayments() / 5)) {
$this->createAndSendNewPromocode($customer);
}
return $this->render('PlatformBundle:Payment:success.html.twig', array(
'isIndex' => false,
'info' => $info
));
} else return new RedirectResponse('cancel');
}
private function sendEmail($info)
{
$mail = $this->container->get('platform.mail');
$mail->send(
$info['email'],
'You have ordered a transfer for Dublin',
$this->renderView('PlatformBundle:Mail:orderSucceed.html.twig', array('info' => $info)),
'info#dubair.ie'
);
$mail->send(
'info#airportcollections.net, info#dubair.ie, info#365onlineholidays.com',
'A customer ordered a transfer for Dublin',
$this->renderView('PlatformBundle:Mail:report.html.twig', array('info' => $info)),
'info#dubair.ie'
);
}
private function saveCustomerIntoDb($info)
{
// test if the customer already exist
$customersList = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Customer')
->findByEmail($info['email']);
$customerExists = (sizeof($customersList) == 1 ? true : false);
if ($customerExists) {
$customer = $customersList[0];
} else {
// Create the entity
$customer = new Customer();
// dateRegistration, country and ip are automatically created in the constructor
$customer->setEmail($info['email']);
$customer->setPayments(0);
}
$customer->setName($info['name']);
$customer->setPhone($info['phone']);
$em = $this->getDoctrine()->getManager();
$em->persist($customer);
$em->flush();
}
private function saveTransferIntoDb($info)
{
$customers = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Customer')
->findByEmail($info['email']);
$customer = $customers[0];
$customer->setPayments($customer->getPayments() + 1);
// make promocode outdated
if ($info['promocode'] != '') {
$promocode = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Promocode')
->findOneBy(array(
'value' => $info['promocode'],
'outdated' => 0,
'type' => 'short'
));
$promocode->setOutdated(1);
}
// test if transfer already exist
$transferList = $this->getDoctrine()->getManager()->getRepository('PlatformBundle:Transfer')->findBy(
array(
'customer' => $customer,
'pickup' => $info['pickup'],
'destination' => $info['destination'],
'pickupTime' => $info['pickupTime'],
'address' => $info['address']
), // criteria
array('pickup' => 'desc'), // sorting
5, // Limit
0 // Offset
);
// if transfer doesn't already exist, create it
if (sizeof($transferList) == 0) {
$transfer = new Transfer();
$transfer->setPickup($info['pickup']);
$transfer->setDestination($info['destination']);
$dateArray = explode('-', $info['date']);
$transfer->setDate(new \DateTime($dateArray[2].'-'.$dateArray[1].'-'.$dateArray[0]));
$transfer->setAddress($info['address']);
$transfer->setFlightTime($info['flightTime']);
$transfer->setPickupTime($info['pickupTime']);
$transfer->setSeats($info['seats']);
$transfer->setAirline($info['airline']);
$transfer->setFlight($info['flight']);
$transfer->setType($info['type']);
$transfer->setBags($info['bags']);
$transfer->setFare($info['fare']);
// join
$transfer->setCustomer($customer);
$em = $this->getDoctrine()->getManager();
$em->persist($transfer);
$em->flush();
}
}
private function createAndSendNewPromocode($customer)
{
$newPromocode = $this->container->get('platform.useful')->createRandomPassword();
$promocode = new Promocode();
$promocode->setValue($newPromocode);
$promocode->setType('short');
$promocode->setDiscount(10);
$em = $this->getDoctrine()->getManager();
$em->persist($promocode);
$em->flush();
$mail = $this->container->get('platform.mail');
$mail->send(
$customer->getEmail(),
'A promotional code for your next transfer on dubair.ie !',
$this->renderView('PlatformBundle:Mail:promocode.html.twig', array(
'customer' => $customer,
'promocode' => $newPromocode
)),
'info#dubair.ie'
);
}
private function stripeConfig()
{
$stripe = array(
"secret_key" => "xx",
"publishable_key" => "xx"
);
\Stripe\Stripe::setApiKey($stripe['secret_key']);
return $stripe;
}
public function stripeChargeAction(Request $req)
{
$this->stripeConfig();
$info = $req->getSession()->get('info');
$amount = ($info['fare'] * 100);
$info['payed'] = true;
$req->getSession()->set('info', $info);
$token = $req->request->get('stripeToken');
$customer = \Stripe\Customer::create(array(
'email' => $req->request->get('email'),
'card' => $token
));
$charge = \Stripe\Charge::create(array(
'customer' => $customer->id,
'amount' => $amount,
'currency' => 'eur'
));
return new RedirectResponse('success');
}
}
thanks
I tried to make the monitoring session but when adding script of the model script is not running?
Login controller:
public function do_login(){
$data = $this->input->post(null,true);
$result = $this->db->get_where('user',array('username'=>$data['username'],'password'=>md5(trim($data['password'])),))->row();
$is_login = $this->defaults->login($result); //load from model
if($is_login){
$session_set = array(
'is_login' => true,
'nama' => $is_login->nama,
'nik' => $is_login->nik,
'divisi' => $is_login->divisi,
'jabatan_id' => $is_login->jabatan_id,
'id_user' => $is_login->id_user,
'username' => $is_login->username,
'last_login' => $is_login->last_login
);
$this->db->update('user',array('last_login'=>date('Y-m-d H:i:s')),array('id_user'=>$is_login->id_user));
$this->session->set_userdata($session_set);
redirect('home/home');
} else {
redirect('login/login/index/error');
}
}
Model:
public function login() {
if ($this->agent->is_browser()) {
$agent =$this->agent->browser().''.$this->agent->version();
}
elseif ($this->agent->is_robot()) {
$agent = $this->agent->robot();
}
elseif ($this->agent->is_mobile()) {
$agent = $this->agent->mobile();
}
else {
$agent = 'Unidentified User Agent';
}
$username = $this->security->xss_clean($this->input->post('username'));
$data = array(
'namapengguna' => $username,
'platform' => $this->agent->platform(),
'browser' => $agent,
'logged_in' => true,);
$this->session->set_userdata($data);
return true;
}
I thought I have to ask here some help to my problem. I've spend whole evening with this. I have a login method in UsersController like this:
public function login() {
if ( $this->request->is( 'post' ) ) {
if ( $this->Auth->login() ) {
$this->redirect( array( 'controller' => 'reservations', 'action' => 'index' ) );
} else {
$this->Session->setFlash( __( 'Login error.' ), 'flashError' );
}
}
}
I trying to test this with PHPUnit, so I can be sure that only valid users can login → after a successful login they will be redirected to a specific page. Here's my testLogin method in UsersControllerTest class:
function testLogin() {
$UsersController = $this->generate( 'Users', array(
'components' => array(
'Auth' => array( 'user' )
),
)
);
$UsersController->Auth->expects( $this->any() )
->method( 'user' )
->with( 'id' )
->will( $this->returnValue( 2 ) );
$data = array( 'User' => array(
'student_number' => 1111111,
'password' => 'qwerty'
) );
//$UsersController->Auth->login( $data['User'] );
$this->testAction( '/users/login', array( 'data' => $data, 'method' => 'get' ) );
$url = parse_url( $this->headers['Location'] );
$this->assertEquals( $url['path'], '/reservations' );
}
I am still learning the basics of unit testing with CakePHP. I get this error:
PHPUNIT_FRAMEWORK_ERROR_NOTICE
Undefined index: Location
Test case: UsersControllerTest(testLogin)
I have no idea what causes this... What's wrong with my test method and how it should be written?
Thanks!
I got this working with the following code:
function testLogin() {
//mock user
$this->Users = $this->generate( 'Users', array(
'components' => array(
'Security' => array( '_validatePost' ),
)
) );
//create user data array with valid info
$data = array();
$data['User']['student_number'] = 1234567;
$data['User']['password'] = '[valid password here]';
//test login action
$result = $this->testAction( "/users/login", array(
"method" => "post",
"return" => "contents",
"data" => $data
)
);
$foo[] = $this->view;
//debug($foo);
//test successful login
$this->assertNotNull( $this->headers['Location'] );
$this->assertContains( 'reservations', $this->headers['Location'] );
$this->assertNotContains( '"/users/login" id="UserLoginForm"', $foo );
//logout mocked user
$this->Users->Auth->logout();
}
I use this testcase to override the cake Auth call and Session and check if the login is successful.
this is more of a generic solution that i use in my testing., to get the values put into the session after the user logs in and also to check if the login is successful.
<?php
App::uses('UsersController', 'Controller');
App::uses('AuthComponent', 'Controller/Component');
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
$_SERVER['HTTP_USER_AGENT'] = '';
class stubSession {
public $data = array();
public function write($key, $value){
$this->data[$key] = $value;
}
public function read($key){
if(array_key_exists($key, $this->data)){
return $this->data[$key];
}
}
public function renew() {
}
public function setFlash(){
}
public function delete() {
}
public function check(){
}
}
class stubRequest {
public $data = array();
function __construct($data) {
$this->data = $data;
}
public function is() {
return true;
}
public function clientIp(){
}
}
class stubAuthComponent extends AuthComponent{
public static $_session;
public function __construct($args, $session){
parent::__construct($args);
$this->Session = $session;
self::$_session = $session;
$this->request = new CakeRequest();
$this->response = new CakeResponse();
}
public function loggedIn() {
return self::$_session->read(self::$sessionKey) != array();
}
public function logout(){
}
public static function user($key) {
$user = self::$_session->read(self::$sessionKey);
return $user[$key];
}
}
class UsersControllerTest extends UsersController {
function __construct($data){
$this->User = ClassRegistry::init('User');
$this->Session = new stubSession();
$this->Auth = new stubAuthComponent(new ComponentCollection(), $this->Session);
$this->request = new stubRequest($data);
}
public function redirect(){
}
}
class TestUsersController extends CakeTestCase {
public function testLogin(){
$_POST = array('User' => array('email' => 'mail#someemail.com', 'username' => 'mail#someemail.com', 'password' => 'abcd1234'));
$usersController = new UsersControllerTest($_POST);
$usersController->login();
$login = $usersController->Auth->loggedIn();
//debug($usersController->Session->data); //you can test the session key value in here
$this->assertEquals($login, true);
}
}