3434use OCP \IUserManager ;
3535use OCP \UserMigration \IExportDestination ;
3636use OCP \UserMigration \IImportSource ;
37+ use PHPUnit \Framework \Constraint \JsonMatches ;
3738use PHPUnit \Framework \MockObject \MockObject ;
3839use Sabre \VObject \UUIDUtil ;
3940use Symfony \Component \Console \Output \OutputInterface ;
@@ -65,6 +66,8 @@ class AccountMigratorTest extends TestCase {
6566
6667 private const REGEX_AVATAR_FILE = '/^ ' . Application::APP_ID . '\/ ' . 'avatar\.(jpg|png) ' . '$/ ' ;
6768
69+ private const REGEX_CONFIG_FILE = '/^ ' . Application::APP_ID . '\/ ' . '[a-z]+\.json ' . '$/ ' ;
70+
6871 protected function setUp (): void {
6972 $ app = new App (Application::APP_ID );
7073 $ container = $ app ->getContainer ();
@@ -81,30 +84,33 @@ protected function setUp(): void {
8184 public function dataImportExportAccount (): array {
8285 return array_map (
8386 function (string $ filename ) {
84- $ dataPath = self ::ASSETS_DIR . $ filename ;
85- // For each json file there is an avatar image with the same basename
86- $ avatarBasename = pathinfo ($ filename , PATHINFO_FILENAME );
87- $ avatarPath = self ::ASSETS_DIR . (file_exists (self ::ASSETS_DIR . "$ avatarBasename.jpg " ) ? "$ avatarBasename.jpg " : "$ avatarBasename.png " );
87+ $ dataPath = static ::ASSETS_DIR . $ filename ;
88+ // For each account json file there is an avatar image and a config json file with the same basename
89+ $ basename = pathinfo ($ filename , PATHINFO_FILENAME );
90+ $ avatarPath = static ::ASSETS_DIR . (file_exists (static ::ASSETS_DIR . "$ basename.jpg " ) ? "$ basename.jpg " : "$ basename.png " );
91+ $ configPath = static ::ASSETS_DIR . "$ basename-config. " . pathinfo ($ filename , PATHINFO_EXTENSION );
8892 return [
8993 UUIDUtil::getUUID (),
9094 json_decode (file_get_contents ($ dataPath ), true , 512 , JSON_THROW_ON_ERROR ),
9195 $ avatarPath ,
96+ json_decode (file_get_contents ($ configPath ), true , 512 , JSON_THROW_ON_ERROR ),
9297 ];
9398 },
9499 array_filter (
95- scandir (self ::ASSETS_DIR ),
96- fn (string $ filename ) => pathinfo ($ filename , PATHINFO_EXTENSION ) === 'json ' ,
100+ scandir (static ::ASSETS_DIR ),
101+ fn (string $ filename ) => pathinfo ($ filename , PATHINFO_EXTENSION ) === 'json ' && mb_strpos ( pathinfo ( $ filename , PATHINFO_FILENAME ), ' config ' ) === false ,
97102 ),
98103 );
99104 }
100105
101106 /**
102107 * @dataProvider dataImportExportAccount
103108 */
104- public function testImportExportAccount (string $ userId , array $ importData , string $ avatarPath ): void {
109+ public function testImportExportAccount (string $ userId , array $ importData , string $ avatarPath, array $ importConfig ): void {
105110 $ user = $ this ->userManager ->createUser ($ userId , 'topsecretpassword ' );
106111 $ avatarExt = pathinfo ($ avatarPath , PATHINFO_EXTENSION );
107112 $ exportData = $ importData ;
113+ $ exportConfig = $ importConfig ;
108114 // Verification status of email will be set to in progress on import so we set the export data to reflect that
109115 $ exportData [IAccountManager::PROPERTY_EMAIL ]['verified ' ] = IAccountManager::VERIFICATION_IN_PROGRESS ;
110116
@@ -115,10 +121,16 @@ public function testImportExportAccount(string $userId, array $importData, strin
115121 ->willReturn (1 );
116122
117123 $ this ->importSource
118- ->expects ($ this ->once ( ))
124+ ->expects ($ this ->exactly ( 2 ))
119125 ->method ('getFileContents ' )
120- ->with ($ this ->matchesRegularExpression (self ::REGEX_ACCOUNT_FILE ))
121- ->willReturn (json_encode ($ importData ));
126+ ->withConsecutive (
127+ [$ this ->matchesRegularExpression (static ::REGEX_ACCOUNT_FILE )],
128+ [$ this ->matchesRegularExpression (static ::REGEX_CONFIG_FILE )],
129+ )
130+ ->willReturnOnConsecutiveCalls (
131+ json_encode ($ importData ),
132+ json_encode ($ importConfig ),
133+ );
122134
123135 $ this ->importSource
124136 ->expects ($ this ->once ())
@@ -129,7 +141,7 @@ public function testImportExportAccount(string $userId, array $importData, strin
129141 $ this ->importSource
130142 ->expects ($ this ->once ())
131143 ->method ('getFileAsStream ' )
132- ->with ($ this ->matchesRegularExpression (self ::REGEX_AVATAR_FILE ))
144+ ->with ($ this ->matchesRegularExpression (static ::REGEX_AVATAR_FILE ))
133145 ->willReturn (fopen ($ avatarPath , 'r ' ));
134146
135147 $ this ->migrator ->import ($ user , $ this ->importSource , $ this ->output );
@@ -150,14 +162,17 @@ public function testImportExportAccount(string $userId, array $importData, strin
150162 }
151163
152164 $ this ->exportDestination
153- ->expects ($ this ->once ( ))
165+ ->expects ($ this ->exactly ( 2 ))
154166 ->method ('addFileContents ' )
155- ->with ($ this ->matchesRegularExpression (self ::REGEX_ACCOUNT_FILE ), json_encode ($ exportData ));
167+ ->withConsecutive (
168+ [$ this ->matchesRegularExpression (static ::REGEX_ACCOUNT_FILE ), new JsonMatches (json_encode ($ exportData ))],
169+ [$ this ->matchesRegularExpression (static ::REGEX_CONFIG_FILE ), new JsonMatches (json_encode ($ exportConfig ))],
170+ );
156171
157172 $ this ->exportDestination
158173 ->expects ($ this ->once ())
159174 ->method ('addFileAsStream ' )
160- ->with ($ this ->matchesRegularExpression (self ::REGEX_AVATAR_FILE ), $ this ->isType ('resource ' ));
175+ ->with ($ this ->matchesRegularExpression (static ::REGEX_AVATAR_FILE ), $ this ->isType ('resource ' ));
161176
162177 $ this ->migrator ->export ($ user , $ this ->exportDestination , $ this ->output );
163178 }
0 commit comments