Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * MUser Test File
- *
- * PHP version 5
- *
- * @package www_tests
- * @subpackage unit_models
- * @author Zarko Nemcanin <nemcaninz@gmail.com>
- * @copyright 2013 First Beat Media
- */
- /**
- * MUser Test
- *
- * PHP version 5
- *
- * @package www_tests
- * @subpackage unit_models
- * @author Aleksandar Atanasijevic <aleksandarqm@gmail.com>
- * @copyright 2013 First Beat Media
- */
- class MUserTest extends PilotTestCase
- {
- /**
- * setUp Method
- *
- * @return void
- */
- protected function setUp()
- {
- parent::setUp();
- $this->udata = [
- 'username' => 'aleksandar',
- 'login' => 'aleksandar',
- 'email' => 'aleksandar@aleksandar.com',
- 'password' => 'aleksandar',
- 'birthday' => time() - 3600 * 24 * 365 * 20,
- 'created_on' => time(),
- 'last_on' => time(),
- 'site_id' => 22,
- 'headline' => 'something about me...',
- 'self_description' => 'prog ramer tes ting account. Please remove. Thanks :-)',
- 'gender' => 1,
- 'seeking_for' => 4,
- 'country' => 'US',
- 'city_id' => 1,
- 'zip' => '00501',
- 'join_page' => 'join',
- ];
- $this->_app->db->query('delete from user_roles where user_id=:user_id', ['user_id' => 1], C::Db()->SITE_DEFAULT);
- $this->_app->setAuthMode(MPerm::MODE_NORMAL);
- $q = "DELETE FROM `users` WHERE `username` = :username or email = :email";
- $this->_app->db->query($q, array('username' => 'aleksandar', 'email' => 'aleksandar@aleksandar.com'));
- }
- /**
- * add new user
- *
- * @return int user id
- */
- protected function addUser()
- {
- $user = new MUser();
- $user->login = $this->udata['login'];
- $user->username = $this->udata['username'];
- $user->email = $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getProfile()->want_to_be_millionaire = 1;
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $id = $user->save();
- $this->assertTrue(in_array('NOTIFY_NEW_MSGS', $user->getSettings()->notifications));
- $this->assertTrue(in_array('NOTIFY_BB_ACK', $user->getSettings()->notifications));
- $this->assertTrue(in_array('NOTIFY_OFFERS', $user->getSettings()->notifications));
- $this->assertTrue($user->is_new);
- $this->assertNotEquals('new', $user->getStatus());
- $this->_app->db->insert('admin_site_users',
- ['admin_id' => 1, 'user_id' => $id, 'site_db' => C::Db()->SITE_DEFAULT], C::Db()->DATING);
- $user->setAdminUser(1);
- $this->_app->db->insert('photos', ['user_id' => $id, 'approved' => 1], C::Db()->SITE_DEFAULT);
- $this->_app->db->insert('photos', ['user_id' => $id, 'approved' => 1], C::Db()->SITE_DEFAULT);
- return $user;
- }
- /**
- * check user
- *
- * @param Muser $user user model
- *
- * @return void
- */
- protected function checkUser($user)
- {
- $this->assertEquals($this->udata['username'], $user->username);
- $this->assertEquals($this->udata['email'], $user->email);
- $this->assertEquals($this->udata['headline'], $user->getProfile()->headline);
- $this->assertEquals($this->udata['seeking_for'], $user->getProfile()->seeking_for);
- $this->assertEquals($this->udata['self_description'], $user->getProfile()->self_description);
- $this->assertEquals($this->udata['country'], $user->getGeoData()->country);
- $this->assertEquals($this->udata['city_id'], $user->getGeoData()->city_id);
- $this->assertEquals($this->udata['join_page'], $user->getJoinPage());
- $this->assertEquals($this->udata['birthday'], $user->birthday);
- // default role
- $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
- $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
- $this->assertFalse($user->getPerm()->check('WWW_PREMIUM'));
- $this->assertFalse($user->getPerm()->check('WWW_PAID'));
- }
- /**
- * test set property
- *
- * @return int user id
- */
- public function testSet()
- {
- $user = new MUser();
- $user->login = $this->udata['login'];
- $user->username = $this->udata['username'];
- $user->email = $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->last_on = $this->udata['last_on'];
- $user->site_id = $this->udata['site_id'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getProfile()->want_to_be_millionaire = 1;
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $this->assertEquals(0, $user->membership_weight);
- $this->checkUser($user);
- }
- /**
- * test new user
- *
- * @return void
- */
- public function testNewUser()
- {
- $user = $this->addUser();
- $roles_list = $this->_app->db->getAllForced(
- 'select role_id as id from user_roles where user_id=:user_id',
- ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
- $this->assertNotEmpty($roles_list);
- $this->_app->auth->login($user);
- $this->assertEquals(1, $this->_app->auth->user->isAdminUser());
- $this->checkUser($this->_app->auth->user);
- // $this->assertEquals(2, $this->_app->auth->user->photos_count);
- $this->checkMembershipWeight($this->_app->auth->user, 0);
- $this->checkUser($user);
- // $this->assertEquals(2, $user->photos_count);
- $this->assertTrue(in_array('NOTIFY_NEW_MSGS', $user->getSettings()->notifications));
- $this->checkMembershipWeight($user, 0);
- $sql = 'select data from user_settings where user_id = :user_id limit 1';
- $row = $this->_app->db->getRow($sql, ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
- $this->assertTrue(!empty($row));
- $sql = 'select data from user_geodata where user_id = :user_id limit 1';
- $row = $this->_app->db->getRow($sql, ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
- $this->assertTrue(!empty($row));
- $sql = 'select data from user_profiles where user_id = :user_id limit 1';
- $row = $this->_app->db->getRow($sql, ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
- $this->assertTrue(!empty($row));
- }
- /**
- * test update user
- *
- * @return void
- */
- public function testUpdateUser()
- {
- $user = $this->addUser();
- $this->_app->db->insert('photos', ['user_id' => $user->id, 'approved' => 1], C::Db()->SITE_DEFAULT);
- $this->_app->auth->login($user->id);
- $user = $this->_app->auth->user;
- // $this->assertEquals(2, $this->_app->auth->user->photos_count);
- $this->checkUser($user);
- $this->checkMembershipWeight($user, 0);
- $last_on = time();
- $user->username = $this->udata['username'] . '_';
- $user->getProfile()->headline = $this->udata['headline'] . '_new';
- $user->getProfile()->self_description = $this->udata['self_description'] . '_new';
- $user->getProfile()->self_description = $this->udata['self_description'] . '_new';
- $user->last_on = $last_on;
- $user->photo_id = 1;
- $user->save();
- $this->assertEquals($this->udata['username'] . '_', $user->username);
- $this->assertEquals($this->udata['headline'] . '_new', $user->getProfile()->headline);
- $this->assertEquals($this->udata['self_description'] . '_new', $user->getProfile()->self_description);
- $this->assertEquals($last_on, $user->last_on);
- $this->assertEquals(1, $user->photo_id);
- $user->setVoc('sr');
- $this->assertEquals('sr', $user->voc);
- $user = $this->_app->auth->user;
- $this->assertEquals($this->udata['username'] . '_', $user->username);
- $this->assertEquals($this->udata['headline'] . '_new', $user->getProfile()->headline);
- $this->assertEquals($this->udata['self_description'] . '_new', $user->getProfile()->self_description);
- $this->assertEquals($last_on, $user->last_on);
- $this->assertEquals(3, $user->photos_count);
- $this->assertEquals(1, $user->photo_id);
- $this->checkMembershipWeight($user, 0);
- $this->assertEquals('sr', $user->voc);
- }
- /**
- * load user
- *
- * @return void
- */
- public function testLoadUser()
- {
- $this->addUser();
- $user = new MUser(['username' => $this->udata['username']], C::Db()->SITE_DEFAULT);
- $this->checkUser($user);
- $user = new MUser(['username' => $this->udata['username'], 'email' => $this->udata['email']], C::Db()->SITE_DEFAULT);
- $this->checkUser($user);
- }
- /**
- * test free premium
- *
- * @return void
- */
- public function testWithFreePremium()
- {
- // with free premium
- $result = App::get()->db->query(
- 'update site_gender_age set free_premium = 1 where site_id = 22 and gender_id =1', null, C::Db()->DATING
- );
- $this->_app->auth->logout();
- $u = $this->addUser();
- $user_free = $this->_app->db->getRow(
- 'SELECT * FROM user_free_premium WHERE user_id = :id', ['id' => $u->id], C::Db()->SITE_DEFAULT, 0);
- $this->assertTrue(!empty($user_free));
- $this->assertTrue($user_free['reason'] == 'gender_free_premium');
- $this->assertTrue($user_free['application'] == 'www');
- $this->_app->auth->login($u->id);
- $this->checkMembershipWeight($this->_app->auth->user, 101);
- $user = $this->_app->auth->user;
- $free_date = $user->getPerm()->getFreePremium();
- $this->assertTrue(!empty($free_date));
- $this->checkMembershipWeight($user, 101);
- // remove free premium
- $user->getPerm()->setFreePremium();
- $user->save();
- $this->checkMembershipWeight($user, 0);
- $user_free = $this->_app->db->getRow(
- 'SELECT * FROM user_free_premium WHERE user_id = :id', ['id' => $u->id], C::Db()->SITE_DEFAULT, 0);
- $this->assertTrue(empty($user_free));
- $free_date = $user->getPerm()->getFreePremium();
- $this->assertTrue(empty($free_date));
- // add free premium
- $user->getPerm()->setFreePremium(date('Y-m-d H:i:s', strtotime('+ 5 day')));
- $user->save();
- $this->checkMembershipWeight($user, 101);
- $user_free = $this->_app->db->getRow(
- 'SELECT * FROM user_free_premium WHERE user_id = :id', ['id' => $u->id], C::Db()->SITE_DEFAULT, 0);
- $this->assertTrue(!empty($user_free));
- $free_date = $user->getPerm()->getFreePremium();
- $this->assertTrue(!empty($free_date));
- $this->checkMembershipWeight($user, 101);
- // remove free premium
- $result = App::get()->db->query(
- 'update site_gender_age set free_premium = 0 where site_id = 22', null, C::Db()->DATING
- );
- }
- /**
- * test new user
- *
- * @return void
- */
- public function testChangeRole()
- {
- $this->_app->auth->login($this->addUser());
- $user = $this->_app->auth->user;
- $this->assertTrue($user instanceof MUser);
- // default role
- $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
- $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
- $this->assertFalse($user->getPerm()->check('WWW_PREMIUM'));
- $this->assertFalse($user->getPerm()->check('WWW_PAID'));
- $user->save();
- $this->checkMembershipWeight($user, 0);
- $user->getPerm()->changeMembership(Roles::PAYING, 1, 'test');
- $this->checkMembershipChangeLog($user, Roles::PAYING);
- // still basic?
- $this->assertFalse($user->getPerm()->check('WWW_BASIC'));
- $this->assertFalse($user->getPerm()->check('WWW_SHOW_UPGRADE'));
- // is paying
- $this->assertTrue($user->getPerm()->check('WWW_PAID'));
- $user->save();
- $this->checkMembershipWeight($user, 50);
- $this->checkMembershipChangeLog($user, Roles::PAYING);
- // developer
- $user->getPerm()->changeMembership(Roles::DEVELOPER);
- $user->save();
- $this->assertTrue($user->getPerm()->check('WWW_DEVELOPER'));
- // and paying memeber
- $this->assertTrue($user->getPerm()->check('WWW_PAID'));
- $user->save();
- $this->checkMembershipWeight($user, 50);
- $this->checkMembershipChangeLog($user, Roles::PAYING);
- // basic
- $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test');
- $user->save();
- $this->checkMembershipChangeLog($user, Roles::BASIC);
- $this->checkMembershipWeight($user, 0);
- $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
- $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
- $this->assertFalse($user->getPerm()->check('WWW_PAID'));
- // must be developer
- $this->assertTrue($user->getPerm()->check('WWW_DEVELOPER'));
- $user->getPerm()->setFreePremium('2020-01-01 00:00:00');
- $this->checkMembershipWeight($user, 101);
- $user->getPerm()->setFreePremium('2030-01-01 00:00:00');
- $this->checkMembershipWeight($user, 101);
- $user->getPerm()->setFreePremium('2020-01-01 00:00:00');
- $this->checkMembershipWeight($user, 101);
- $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test');
- $user->save();
- $this->checkMembershipChangeLog($user, Roles::BASIC);
- $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test1');
- $user->save();
- $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test2');
- $user->save();
- $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test3');
- $user->save();
- $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test4');
- $user->save();
- $membership_change = $this->_app->db->getAllForced(
- 'select * from user_membership_change where user_id=:user_id',
- [ 'user_id' => $user->id], C::Db()->SITE_DEFAULT);
- $this->assertNotEmpty($membership_change);
- $this->assertEquals(2, count($membership_change));
- }
- /**
- * test gender switch
- *
- * @return void
- */
- public function testGender()
- {
- $user = new MUser($this->addUser());
- $user->getProfile()->gender = ProfileOptions::GENDER_BOY_TOY;
- $user->getProfile()->seeking_for = ProfileOptions::SEEKING_FOR_CUB_MALE;
- $user->save();
- $u = new MUser($user->id);
- $this->assertEquals(ProfileOptions::GENDER_MAN, $u->getProfile()->gender);
- $this->assertEquals(ProfileOptions::SEEKING_FOR_WOMAN, $u->getProfile()->seeking_for);
- }
- /**
- * test new user
- *
- * @return void
- */
- public function testWipe()
- {
- $this->_app->auth->login($this->addUser());
- $user = $this->_app->auth->user;
- $user->wipe();
- $user->save();
- $this->assertEquals('wiped', $user->status);
- $this->assertRegExp('/wiped/', $user->username);
- $this->assertRegExp('/wiped/', $user->login);
- $this->assertNotEquals($this->udata['email'], $user->email);
- }
- /**
- * test isDefinitionRejected method
- *
- * @throws EDb
- * @return void
- */
- public function testIsDefinitionRejected()
- {
- $this->_app->db->query('DELETE FROM filters_found;', array(), C::Db()->SITE_DEFAULT);
- $user = $this->addUser();
- $this->assertFalse($user->getProfile()->isHeadlineRejected());
- $this->assertFalse($user->getProfile()->isDescriptionRejected());
- $this->_app->db->insert(
- 'filters_found',
- [
- 'user_id' => $user->id,
- 'filter_id' => 2,
- 'info_id' => ProfileInfo::HEADLINE,
- 'definition' => 'some test headline',
- 'status' => 'rejected',
- ], C::Db()->SITE_DEFAULT
- );
- $this->assertTrue($user->getProfile()->isHeadlineRejected());
- $this->_app->db->insert(
- 'filters_found',
- [
- 'user_id' => $user->id,
- 'filter_id' => 2,
- 'info_id' => ProfileInfo::SELF_DESCRIPTION,
- 'definition' => 'some test headline',
- 'status' => 'rejected',
- ], C::Db()->SITE_DEFAULT
- );
- $this->assertTrue($user->getProfile()->isDescriptionRejected());
- }
- /**
- * test status
- *
- * @return void
- */
- public function testStatus()
- {
- // all missing
- $user = new MUser();
- $user->login = $this->udata['login'];
- $user->username = $this->udata['username'];
- $user->email = $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->save();
- $this->assertEquals('new', $user->getStatus());
- // headline & descr. missing
- $user = new MUser();
- $user->login = $this->udata['login'] . '2';
- $user->username = $this->udata['username'] . '2';
- $user->email = '2' . $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $user->save();
- $this->assertEquals('new', $user->getStatus());
- // gender /seeking missing
- $user = new MUser();
- $user->login = $this->udata['login'] . '3';
- $user->username = $this->udata['username'] . '3';
- $user->email = '3' . $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $user->save();
- $this->assertEquals('new', $user->getStatus());
- $user = new MUser();
- $user->login = $this->udata['login'] . '4';
- $user->username = $this->udata['username'] . '4';
- $user->email = '4' . $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $id = $user->save();
- $user = new MUser($id);
- $user->save();
- $this->assertEquals('approved', $user->getStatus());
- }
- /**
- * test user interaction filter
- *
- * @return void
- */
- public function testCanInteract()
- {
- $q = "DELETE FROM `users` WHERE `username` = :username or email = :email";
- $this->_app->db->query($q, array('username' => $this->udata['username'], 'email' => $this->udata['email']));
- $user = new MUser();
- $user->login = $this->udata['login'];
- $user->username = $this->udata['username'];
- $user->email = $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getProfile()->want_to_be_millionaire = 1;
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $id = $user->save();
- $user2 = new MUser();
- $user2->login = $this->udata['login'] . '1';
- $user2->username = $this->udata['username'] . '1';
- $user2->email = '1' . $this->udata['email'];
- $user2->password = $this->udata['password'];
- $user2->birthday = $this->udata['birthday'];
- $user2->site_id = $this->udata['site_id'];
- $user2->last_on = $this->udata['last_on'];
- $user2->getProfile()->headline = $this->udata['headline'];
- $user2->getProfile()->self_description = $this->udata['self_description'];
- $user2->getProfile()->want_to_be_millionaire = 1;
- $user2->getProfile()->gender = $this->udata['gender'];
- $user2->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user2->getGeoData()->country = $this->udata['country'];
- $user2->getGeoData()->city_id = $this->udata['city_id'];
- $user2->getGeoData()->zip = $this->udata['zip'];
- $user2->setJoinPage($this->udata['join_page']);
- $id2 = $user2->save();
- $this->assertFalse($user->canInteract($user2));
- $user2->getProfile()->gender = 2;
- $user2->getProfile()->seeking_for = 3;
- $user2->save();
- $this->assertTrue($user->canInteract($user2));
- $user = new MUser($id);
- $user2 = new MUser($id2);
- $this->assertTrue($user->canInteract($user2));
- $user->getProfile()->gender = 2;
- $user->getProfile()->seeking_for = 3;
- $user->save();
- $this->assertFalse($user->canInteract($user2));
- }
- /**
- * test rebill
- *
- * @throws EApp
- *
- * @return void
- */
- public function testRebill()
- {
- $this->_app->auth->logout();
- $user = new MUser();
- $user->login = 'a' . $this->udata['login'];
- $user->username = 'a' . $this->udata['username'];
- $user->email = 'a' . $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getProfile()->want_to_be_millionaire = 1;
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $id = $user->save();
- // $this->checkMembershipChangeLog($user, Roles::BASIC);
- $this->_app->auth->login($id);
- $this->checkMembershipWeight($user, 0);
- $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
- $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
- $this->assertFalse($user->getPerm()->check('WWW_PAID'));
- $this->assertTrue($this->_app->auth->user->getPerm()->check('WWW_BASIC'));
- $user->getPerm()->changeMembership(Roles::PAYING, 1, 'test');
- $roles_list = $this->_app->db->getAllForced(
- 'select role_id as id from user_roles where user_id=:user_id',
- ['user_id' => $id], C::Db()->SITE_DEFAULT);
- $this->assertTrue($user->getPerm()->check('WWW_PAID'));
- $this->checkMembershipChangeLog($user, Roles::PAYING);
- $u = $this->_app->auth->user;
- $this->assertTrue($u->getPerm()->check('WWW_PAID'));
- $this->assertTrue($this->_app->auth->user->getPerm()->check('WWW_PAID'));
- $this->assertTrue($user->getPerm()->check('WWW_PAID'));
- $u = $this->_app->auth->user;
- $u->getPerm()->changeMembership(Roles::BASIC, 1, 'test');
- $this->checkMembershipChangeLog($user, Roles::BASIC);
- $this->assertTrue($this->_app->auth->user->getPerm()->check('WWW_BASIC'));
- $this->assertTrue($u->getPerm()->check('WWW_BASIC'));
- }
- /**
- * test membership weight
- *
- * @param muser $user muser obj
- * @param int $weight membership weight
- *
- * @return void
- */
- protected function checkMembershipWeight($user, $weight)
- {
- $this->assertEquals($weight, $user->membership_weight);
- $membership_weight = $this->_app->db->getOne(
- 'SELECT membership_weight FROM users WHERE id = :id', ['id' => $user->id], C::Db()->SITE_DEFAULT, 0);
- $this->assertEquals($weight, $membership_weight);
- }
- /**
- * test user token
- *
- * @return void
- */
- public function testTokens()
- {
- $user = new MUser();
- $user->login = $this->udata['login'];
- $user->username = $this->udata['username'];
- $user->email = $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->getGeoData()->country = 'US';
- $user->getGeoData()->city_id = 1;
- $user->getGeoData()->zip = '00501';
- $user_id = $user->save();
- $token = $this->_app->db->getOne(
- 'select token from user_tokens where user_id = :user_id', ['user_id' => $user_id ], C::Db()->SITE_DEFAULT);
- $this->assertNotEmpty($token);
- $this->assertEquals($user->getUserToken(), $token);
- $this->assertEquals(md5($user->login . $user->id), $token);
- $new_user = MUser::initByToken($token, new MSite(C::Env()->PURE_HOST));
- $this->assertEquals($new_user->id, $user->id);
- // test missing token
- $this->_app->db->query(
- 'delete from user_tokens where user_id = :user', ['user' => $user_id], C::Db()->SITE_DEFAULT);
- $this->assertEquals($user->getUserToken(), $token);
- $token2 = $this->_app->db->getOneForced(
- 'select token from user_tokens where user_id = :user_id', ['user_id' => $user_id ], C::Db()->SITE_DEFAULT);
- $this->assertEquals($user->getUserToken(), $token2);
- }
- /**
- * test invalid user token
- *
- * @expectedException EFrontUser
- * @return void
- */
- public function testInvalidTokens()
- {
- MUser::initByToken('mynewtoken', new MSite(C::Env()->PURE_HOST));
- }
- /**
- * test invalid user
- *
- * @expectedException EFrontUser
- * @return void
- */
- public function testInvalidUsers()
- {
- $usr = new MUser(['username' => 'blablabla'], new MSite(C::Env()->PURE_HOST));
- }
- /**
- * test has allowedProfileOptions
- *
- * @return void
- */
- public function testHasAllowedProfileOption()
- {
- $user = new MUser();
- $user->login = $this->udata['login'];
- $user->username = $this->udata['username'];
- $user->email = $this->udata['email'];
- $user->password = $this->udata['password'];
- $user->birthday = $this->udata['birthday'];
- $user->site_id = $this->udata['site_id'];
- $user->last_on = $this->udata['last_on'];
- $user->getProfile()->headline = $this->udata['headline'];
- $user->getProfile()->self_description = $this->udata['self_description'];
- $user->getProfile()->want_to_be_millionaire = 1;
- $user->getProfile()->gender = $this->udata['gender'];
- $user->getProfile()->seeking_for = $this->udata['seeking_for'];
- $user->getGeoData()->country = $this->udata['country'];
- $user->getGeoData()->city_id = $this->udata['city_id'];
- $user->getGeoData()->zip = $this->udata['zip'];
- $user->setJoinPage($this->udata['join_page']);
- $id = $user->save();
- $user->getProfile()->religion = 402;
- $user->getProfile()->ethnicity = null;
- $user->save();
- $this->assertTrue($user->hasAllowedProfileOption('religion'));
- $this->assertTrue($user->hasAllowedProfileOption('ethnicity'));
- $user->getProfile()->religion = 1;
- $user->getProfile()->ethnicity = 2;
- $user->save();
- $this->assertFalse($user->hasAllowedProfileOption('religion'));
- $this->assertFalse($user->hasAllowedProfileOption('ethnicity'));
- }
- /**
- * tearDown Method
- *
- * @return void
- */
- protected function tearDown()
- {
- parent::tearDown();
- unset($this->udata);
- }
- /**
- * @param muser $user muser object
- *
- * @return void
- */
- protected function resetMembershipChangeLog($user)
- {
- $this->_app->db->query(
- 'delete from user_membership_change where user_id=:user_id',
- [ 'user_id' => $user->id, ], C::Db()->SITE_DEFAULT);
- }
- /**
- * @param muser $user muser object
- * @param int $role role id
- *
- * @return void
- */
- protected function checkMembershipChangeLog($user, $role)
- {
- $membership = $this->_app->db->getOneForced(
- 'select membership from user_membership_change where user_id=:user_id order by id desc',
- [ 'user_id' => $user->id, 'role' => $role ], C::Db()->SITE_DEFAULT);
- $this->assertEquals($role, $membership);
- // $this->resetMembershipChangeLog($user);
- }
- }
Add Comment
Please, Sign In to add comment