PersonSettingsTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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;
  21. use App\Core\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. public function testPersonalInfo()
  29. {
  30. $client = static::createClient();
  31. $user = DB::findOneBy(LocalUser::class, ['nickname' => 'form_personal_info_test_user']);
  32. $client->loginUser($user);
  33. $client->request('GET', Router::url('person_actor_settings', ['id' => $user->getId()]));
  34. $this->assertResponseIsSuccessful();
  35. $crawler = $client->submitForm('Save personal info', [
  36. 'save_personal_info[nickname]' => 'form_test_user_new_nickname',
  37. 'save_personal_info[full_name]' => 'Form User',
  38. 'save_personal_info[homepage]' => 'https://gnu.org',
  39. 'save_personal_info[bio]' => 'I was born at a very young age',
  40. 'save_personal_info[location]' => 'right here',
  41. // 'save_personal_info[phone_number]' => '+351908555842', // from fakenumber.net
  42. ]);
  43. $changed_user = DB::findOneBy(LocalUser::class, ['id' => $user->getId()]);
  44. $actor = $changed_user->getActor();
  45. static::assertSame('form_test_user_new_nickname', $changed_user->getNickname());
  46. static::assertSame('form_test_user_new_nickname', $actor->getNickname());
  47. static::assertSame('Form User', $actor->getFullName());
  48. static::assertSame('https://gnu.org', $actor->getHomepage());
  49. static::assertSame('I was born at a very young age', $actor->getBio());
  50. static::assertSame('right here', $actor->getLocation());
  51. // static::assertSame('908555842', $changed_user->getPhoneNumber()->getNationalNumber());
  52. }
  53. public function testEmail()
  54. {
  55. $client = static::createClient();
  56. $user = DB::findOneBy(LocalUser::class, ['nickname' => 'form_account_test_user']);
  57. $client->loginUser($user);
  58. $client->request('GET', Router::url('person_actor_settings', ['id' => $user->getId()]));
  59. $this->assertResponseIsSuccessful();
  60. $crawler = $client->submitForm('Save email info', [
  61. 'save_email[outgoing_email_sanitized]' => 'outgoing@provider.any',
  62. 'save_email[incoming_email_sanitized]' => 'incoming@provider.any',
  63. ]);
  64. $changed_user = DB::findOneBy(LocalUser::class, ['id' => $user->getId()]);
  65. static::assertSame($changed_user->getOutgoingEmail(), 'outgoing@provider.any');
  66. static::assertSame($changed_user->getIncomingEmail(), 'incoming@provider.any');
  67. }
  68. public function testCorrectPassword()
  69. {
  70. $client = static::createClient();
  71. $user = DB::findOneBy(LocalUser::class, ['nickname' => 'form_account_test_user']);
  72. $client->loginUser($user);
  73. $client->request('GET', Router::url('person_actor_settings', ['id' => $user->getId()]));
  74. $this->assertResponseIsSuccessful();
  75. $crawler = $client->submitForm('Save new password', [
  76. 'save_password[old_password]' => 'foobar',
  77. 'save_password[password][first]' => 'this is some test password',
  78. 'save_password[password][second]' => 'this is some test password',
  79. ]);
  80. $changed_user = DB::findOneBy(LocalUser::class, ['id' => $user->getId()]);
  81. static::assertTrue($changed_user->checkPassword('this is some test password'));
  82. }
  83. public function testAccountWrongPassword()
  84. {
  85. $client = static::createClient();
  86. $user = DB::findOneBy(LocalUser::class, ['nickname' => 'form_account_test_user']);
  87. $client->loginUser($user);
  88. $client->request('GET', Router::url('person_actor_settings', ['id' => $user->getId()]));
  89. $this->assertResponseIsSuccessful();
  90. $crawler = $client->submitForm('Save new password', [
  91. 'save_password[old_password]' => 'some wrong password',
  92. 'save_password[password][first]' => 'this is some test password',
  93. 'save_password[password][second]' => 'this is some test password',
  94. ]);
  95. $this->assertResponseStatusCodeSame(500); // 401 in future
  96. $this->assertSelectorTextContains('.stacktrace', 'AuthenticationException');
  97. }
  98. // TODO: First actually implement this functionality
  99. // public function testNotifications()
  100. // {
  101. // $client = static::createClient();
  102. // $user = DB::findOneBy(LocalUser::class, ['nickname' => 'form_account_test_user']);
  103. // $client->loginUser($user);
  104. //
  105. // $client->request('GET', Router::url('person_actor_settings', ['id' => $user->getId()]));
  106. // $this->assertResponseIsSuccessful();
  107. // $crawler = $client->submitForm('Save notification settings for Email', [
  108. // 'save_email[activity_by_subscribed]' => false,
  109. // 'save_email[mention]' => true,
  110. // 'save_email[reply]' => false,
  111. // 'save_email[subscription]' => true,
  112. // 'save_email[favorite]' => false,
  113. // 'save_email[nudge]' => true,
  114. // 'save_email[dm]' => false,
  115. // 'save_email[enable_posting]' => true,
  116. // ]);
  117. // $settings = DB::findOneBy('user_notification_prefs', ['user_id' => $user->getId(), 'transport' => 'email']);
  118. // static::assertSame($settings->getActivityBySubscribed(), false);
  119. // static::assertSame($settings->getMention(), true);
  120. // static::assertSame($settings->getReply(), false);
  121. // static::assertSame($settings->getSubscription(), true);
  122. // static::assertSame($settings->getFavorite(), false);
  123. // static::assertSame($settings->getNudge(), true);
  124. // static::assertSame($settings->getDm(), false);
  125. // static::assertSame($settings->getEnablePosting(), true);
  126. // }
  127. }