Guest User

Untitled

a guest
Jun 2nd, 2017
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.82 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. * MUser Test File
  5. *
  6. * PHP version 5
  7. *
  8. * @package www_tests
  9. * @subpackage unit_models
  10. * @author Zarko Nemcanin <nemcaninz@gmail.com>
  11. * @copyright 2013 First Beat Media
  12. */
  13.  
  14.  
  15. /**
  16. * MUser Test
  17. *
  18. * PHP version 5
  19. *
  20. * @package www_tests
  21. * @subpackage unit_models
  22. * @author Aleksandar Atanasijevic <aleksandarqm@gmail.com>
  23. * @copyright 2013 First Beat Media
  24. */
  25. class MUserTest extends PilotTestCase
  26. {
  27. /**
  28. * setUp Method
  29. *
  30. * @return void
  31. */
  32. protected function setUp()
  33. {
  34. parent::setUp();
  35. $this->udata = [
  36. 'username' => 'aleksandar',
  37. 'login' => 'aleksandar',
  38. 'email' => 'aleksandar@aleksandar.com',
  39. 'password' => 'aleksandar',
  40. 'birthday' => time() - 3600 * 24 * 365 * 20,
  41. 'created_on' => time(),
  42. 'last_on' => time(),
  43. 'site_id' => 22,
  44. 'headline' => 'something about me...',
  45. 'self_description' => 'prog ramer tes ting account. Please remove. Thanks :-)',
  46. 'gender' => 1,
  47. 'seeking_for' => 4,
  48. 'country' => 'US',
  49. 'city_id' => 1,
  50. 'zip' => '00501',
  51. 'join_page' => 'join',
  52. ];
  53.  
  54. $this->_app->db->query('delete from user_roles where user_id=:user_id', ['user_id' => 1], C::Db()->SITE_DEFAULT);
  55. $this->_app->setAuthMode(MPerm::MODE_NORMAL);
  56. $q = "DELETE FROM `users` WHERE `username` = :username or email = :email";
  57. $this->_app->db->query($q, array('username' => 'aleksandar', 'email' => 'aleksandar@aleksandar.com'));
  58.  
  59. }
  60.  
  61. /**
  62. * add new user
  63. *
  64. * @return int user id
  65. */
  66. protected function addUser()
  67. {
  68. $user = new MUser();
  69. $user->login = $this->udata['login'];
  70. $user->username = $this->udata['username'];
  71. $user->email = $this->udata['email'];
  72. $user->password = $this->udata['password'];
  73. $user->birthday = $this->udata['birthday'];
  74. $user->site_id = $this->udata['site_id'];
  75. $user->last_on = $this->udata['last_on'];
  76. $user->getProfile()->headline = $this->udata['headline'];
  77. $user->getProfile()->self_description = $this->udata['self_description'];
  78. $user->getProfile()->want_to_be_millionaire = 1;
  79. $user->getProfile()->gender = $this->udata['gender'];
  80. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  81.  
  82. $user->getGeoData()->country = $this->udata['country'];
  83. $user->getGeoData()->city_id = $this->udata['city_id'];
  84. $user->getGeoData()->zip = $this->udata['zip'];
  85. $user->setJoinPage($this->udata['join_page']);
  86. $id = $user->save();
  87.  
  88. $this->assertTrue(in_array('NOTIFY_NEW_MSGS', $user->getSettings()->notifications));
  89. $this->assertTrue(in_array('NOTIFY_BB_ACK', $user->getSettings()->notifications));
  90. $this->assertTrue(in_array('NOTIFY_OFFERS', $user->getSettings()->notifications));
  91.  
  92. $this->assertTrue($user->is_new);
  93. $this->assertNotEquals('new', $user->getStatus());
  94.  
  95. $this->_app->db->insert('admin_site_users',
  96. ['admin_id' => 1, 'user_id' => $id, 'site_db' => C::Db()->SITE_DEFAULT], C::Db()->DATING);
  97.  
  98. $user->setAdminUser(1);
  99. $this->_app->db->insert('photos', ['user_id' => $id, 'approved' => 1], C::Db()->SITE_DEFAULT);
  100. $this->_app->db->insert('photos', ['user_id' => $id, 'approved' => 1], C::Db()->SITE_DEFAULT);
  101.  
  102.  
  103. return $user;
  104. }
  105.  
  106. /**
  107. * check user
  108. *
  109. * @param Muser $user user model
  110. *
  111. * @return void
  112. */
  113. protected function checkUser($user)
  114. {
  115. $this->assertEquals($this->udata['username'], $user->username);
  116. $this->assertEquals($this->udata['email'], $user->email);
  117. $this->assertEquals($this->udata['headline'], $user->getProfile()->headline);
  118. $this->assertEquals($this->udata['seeking_for'], $user->getProfile()->seeking_for);
  119. $this->assertEquals($this->udata['self_description'], $user->getProfile()->self_description);
  120. $this->assertEquals($this->udata['country'], $user->getGeoData()->country);
  121. $this->assertEquals($this->udata['city_id'], $user->getGeoData()->city_id);
  122. $this->assertEquals($this->udata['join_page'], $user->getJoinPage());
  123. $this->assertEquals($this->udata['birthday'], $user->birthday);
  124.  
  125. // default role
  126. $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
  127. $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
  128.  
  129. $this->assertFalse($user->getPerm()->check('WWW_PREMIUM'));
  130. $this->assertFalse($user->getPerm()->check('WWW_PAID'));
  131. }
  132.  
  133. /**
  134. * test set property
  135. *
  136. * @return int user id
  137. */
  138. public function testSet()
  139. {
  140. $user = new MUser();
  141. $user->login = $this->udata['login'];
  142. $user->username = $this->udata['username'];
  143. $user->email = $this->udata['email'];
  144. $user->password = $this->udata['password'];
  145. $user->birthday = $this->udata['birthday'];
  146. $user->last_on = $this->udata['last_on'];
  147. $user->site_id = $this->udata['site_id'];
  148. $user->getProfile()->headline = $this->udata['headline'];
  149. $user->getProfile()->self_description = $this->udata['self_description'];
  150. $user->getProfile()->want_to_be_millionaire = 1;
  151. $user->getProfile()->gender = $this->udata['gender'];
  152. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  153.  
  154. $user->getGeoData()->country = $this->udata['country'];
  155. $user->getGeoData()->city_id = $this->udata['city_id'];
  156. $user->getGeoData()->zip = $this->udata['zip'];
  157. $user->setJoinPage($this->udata['join_page']);
  158.  
  159. $this->assertEquals(0, $user->membership_weight);
  160. $this->checkUser($user);
  161. }
  162.  
  163. /**
  164. * test new user
  165. *
  166. * @return void
  167. */
  168. public function testNewUser()
  169. {
  170. $user = $this->addUser();
  171.  
  172. $roles_list = $this->_app->db->getAllForced(
  173. 'select role_id as id from user_roles where user_id=:user_id',
  174. ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
  175.  
  176. $this->assertNotEmpty($roles_list);
  177. $this->_app->auth->login($user);
  178. $this->assertEquals(1, $this->_app->auth->user->isAdminUser());
  179. $this->checkUser($this->_app->auth->user);
  180. // $this->assertEquals(2, $this->_app->auth->user->photos_count);
  181. $this->checkMembershipWeight($this->_app->auth->user, 0);
  182.  
  183. $this->checkUser($user);
  184. // $this->assertEquals(2, $user->photos_count);
  185. $this->assertTrue(in_array('NOTIFY_NEW_MSGS', $user->getSettings()->notifications));
  186. $this->checkMembershipWeight($user, 0);
  187.  
  188. $sql = 'select data from user_settings where user_id = :user_id limit 1';
  189. $row = $this->_app->db->getRow($sql, ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
  190. $this->assertTrue(!empty($row));
  191.  
  192. $sql = 'select data from user_geodata where user_id = :user_id limit 1';
  193. $row = $this->_app->db->getRow($sql, ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
  194. $this->assertTrue(!empty($row));
  195.  
  196. $sql = 'select data from user_profiles where user_id = :user_id limit 1';
  197. $row = $this->_app->db->getRow($sql, ['user_id' => $user->id], C::Db()->SITE_DEFAULT);
  198. $this->assertTrue(!empty($row));
  199.  
  200. }
  201.  
  202. /**
  203. * test update user
  204. *
  205. * @return void
  206. */
  207. public function testUpdateUser()
  208. {
  209. $user = $this->addUser();
  210. $this->_app->db->insert('photos', ['user_id' => $user->id, 'approved' => 1], C::Db()->SITE_DEFAULT);
  211.  
  212. $this->_app->auth->login($user->id);
  213. $user = $this->_app->auth->user;
  214.  
  215. // $this->assertEquals(2, $this->_app->auth->user->photos_count);
  216.  
  217. $this->checkUser($user);
  218. $this->checkMembershipWeight($user, 0);
  219.  
  220. $last_on = time();
  221. $user->username = $this->udata['username'] . '_';
  222. $user->getProfile()->headline = $this->udata['headline'] . '_new';
  223. $user->getProfile()->self_description = $this->udata['self_description'] . '_new';
  224. $user->getProfile()->self_description = $this->udata['self_description'] . '_new';
  225. $user->last_on = $last_on;
  226. $user->photo_id = 1;
  227. $user->save();
  228.  
  229. $this->assertEquals($this->udata['username'] . '_', $user->username);
  230. $this->assertEquals($this->udata['headline'] . '_new', $user->getProfile()->headline);
  231. $this->assertEquals($this->udata['self_description'] . '_new', $user->getProfile()->self_description);
  232. $this->assertEquals($last_on, $user->last_on);
  233. $this->assertEquals(1, $user->photo_id);
  234. $user->setVoc('sr');
  235. $this->assertEquals('sr', $user->voc);
  236.  
  237. $user = $this->_app->auth->user;
  238. $this->assertEquals($this->udata['username'] . '_', $user->username);
  239. $this->assertEquals($this->udata['headline'] . '_new', $user->getProfile()->headline);
  240. $this->assertEquals($this->udata['self_description'] . '_new', $user->getProfile()->self_description);
  241. $this->assertEquals($last_on, $user->last_on);
  242. $this->assertEquals(3, $user->photos_count);
  243. $this->assertEquals(1, $user->photo_id);
  244. $this->checkMembershipWeight($user, 0);
  245. $this->assertEquals('sr', $user->voc);
  246.  
  247. }
  248.  
  249. /**
  250. * load user
  251. *
  252. * @return void
  253. */
  254. public function testLoadUser()
  255. {
  256. $this->addUser();
  257. $user = new MUser(['username' => $this->udata['username']], C::Db()->SITE_DEFAULT);
  258. $this->checkUser($user);
  259.  
  260. $user = new MUser(['username' => $this->udata['username'], 'email' => $this->udata['email']], C::Db()->SITE_DEFAULT);
  261. $this->checkUser($user);
  262. }
  263.  
  264. /**
  265. * test free premium
  266. *
  267. * @return void
  268. */
  269. public function testWithFreePremium()
  270. {
  271. // with free premium
  272. $result = App::get()->db->query(
  273. 'update site_gender_age set free_premium = 1 where site_id = 22 and gender_id =1', null, C::Db()->DATING
  274. );
  275.  
  276. $this->_app->auth->logout();
  277.  
  278. $u = $this->addUser();
  279. $user_free = $this->_app->db->getRow(
  280. 'SELECT * FROM user_free_premium WHERE user_id = :id', ['id' => $u->id], C::Db()->SITE_DEFAULT, 0);
  281. $this->assertTrue(!empty($user_free));
  282. $this->assertTrue($user_free['reason'] == 'gender_free_premium');
  283. $this->assertTrue($user_free['application'] == 'www');
  284.  
  285.  
  286. $this->_app->auth->login($u->id);
  287. $this->checkMembershipWeight($this->_app->auth->user, 101);
  288. $user = $this->_app->auth->user;
  289.  
  290. $free_date = $user->getPerm()->getFreePremium();
  291. $this->assertTrue(!empty($free_date));
  292. $this->checkMembershipWeight($user, 101);
  293.  
  294.  
  295. // remove free premium
  296. $user->getPerm()->setFreePremium();
  297. $user->save();
  298.  
  299. $this->checkMembershipWeight($user, 0);
  300. $user_free = $this->_app->db->getRow(
  301. 'SELECT * FROM user_free_premium WHERE user_id = :id', ['id' => $u->id], C::Db()->SITE_DEFAULT, 0);
  302. $this->assertTrue(empty($user_free));
  303.  
  304. $free_date = $user->getPerm()->getFreePremium();
  305. $this->assertTrue(empty($free_date));
  306.  
  307. // add free premium
  308. $user->getPerm()->setFreePremium(date('Y-m-d H:i:s', strtotime('+ 5 day')));
  309. $user->save();
  310. $this->checkMembershipWeight($user, 101);
  311.  
  312. $user_free = $this->_app->db->getRow(
  313. 'SELECT * FROM user_free_premium WHERE user_id = :id', ['id' => $u->id], C::Db()->SITE_DEFAULT, 0);
  314. $this->assertTrue(!empty($user_free));
  315.  
  316. $free_date = $user->getPerm()->getFreePremium();
  317. $this->assertTrue(!empty($free_date));
  318. $this->checkMembershipWeight($user, 101);
  319.  
  320. // remove free premium
  321. $result = App::get()->db->query(
  322. 'update site_gender_age set free_premium = 0 where site_id = 22', null, C::Db()->DATING
  323. );
  324. }
  325.  
  326. /**
  327. * test new user
  328. *
  329. * @return void
  330. */
  331. public function testChangeRole()
  332. {
  333. $this->_app->auth->login($this->addUser());
  334. $user = $this->_app->auth->user;
  335. $this->assertTrue($user instanceof MUser);
  336. // default role
  337. $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
  338. $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
  339. $this->assertFalse($user->getPerm()->check('WWW_PREMIUM'));
  340. $this->assertFalse($user->getPerm()->check('WWW_PAID'));
  341.  
  342.  
  343. $user->save();
  344. $this->checkMembershipWeight($user, 0);
  345. $user->getPerm()->changeMembership(Roles::PAYING, 1, 'test');
  346. $this->checkMembershipChangeLog($user, Roles::PAYING);
  347.  
  348. // still basic?
  349. $this->assertFalse($user->getPerm()->check('WWW_BASIC'));
  350. $this->assertFalse($user->getPerm()->check('WWW_SHOW_UPGRADE'));
  351. // is paying
  352. $this->assertTrue($user->getPerm()->check('WWW_PAID'));
  353. $user->save();
  354. $this->checkMembershipWeight($user, 50);
  355. $this->checkMembershipChangeLog($user, Roles::PAYING);
  356.  
  357. // developer
  358. $user->getPerm()->changeMembership(Roles::DEVELOPER);
  359. $user->save();
  360.  
  361. $this->assertTrue($user->getPerm()->check('WWW_DEVELOPER'));
  362. // and paying memeber
  363. $this->assertTrue($user->getPerm()->check('WWW_PAID'));
  364. $user->save();
  365. $this->checkMembershipWeight($user, 50);
  366. $this->checkMembershipChangeLog($user, Roles::PAYING);
  367.  
  368. // basic
  369. $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test');
  370. $user->save();
  371. $this->checkMembershipChangeLog($user, Roles::BASIC);
  372. $this->checkMembershipWeight($user, 0);
  373. $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
  374. $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
  375. $this->assertFalse($user->getPerm()->check('WWW_PAID'));
  376. // must be developer
  377. $this->assertTrue($user->getPerm()->check('WWW_DEVELOPER'));
  378. $user->getPerm()->setFreePremium('2020-01-01 00:00:00');
  379. $this->checkMembershipWeight($user, 101);
  380.  
  381. $user->getPerm()->setFreePremium('2030-01-01 00:00:00');
  382. $this->checkMembershipWeight($user, 101);
  383. $user->getPerm()->setFreePremium('2020-01-01 00:00:00');
  384. $this->checkMembershipWeight($user, 101);
  385.  
  386. $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test');
  387. $user->save();
  388. $this->checkMembershipChangeLog($user, Roles::BASIC);
  389.  
  390. $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test1');
  391. $user->save();
  392. $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test2');
  393. $user->save();
  394. $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test3');
  395. $user->save();
  396. $user->getPerm()->changeMembership(Roles::BASIC, 1, 'test4');
  397. $user->save();
  398. $membership_change = $this->_app->db->getAllForced(
  399. 'select * from user_membership_change where user_id=:user_id',
  400. [ 'user_id' => $user->id], C::Db()->SITE_DEFAULT);
  401.  
  402. $this->assertNotEmpty($membership_change);
  403. $this->assertEquals(2, count($membership_change));
  404. }
  405.  
  406. /**
  407. * test gender switch
  408. *
  409. * @return void
  410. */
  411. public function testGender()
  412. {
  413. $user = new MUser($this->addUser());
  414. $user->getProfile()->gender = ProfileOptions::GENDER_BOY_TOY;
  415. $user->getProfile()->seeking_for = ProfileOptions::SEEKING_FOR_CUB_MALE;
  416. $user->save();
  417.  
  418. $u = new MUser($user->id);
  419. $this->assertEquals(ProfileOptions::GENDER_MAN, $u->getProfile()->gender);
  420. $this->assertEquals(ProfileOptions::SEEKING_FOR_WOMAN, $u->getProfile()->seeking_for);
  421. }
  422.  
  423. /**
  424. * test new user
  425. *
  426. * @return void
  427. */
  428. public function testWipe()
  429. {
  430. $this->_app->auth->login($this->addUser());
  431. $user = $this->_app->auth->user;
  432.  
  433. $user->wipe();
  434. $user->save();
  435. $this->assertEquals('wiped', $user->status);
  436. $this->assertRegExp('/wiped/', $user->username);
  437. $this->assertRegExp('/wiped/', $user->login);
  438. $this->assertNotEquals($this->udata['email'], $user->email);
  439. }
  440.  
  441. /**
  442. * test isDefinitionRejected method
  443. *
  444. * @throws EDb
  445. * @return void
  446. */
  447. public function testIsDefinitionRejected()
  448. {
  449. $this->_app->db->query('DELETE FROM filters_found;', array(), C::Db()->SITE_DEFAULT);
  450. $user = $this->addUser();
  451.  
  452. $this->assertFalse($user->getProfile()->isHeadlineRejected());
  453. $this->assertFalse($user->getProfile()->isDescriptionRejected());
  454.  
  455. $this->_app->db->insert(
  456. 'filters_found',
  457. [
  458. 'user_id' => $user->id,
  459. 'filter_id' => 2,
  460. 'info_id' => ProfileInfo::HEADLINE,
  461. 'definition' => 'some test headline',
  462. 'status' => 'rejected',
  463. ], C::Db()->SITE_DEFAULT
  464. );
  465. $this->assertTrue($user->getProfile()->isHeadlineRejected());
  466.  
  467. $this->_app->db->insert(
  468. 'filters_found',
  469. [
  470. 'user_id' => $user->id,
  471. 'filter_id' => 2,
  472. 'info_id' => ProfileInfo::SELF_DESCRIPTION,
  473. 'definition' => 'some test headline',
  474. 'status' => 'rejected',
  475. ], C::Db()->SITE_DEFAULT
  476. );
  477. $this->assertTrue($user->getProfile()->isDescriptionRejected());
  478. }
  479.  
  480. /**
  481. * test status
  482. *
  483. * @return void
  484. */
  485. public function testStatus()
  486. {
  487. // all missing
  488. $user = new MUser();
  489. $user->login = $this->udata['login'];
  490. $user->username = $this->udata['username'];
  491. $user->email = $this->udata['email'];
  492. $user->password = $this->udata['password'];
  493. $user->birthday = $this->udata['birthday'];
  494. $user->site_id = $this->udata['site_id'];
  495. $user->last_on = $this->udata['last_on'];
  496. $user->save();
  497. $this->assertEquals('new', $user->getStatus());
  498.  
  499. // headline & descr. missing
  500. $user = new MUser();
  501. $user->login = $this->udata['login'] . '2';
  502. $user->username = $this->udata['username'] . '2';
  503. $user->email = '2' . $this->udata['email'];
  504. $user->password = $this->udata['password'];
  505. $user->birthday = $this->udata['birthday'];
  506. $user->site_id = $this->udata['site_id'];
  507. $user->last_on = $this->udata['last_on'];
  508.  
  509. $user->getProfile()->gender = $this->udata['gender'];
  510. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  511.  
  512. $user->getGeoData()->country = $this->udata['country'];
  513. $user->getGeoData()->city_id = $this->udata['city_id'];
  514. $user->getGeoData()->zip = $this->udata['zip'];
  515. $user->setJoinPage($this->udata['join_page']);
  516.  
  517. $user->save();
  518. $this->assertEquals('new', $user->getStatus());
  519.  
  520. // gender /seeking missing
  521. $user = new MUser();
  522. $user->login = $this->udata['login'] . '3';
  523. $user->username = $this->udata['username'] . '3';
  524. $user->email = '3' . $this->udata['email'];
  525. $user->password = $this->udata['password'];
  526. $user->birthday = $this->udata['birthday'];
  527. $user->site_id = $this->udata['site_id'];
  528. $user->last_on = $this->udata['last_on'];
  529.  
  530. $user->getProfile()->headline = $this->udata['headline'];
  531. $user->getProfile()->self_description = $this->udata['self_description'];
  532.  
  533. $user->getGeoData()->country = $this->udata['country'];
  534. $user->getGeoData()->city_id = $this->udata['city_id'];
  535. $user->getGeoData()->zip = $this->udata['zip'];
  536. $user->setJoinPage($this->udata['join_page']);
  537.  
  538. $user->save();
  539. $this->assertEquals('new', $user->getStatus());
  540.  
  541. $user = new MUser();
  542. $user->login = $this->udata['login'] . '4';
  543. $user->username = $this->udata['username'] . '4';
  544. $user->email = '4' . $this->udata['email'];
  545. $user->password = $this->udata['password'];
  546. $user->birthday = $this->udata['birthday'];
  547. $user->site_id = $this->udata['site_id'];
  548. $user->last_on = $this->udata['last_on'];
  549.  
  550. $user->getProfile()->gender = $this->udata['gender'];
  551. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  552. $user->getProfile()->headline = $this->udata['headline'];
  553. $user->getProfile()->self_description = $this->udata['self_description'];
  554. $user->getGeoData()->country = $this->udata['country'];
  555. $user->getGeoData()->city_id = $this->udata['city_id'];
  556. $user->getGeoData()->zip = $this->udata['zip'];
  557. $user->setJoinPage($this->udata['join_page']);
  558.  
  559. $id = $user->save();
  560. $user = new MUser($id);
  561. $user->save();
  562. $this->assertEquals('approved', $user->getStatus());
  563.  
  564. }
  565.  
  566. /**
  567. * test user interaction filter
  568. *
  569. * @return void
  570. */
  571. public function testCanInteract()
  572. {
  573. $q = "DELETE FROM `users` WHERE `username` = :username or email = :email";
  574. $this->_app->db->query($q, array('username' => $this->udata['username'], 'email' => $this->udata['email']));
  575.  
  576. $user = new MUser();
  577. $user->login = $this->udata['login'];
  578. $user->username = $this->udata['username'];
  579. $user->email = $this->udata['email'];
  580. $user->password = $this->udata['password'];
  581. $user->birthday = $this->udata['birthday'];
  582. $user->site_id = $this->udata['site_id'];
  583. $user->last_on = $this->udata['last_on'];
  584. $user->getProfile()->headline = $this->udata['headline'];
  585. $user->getProfile()->self_description = $this->udata['self_description'];
  586. $user->getProfile()->want_to_be_millionaire = 1;
  587. $user->getProfile()->gender = $this->udata['gender'];
  588. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  589.  
  590. $user->getGeoData()->country = $this->udata['country'];
  591. $user->getGeoData()->city_id = $this->udata['city_id'];
  592. $user->getGeoData()->zip = $this->udata['zip'];
  593. $user->setJoinPage($this->udata['join_page']);
  594.  
  595. $id = $user->save();
  596.  
  597.  
  598. $user2 = new MUser();
  599. $user2->login = $this->udata['login'] . '1';
  600. $user2->username = $this->udata['username'] . '1';
  601. $user2->email = '1' . $this->udata['email'];
  602. $user2->password = $this->udata['password'];
  603. $user2->birthday = $this->udata['birthday'];
  604. $user2->site_id = $this->udata['site_id'];
  605. $user2->last_on = $this->udata['last_on'];
  606. $user2->getProfile()->headline = $this->udata['headline'];
  607. $user2->getProfile()->self_description = $this->udata['self_description'];
  608. $user2->getProfile()->want_to_be_millionaire = 1;
  609. $user2->getProfile()->gender = $this->udata['gender'];
  610. $user2->getProfile()->seeking_for = $this->udata['seeking_for'];
  611.  
  612. $user2->getGeoData()->country = $this->udata['country'];
  613. $user2->getGeoData()->city_id = $this->udata['city_id'];
  614. $user2->getGeoData()->zip = $this->udata['zip'];
  615. $user2->setJoinPage($this->udata['join_page']);
  616. $id2 = $user2->save();
  617.  
  618. $this->assertFalse($user->canInteract($user2));
  619. $user2->getProfile()->gender = 2;
  620. $user2->getProfile()->seeking_for = 3;
  621. $user2->save();
  622. $this->assertTrue($user->canInteract($user2));
  623. $user = new MUser($id);
  624. $user2 = new MUser($id2);
  625. $this->assertTrue($user->canInteract($user2));
  626. $user->getProfile()->gender = 2;
  627. $user->getProfile()->seeking_for = 3;
  628. $user->save();
  629. $this->assertFalse($user->canInteract($user2));
  630.  
  631. }
  632.  
  633. /**
  634. * test rebill
  635. *
  636. * @throws EApp
  637. *
  638. * @return void
  639. */
  640. public function testRebill()
  641. {
  642. $this->_app->auth->logout();
  643. $user = new MUser();
  644. $user->login = 'a' . $this->udata['login'];
  645. $user->username = 'a' . $this->udata['username'];
  646. $user->email = 'a' . $this->udata['email'];
  647. $user->password = $this->udata['password'];
  648. $user->birthday = $this->udata['birthday'];
  649. $user->site_id = $this->udata['site_id'];
  650. $user->last_on = $this->udata['last_on'];
  651. $user->getProfile()->headline = $this->udata['headline'];
  652. $user->getProfile()->self_description = $this->udata['self_description'];
  653. $user->getProfile()->want_to_be_millionaire = 1;
  654. $user->getProfile()->gender = $this->udata['gender'];
  655. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  656.  
  657. $user->getGeoData()->country = $this->udata['country'];
  658. $user->getGeoData()->city_id = $this->udata['city_id'];
  659. $user->getGeoData()->zip = $this->udata['zip'];
  660. $user->setJoinPage($this->udata['join_page']);
  661.  
  662. $id = $user->save();
  663.  
  664. // $this->checkMembershipChangeLog($user, Roles::BASIC);
  665.  
  666. $this->_app->auth->login($id);
  667. $this->checkMembershipWeight($user, 0);
  668. $this->assertTrue($user->getPerm()->check('WWW_BASIC'));
  669. $this->assertTrue($user->getPerm()->check('WWW_SHOW_UPGRADE'));
  670. $this->assertFalse($user->getPerm()->check('WWW_PAID'));
  671.  
  672. $this->assertTrue($this->_app->auth->user->getPerm()->check('WWW_BASIC'));
  673. $user->getPerm()->changeMembership(Roles::PAYING, 1, 'test');
  674.  
  675. $roles_list = $this->_app->db->getAllForced(
  676. 'select role_id as id from user_roles where user_id=:user_id',
  677. ['user_id' => $id], C::Db()->SITE_DEFAULT);
  678.  
  679. $this->assertTrue($user->getPerm()->check('WWW_PAID'));
  680.  
  681. $this->checkMembershipChangeLog($user, Roles::PAYING);
  682.  
  683. $u = $this->_app->auth->user;
  684. $this->assertTrue($u->getPerm()->check('WWW_PAID'));
  685.  
  686. $this->assertTrue($this->_app->auth->user->getPerm()->check('WWW_PAID'));
  687. $this->assertTrue($user->getPerm()->check('WWW_PAID'));
  688.  
  689. $u = $this->_app->auth->user;
  690. $u->getPerm()->changeMembership(Roles::BASIC, 1, 'test');
  691.  
  692. $this->checkMembershipChangeLog($user, Roles::BASIC);
  693. $this->assertTrue($this->_app->auth->user->getPerm()->check('WWW_BASIC'));
  694. $this->assertTrue($u->getPerm()->check('WWW_BASIC'));
  695. }
  696.  
  697. /**
  698. * test membership weight
  699. *
  700. * @param muser $user muser obj
  701. * @param int $weight membership weight
  702. *
  703. * @return void
  704. */
  705. protected function checkMembershipWeight($user, $weight)
  706. {
  707. $this->assertEquals($weight, $user->membership_weight);
  708. $membership_weight = $this->_app->db->getOne(
  709. 'SELECT membership_weight FROM users WHERE id = :id', ['id' => $user->id], C::Db()->SITE_DEFAULT, 0);
  710.  
  711. $this->assertEquals($weight, $membership_weight);
  712.  
  713. }
  714.  
  715. /**
  716. * test user token
  717. *
  718. * @return void
  719. */
  720. public function testTokens()
  721. {
  722. $user = new MUser();
  723. $user->login = $this->udata['login'];
  724. $user->username = $this->udata['username'];
  725. $user->email = $this->udata['email'];
  726. $user->password = $this->udata['password'];
  727. $user->birthday = $this->udata['birthday'];
  728. $user->site_id = $this->udata['site_id'];
  729.  
  730. $user->getGeoData()->country = 'US';
  731. $user->getGeoData()->city_id = 1;
  732. $user->getGeoData()->zip = '00501';
  733.  
  734. $user_id = $user->save();
  735. $token = $this->_app->db->getOne(
  736. 'select token from user_tokens where user_id = :user_id', ['user_id' => $user_id ], C::Db()->SITE_DEFAULT);
  737. $this->assertNotEmpty($token);
  738.  
  739. $this->assertEquals($user->getUserToken(), $token);
  740.  
  741. $this->assertEquals(md5($user->login . $user->id), $token);
  742.  
  743. $new_user = MUser::initByToken($token, new MSite(C::Env()->PURE_HOST));
  744. $this->assertEquals($new_user->id, $user->id);
  745.  
  746. // test missing token
  747. $this->_app->db->query(
  748. 'delete from user_tokens where user_id = :user', ['user' => $user_id], C::Db()->SITE_DEFAULT);
  749.  
  750. $this->assertEquals($user->getUserToken(), $token);
  751.  
  752. $token2 = $this->_app->db->getOneForced(
  753. 'select token from user_tokens where user_id = :user_id', ['user_id' => $user_id ], C::Db()->SITE_DEFAULT);
  754. $this->assertEquals($user->getUserToken(), $token2);
  755. }
  756.  
  757. /**
  758. * test invalid user token
  759. *
  760. * @expectedException EFrontUser
  761. * @return void
  762. */
  763. public function testInvalidTokens()
  764. {
  765. MUser::initByToken('mynewtoken', new MSite(C::Env()->PURE_HOST));
  766. }
  767.  
  768. /**
  769. * test invalid user
  770. *
  771. * @expectedException EFrontUser
  772. * @return void
  773. */
  774. public function testInvalidUsers()
  775. {
  776. $usr = new MUser(['username' => 'blablabla'], new MSite(C::Env()->PURE_HOST));
  777. }
  778.  
  779. /**
  780. * test has allowedProfileOptions
  781. *
  782. * @return void
  783. */
  784. public function testHasAllowedProfileOption()
  785. {
  786. $user = new MUser();
  787. $user->login = $this->udata['login'];
  788. $user->username = $this->udata['username'];
  789. $user->email = $this->udata['email'];
  790. $user->password = $this->udata['password'];
  791. $user->birthday = $this->udata['birthday'];
  792. $user->site_id = $this->udata['site_id'];
  793. $user->last_on = $this->udata['last_on'];
  794. $user->getProfile()->headline = $this->udata['headline'];
  795. $user->getProfile()->self_description = $this->udata['self_description'];
  796. $user->getProfile()->want_to_be_millionaire = 1;
  797. $user->getProfile()->gender = $this->udata['gender'];
  798. $user->getProfile()->seeking_for = $this->udata['seeking_for'];
  799.  
  800. $user->getGeoData()->country = $this->udata['country'];
  801. $user->getGeoData()->city_id = $this->udata['city_id'];
  802. $user->getGeoData()->zip = $this->udata['zip'];
  803. $user->setJoinPage($this->udata['join_page']);
  804.  
  805. $id = $user->save();
  806.  
  807. $user->getProfile()->religion = 402;
  808. $user->getProfile()->ethnicity = null;
  809. $user->save();
  810.  
  811. $this->assertTrue($user->hasAllowedProfileOption('religion'));
  812. $this->assertTrue($user->hasAllowedProfileOption('ethnicity'));
  813.  
  814. $user->getProfile()->religion = 1;
  815. $user->getProfile()->ethnicity = 2;
  816. $user->save();
  817.  
  818. $this->assertFalse($user->hasAllowedProfileOption('religion'));
  819. $this->assertFalse($user->hasAllowedProfileOption('ethnicity'));
  820.  
  821. }
  822. /**
  823. * tearDown Method
  824. *
  825. * @return void
  826. */
  827. protected function tearDown()
  828. {
  829. parent::tearDown();
  830. unset($this->udata);
  831. }
  832.  
  833. /**
  834. * @param muser $user muser object
  835. *
  836. * @return void
  837. */
  838. protected function resetMembershipChangeLog($user)
  839. {
  840. $this->_app->db->query(
  841. 'delete from user_membership_change where user_id=:user_id',
  842. [ 'user_id' => $user->id, ], C::Db()->SITE_DEFAULT);
  843. }
  844.  
  845. /**
  846. * @param muser $user muser object
  847. * @param int $role role id
  848. *
  849. * @return void
  850. */
  851. protected function checkMembershipChangeLog($user, $role)
  852. {
  853. $membership = $this->_app->db->getOneForced(
  854. 'select membership from user_membership_change where user_id=:user_id order by id desc',
  855. [ 'user_id' => $user->id, 'role' => $role ], C::Db()->SITE_DEFAULT);
  856.  
  857. $this->assertEquals($role, $membership);
  858. // $this->resetMembershipChangeLog($user);
  859. }
  860. }
Add Comment
Please, Sign In to add comment