PersonSettingsTest.php 7.3 KB

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