UserPanelTest.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. // {{{ License
  3. // This file is part of GNU social - https://www.gnu.org/software/social
  4. //
  5. // GNU social is free software: you can redistribute it and/or modify
  6. // it under the terms of the GNU Affero General Public License as published by
  7. // the Free Software Foundation, either version 3 of the License, or
  8. // (at your option) any later version.
  9. //
  10. // GNU social is distributed in the hope that it will be useful,
  11. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. // GNU Affero General Public License for more details.
  14. //
  15. // You should have received a copy of the GNU Affero General Public License
  16. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  17. // }}}
  18. namespace App\Tests\Core;
  19. use App\Core\DB\DB;
  20. use App\Util\GNUsocialTestCase;
  21. use Functional as F;
  22. use Jchook\AssertThrows\AssertThrows;
  23. class UserPanelTest extends GNUsocialTestCase
  24. {
  25. use AssertThrows;
  26. /**
  27. * @covers \App\Controller\UserPanel::all_settings
  28. * @covers \App\Controller\UserPanel::personal_info
  29. */
  30. public function testPersonalInfo()
  31. {
  32. $client = static::createClient();
  33. $user = DB::findOneBy('local_user', ['nickname' => 'form_personal_info_test_user']);
  34. $client->loginUser($user);
  35. $client->request('GET', '/settings');
  36. $this->assertResponseIsSuccessful();
  37. $crawler = $client->submitForm('Save personal info', [
  38. 'save_personal_info[nickname]' => 'form_test_user_new_nickname',
  39. 'save_personal_info[full_name]' => 'Form User',
  40. 'save_personal_info[homepage]' => 'https://gnu.org',
  41. 'save_personal_info[bio]' => 'I was born at a very young age',
  42. 'save_personal_info[location]' => 'right here',
  43. 'save_personal_info[self_tags]' => 'foo bar',
  44. ]);
  45. $changed_user = DB::findOneBy('local_user', ['id' => $user->getId()]);
  46. $actor = $changed_user->getActor();
  47. static::assertSame($changed_user->getNickname(), 'form_test_user_new_nickname');
  48. static::assertSame($actor->getNickname(), 'form_test_user_new_nickname');
  49. static::assertSame($actor->getFullName(), 'Form User');
  50. static::assertSame($actor->getHomepage(), 'https://gnu.org');
  51. static::assertSame($actor->getBio(), 'I was born at a very young age');
  52. static::assertSame($actor->getLocation(), 'right here');
  53. $tags = F\map($actor->getSelfTags(), fn ($tag) => $tag->getTag());
  54. sort($tags);
  55. static::assertSame($tags, ['bar', 'foo']);
  56. }
  57. /**
  58. * @covers \App\Controller\UserPanel::account
  59. * @covers \App\Controller\UserPanel::all_settings
  60. */
  61. public function testAccount()
  62. {
  63. $client = static::createClient();
  64. $user = DB::findOneBy('local_user', ['nickname' => 'form_account_test_user']);
  65. $client->loginUser($user);
  66. $client->request('GET', '/settings');
  67. $this->assertResponseIsSuccessful();
  68. $crawler = $client->submitForm('Save account info', [
  69. 'save_account_info[outgoing_email]' => 'outgoing@provider',
  70. 'save_account_info[incoming_email]' => 'incoming@provider',
  71. 'save_account_info[old_password]' => 'some password',
  72. 'save_account_info[password][first]' => 'this is some test password',
  73. 'save_account_info[password][second]' => 'this is some test password',
  74. 'save_account_info[language]' => 'pt',
  75. 'save_account_info[phone_number]' => '+351908555842', // from fakenumber.net
  76. ]);
  77. $changed_user = DB::findOneBy('local_user', ['id' => $user->getId()]);
  78. static::assertSame($changed_user->getOutgoingEmail(), 'outgoing@provider');
  79. static::assertSame($changed_user->getIncomingEmail(), 'incoming@provider');
  80. static::assertTrue($changed_user->checkPassword('this is some test password'));
  81. static::assertSame($changed_user->getLanguage(), 'pt');
  82. static::assertSame($changed_user->getPhoneNumber()->getNationalNumber(), '908555842');
  83. }
  84. /**
  85. * @covers \App\Controller\UserPanel::account
  86. * @covers \App\Controller\UserPanel::all_settings
  87. */
  88. public function testAccountWrongPassword()
  89. {
  90. $client = static::createClient();
  91. $user = DB::findOneBy('local_user', ['nickname' => 'form_account_test_user']);
  92. $client->loginUser($user);
  93. $client->request('GET', '/settings');
  94. $this->assertResponseIsSuccessful();
  95. $crawler = $client->submitForm('Save account info', [
  96. 'save_account_info[old_password]' => 'some wrong password',
  97. 'save_account_info[password][first]' => 'this is some test password',
  98. 'save_account_info[password][second]' => 'this is some test password',
  99. ]);
  100. $this->assertResponseStatusCodeSame(500); // 401 in future
  101. $this->assertSelectorTextContains('.stacktrace', 'AuthenticationException');
  102. }
  103. /**
  104. * @covers \App\Controller\UserPanel::all_settings
  105. * @covers \App\Controller\UserPanel::notifications
  106. */
  107. public function testNotifications()
  108. {
  109. $client = static::createClient();
  110. $user = DB::findOneBy('local_user', ['nickname' => 'form_account_test_user']);
  111. $client->loginUser($user);
  112. $client->request('GET', '/settings');
  113. $this->assertResponseIsSuccessful();
  114. $crawler = $client->submitForm('Save notification settings for Email', [
  115. 'save_email[activity_by_followed]' => false,
  116. 'save_email[mention]' => true,
  117. 'save_email[reply]' => false,
  118. 'save_email[follow]' => true,
  119. 'save_email[favorite]' => false,
  120. 'save_email[nudge]' => true,
  121. 'save_email[dm]' => false,
  122. 'save_email[enable_posting]' => true,
  123. ]);
  124. $settings = DB::findOneBy('user_notification_prefs', ['user_id' => $user->getId(), 'transport' => 'email']);
  125. static::assertSame($settings->getActivityByFollowed(), false);
  126. static::assertSame($settings->getMention(), true);
  127. static::assertSame($settings->getReply(), false);
  128. static::assertSame($settings->getFollow(), true);
  129. static::assertSame($settings->getFavorite(), false);
  130. static::assertSame($settings->getNudge(), true);
  131. static::assertSame($settings->getDm(), false);
  132. static::assertSame($settings->getEnablePosting(), true);
  133. }
  134. }