mirror of
https://github.com/expo/fbshipit.git
synced 2026-11-15 17:33:57 -10:00
Reviewed By: paulbiss, JoelMarcey Differential Revision: D3175108 fb-gh-sync-id: 11a790b1b8f2f210664b51e5540c53a153eda9fe fbshipit-source-id: 11a790b1b8f2f210664b51e5540c53a153eda9fe
145 lines
3.6 KiB
PHP
145 lines
3.6 KiB
PHP
<?hh
|
|
/**
|
|
* Copyright (c) 2016-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
namespace Facebook\ShipIt;
|
|
|
|
final class UserInfoTestImplementation extends ShipItUserInfo {
|
|
public static async function getDestinationAuthorFromLocalUser(
|
|
string $local_user,
|
|
): Awaitable<string> {
|
|
$user = await self::getDestinationUserFromLocalUser($local_user);
|
|
return 'Example User <'.$user.'@example.com>';
|
|
}
|
|
|
|
public static async function getDestinationUserFromLocalUser(
|
|
string $local_user,
|
|
): Awaitable<string> {
|
|
return $local_user.'-public';
|
|
}
|
|
}
|
|
|
|
final class UserFiltersTest extends BaseTest {
|
|
public function examplesForGetMentions(
|
|
): array<(string, ImmSet<string>)> {
|
|
return [
|
|
tuple(
|
|
'@foo',
|
|
ImmSet { '@foo' },
|
|
),
|
|
tuple(
|
|
'@foo @bar',
|
|
ImmSet { '@foo', '@bar' },
|
|
),
|
|
tuple(
|
|
'@foo [email protected]',
|
|
ImmSet { '@foo' },
|
|
),
|
|
tuple(
|
|
"\n@foo\n",
|
|
ImmSet { '@foo' },
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider examplesForGetMentions
|
|
*/
|
|
public function testGetMentions(
|
|
string $message,
|
|
ImmSet<string> $expected,
|
|
): void {
|
|
$changeset = (new ShipItChangeset())->withMessage($message);
|
|
$this->assertEquals(
|
|
$expected,
|
|
ShipItMentions::getMentions($changeset),
|
|
);
|
|
}
|
|
|
|
public function rewriteMentionsExamples(
|
|
): array<(string, (function(string):string), string)> {
|
|
return [
|
|
tuple(
|
|
'@foo @bar @baz',
|
|
$mention ==> $mention === '@foo' ? '@herp' : $mention,
|
|
'@herp @bar @baz',
|
|
),
|
|
tuple(
|
|
'@foo @bar @baz',
|
|
$mention ==> $mention === '@bar' ? '@herp' : $mention,
|
|
'@foo @herp @baz',
|
|
),
|
|
tuple(
|
|
'@foo @bar @baz',
|
|
$mention ==> $mention === '@bar' ? '' : $mention,
|
|
'@foo @baz',
|
|
),
|
|
tuple(
|
|
'@foo @bar @baz',
|
|
$mention ==> substr($mention, 1),
|
|
'foo bar baz',
|
|
),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider rewriteMentionsExamples
|
|
*/
|
|
public function testRewriteMentions(
|
|
string $message,
|
|
(function(string): string) $callback,
|
|
string $expected_message,
|
|
): void {
|
|
$changeset = (new ShipItChangeset())->withMessage($message);
|
|
$this->assertSame(
|
|
$expected_message,
|
|
ShipItMentions::rewriteMentions($changeset, $callback)->getMessage(),
|
|
);
|
|
}
|
|
|
|
public function testContainsMention(): void {
|
|
$changeset = (new ShipItChangeset())->withMessage('@foo @bar');
|
|
$this->assertTrue(
|
|
ShipItMentions::containsMention($changeset, '@foo')
|
|
);
|
|
$this->assertTrue(
|
|
ShipItMentions::containsMention($changeset, '@bar')
|
|
);
|
|
$this->assertFalse(
|
|
ShipItMentions::containsMention($changeset, '@baz')
|
|
);
|
|
}
|
|
|
|
public function examplesForSVNUserMapping(
|
|
): array<(string, string)> {
|
|
$fake_uuid = str_repeat('a', 36);
|
|
return [
|
|
tuple('Foo <[email protected]>', 'Foo <[email protected]>'),
|
|
tuple('foo@'.$fake_uuid, 'Example User <[email protected]>'),
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @dataProvider examplesForSVNUserMapping
|
|
*/
|
|
public function testSVNUserMapping(
|
|
string $in,
|
|
string $expected,
|
|
): void {
|
|
$changeset = (new ShipItChangeset())->withAuthor($in)
|
|
|> ShipItUserFilters::rewriteSVNAuthor(
|
|
$$,
|
|
UserInfoTestImplementation::class,
|
|
);
|
|
$this->assertSame(
|
|
$expected,
|
|
$changeset->getAuthor(),
|
|
);
|
|
}
|
|
}
|