2021-08-04 04:37:11 +09:00
|
|
|
<?php
|
|
|
|
|
2021-10-10 17:26:18 +09:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2021-08-04 04:37:11 +09:00
|
|
|
// {{{ License
|
|
|
|
|
|
|
|
// This file is part of GNU social - https://www.gnu.org/software/social
|
|
|
|
//
|
|
|
|
// GNU social is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// GNU social is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
// }}}
|
|
|
|
|
2021-11-16 04:27:39 +09:00
|
|
|
namespace App\Tests\Controller;
|
2021-08-04 04:37:11 +09:00
|
|
|
|
|
|
|
use App\Core\DB\DB;
|
|
|
|
use App\Util\GNUsocialTestCase;
|
2021-08-05 05:11:01 +09:00
|
|
|
use Functional as F;
|
|
|
|
use Jchook\AssertThrows\AssertThrows;
|
2021-08-04 04:37:11 +09:00
|
|
|
|
|
|
|
class UserPanelTest extends GNUsocialTestCase
|
|
|
|
{
|
2021-08-05 05:11:01 +09:00
|
|
|
use AssertThrows;
|
|
|
|
|
|
|
|
/**
|
2022-02-11 01:02:51 +09:00
|
|
|
* @covers \App\Controller\PersonSettings::allSettings
|
|
|
|
* @covers \App\Controller\PersonSettings::personalInfo
|
2021-08-05 05:11:01 +09:00
|
|
|
*/
|
|
|
|
public function testPersonalInfo()
|
|
|
|
{
|
|
|
|
$client = static::createClient();
|
|
|
|
$user = DB::findOneBy('local_user', ['nickname' => 'form_personal_info_test_user']);
|
|
|
|
$client->loginUser($user);
|
|
|
|
|
|
|
|
$client->request('GET', '/settings');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
$crawler = $client->submitForm('Save personal info', [
|
2021-08-19 09:09:42 +09:00
|
|
|
'save_personal_info[nickname]' => 'form_test_user_new_nickname',
|
|
|
|
'save_personal_info[full_name]' => 'Form User',
|
|
|
|
'save_personal_info[homepage]' => 'https://gnu.org',
|
|
|
|
'save_personal_info[bio]' => 'I was born at a very young age',
|
|
|
|
'save_personal_info[location]' => 'right here',
|
|
|
|
'save_personal_info[self_tags]' => 'foo bar',
|
2021-08-05 05:11:01 +09:00
|
|
|
]);
|
|
|
|
$changed_user = DB::findOneBy('local_user', ['id' => $user->getId()]);
|
|
|
|
$actor = $changed_user->getActor();
|
|
|
|
static::assertSame($changed_user->getNickname(), 'form_test_user_new_nickname');
|
|
|
|
static::assertSame($actor->getNickname(), 'form_test_user_new_nickname');
|
|
|
|
static::assertSame($actor->getFullName(), 'Form User');
|
|
|
|
static::assertSame($actor->getHomepage(), 'https://gnu.org');
|
|
|
|
static::assertSame($actor->getBio(), 'I was born at a very young age');
|
|
|
|
static::assertSame($actor->getLocation(), 'right here');
|
|
|
|
$tags = F\map($actor->getSelfTags(), fn ($tag) => $tag->getTag());
|
|
|
|
sort($tags);
|
|
|
|
static::assertSame($tags, ['bar', 'foo']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-11 01:02:51 +09:00
|
|
|
* @covers \App\Controller\PersonSettings::account
|
|
|
|
* @covers \App\Controller\PersonSettings::allSettings
|
2021-08-05 05:11:01 +09:00
|
|
|
*/
|
|
|
|
public function testAccount()
|
|
|
|
{
|
|
|
|
$client = static::createClient();
|
|
|
|
$user = DB::findOneBy('local_user', ['nickname' => 'form_account_test_user']);
|
|
|
|
$client->loginUser($user);
|
|
|
|
|
|
|
|
$client->request('GET', '/settings');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
$crawler = $client->submitForm('Save account info', [
|
2021-08-19 09:09:42 +09:00
|
|
|
'save_account_info[outgoing_email]' => 'outgoing@provider',
|
|
|
|
'save_account_info[incoming_email]' => 'incoming@provider',
|
|
|
|
'save_account_info[old_password]' => 'some password',
|
|
|
|
'save_account_info[password][first]' => 'this is some test password',
|
|
|
|
'save_account_info[password][second]' => 'this is some test password',
|
|
|
|
'save_account_info[phone_number]' => '+351908555842', // from fakenumber.net
|
2021-08-05 05:11:01 +09:00
|
|
|
]);
|
|
|
|
|
|
|
|
$changed_user = DB::findOneBy('local_user', ['id' => $user->getId()]);
|
|
|
|
static::assertSame($changed_user->getOutgoingEmail(), 'outgoing@provider');
|
|
|
|
static::assertSame($changed_user->getIncomingEmail(), 'incoming@provider');
|
|
|
|
static::assertTrue($changed_user->checkPassword('this is some test password'));
|
|
|
|
static::assertSame($changed_user->getPhoneNumber()->getNationalNumber(), '908555842');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-11 01:02:51 +09:00
|
|
|
* @covers \App\Controller\PersonSettings::account
|
|
|
|
* @covers \App\Controller\PersonSettings::allSettings
|
2021-08-05 05:11:01 +09:00
|
|
|
*/
|
|
|
|
public function testAccountWrongPassword()
|
|
|
|
{
|
|
|
|
$client = static::createClient();
|
|
|
|
$user = DB::findOneBy('local_user', ['nickname' => 'form_account_test_user']);
|
|
|
|
$client->loginUser($user);
|
|
|
|
|
|
|
|
$client->request('GET', '/settings');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
$crawler = $client->submitForm('Save account info', [
|
2021-08-19 09:09:42 +09:00
|
|
|
'save_account_info[old_password]' => 'some wrong password',
|
|
|
|
'save_account_info[password][first]' => 'this is some test password',
|
|
|
|
'save_account_info[password][second]' => 'this is some test password',
|
2021-08-05 05:11:01 +09:00
|
|
|
]);
|
|
|
|
$this->assertResponseStatusCodeSame(500); // 401 in future
|
|
|
|
$this->assertSelectorTextContains('.stacktrace', 'AuthenticationException');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-02-11 01:02:51 +09:00
|
|
|
* @covers \App\Controller\PersonSettings::allSettings
|
|
|
|
* @covers \App\Controller\PersonSettings::notifications
|
2021-08-05 05:11:01 +09:00
|
|
|
*/
|
|
|
|
public function testNotifications()
|
|
|
|
{
|
|
|
|
$client = static::createClient();
|
|
|
|
$user = DB::findOneBy('local_user', ['nickname' => 'form_account_test_user']);
|
|
|
|
$client->loginUser($user);
|
|
|
|
|
|
|
|
$client->request('GET', '/settings');
|
|
|
|
$this->assertResponseIsSuccessful();
|
|
|
|
$crawler = $client->submitForm('Save notification settings for Email', [
|
2021-11-16 04:27:39 +09:00
|
|
|
'save_email[activity_by_subscribed]' => false,
|
|
|
|
'save_email[mention]' => true,
|
|
|
|
'save_email[reply]' => false,
|
|
|
|
'save_email[subscription]' => true,
|
|
|
|
'save_email[favorite]' => false,
|
|
|
|
'save_email[nudge]' => true,
|
|
|
|
'save_email[dm]' => false,
|
|
|
|
'save_email[enable_posting]' => true,
|
2021-08-05 05:11:01 +09:00
|
|
|
]);
|
|
|
|
$settings = DB::findOneBy('user_notification_prefs', ['user_id' => $user->getId(), 'transport' => 'email']);
|
2021-11-16 04:27:39 +09:00
|
|
|
static::assertSame($settings->getActivityBySubscribed(), false);
|
2021-08-05 05:11:01 +09:00
|
|
|
static::assertSame($settings->getMention(), true);
|
|
|
|
static::assertSame($settings->getReply(), false);
|
2021-11-16 04:27:39 +09:00
|
|
|
static::assertSame($settings->getSubscription(), true);
|
2021-08-05 05:11:01 +09:00
|
|
|
static::assertSame($settings->getFavorite(), false);
|
|
|
|
static::assertSame($settings->getNudge(), true);
|
|
|
|
static::assertSame($settings->getDm(), false);
|
|
|
|
static::assertSame($settings->getEnablePosting(), true);
|
|
|
|
}
|
2021-08-04 04:37:11 +09:00
|
|
|
}
|