77 */ 
88namespace  OCA \DAV \Tests \unit \Connector \Sabre ;
99
10+ use  OC \Accounts \Account ;
11+ use  OC \Accounts \AccountProperty ;
1012use  OC \User \User ;
1113use  OCA \DAV \Connector \Sabre \Directory ;
1214use  OCA \DAV \Connector \Sabre \Exception \InvalidPath ;
1315use  OCA \DAV \Connector \Sabre \File ;
1416use  OCA \DAV \Connector \Sabre \FilesPlugin ;
1517use  OCA \DAV \Connector \Sabre \Node ;
18+ use  OCP \Accounts \IAccountManager ;
1619use  OCP \Files \FileInfo ;
1720use  OCP \Files \IFilenameValidator ;
1821use  OCP \Files \InvalidPathException ;
@@ -43,6 +46,7 @@ class FilesPluginTest extends TestCase {
4346	private  IPreview MockObject $ previewManager
4447	private  IUserSession MockObject $ userSession
4548	private  IFilenameValidator MockObject $ filenameValidator
49+ 	private  IAccountManager MockObject $ accountManager
4650	private  FilesPlugin $ plugin
4751
4852	protected  function  setUp (): void  {
@@ -57,6 +61,7 @@ protected function setUp(): void {
5761		$ this previewManager  = $ this createMock (IPreview::class);
5862		$ this userSession  = $ this createMock (IUserSession::class);
5963		$ this filenameValidator  = $ this createMock (IFilenameValidator::class);
64+ 		$ this accountManager  = $ this createMock (IAccountManager::class);
6065
6166		$ this plugin  = new  FilesPlugin (
6267			$ this tree ,
@@ -65,6 +70,7 @@ protected function setUp(): void {
6570			$ this previewManager ,
6671			$ this userSession ,
6772			$ this filenameValidator ,
73+ 			$ this accountManager ,
6874		);
6975
7076		$ response$ this getMockBuilder (ResponseInterface::class)
@@ -154,13 +160,32 @@ public function testGetPropertiesForFile(): void {
154160			->method ('getDisplayName ' )
155161			->willReturn ('M. Foo ' );
156162
163+ 		$ owner$ this getMockBuilder (Account::class)
164+ 			->disableOriginalConstructor ()->getMock ();
165+ 		$ this accountManager ->expects ($ this once ())
166+ 			->method ('getAccount ' )
167+ 			->with ($ user
168+ 			->willReturn ($ owner
169+ 
157170		$ nodeexpects ($ this once ())
158171			->method ('getDirectDownload ' )
159172			->willReturn (['url '  => 'http://example.com/ ' ]);
160173		$ nodeexpects ($ this exactly (2 ))
161174			->method ('getOwner ' )
162175			->willReturn ($ user
163176
177+ 		$ displayNameProp$ this getMockBuilder (AccountProperty::class)
178+ 			->disableOriginalConstructor ()->getMock ();
179+ 		$ owner
180+ 			->expects ($ this once ())
181+ 			->method ('getProperty ' )
182+ 			->with (IAccountManager::PROPERTY_DISPLAYNAME )
183+ 			->willReturn ($ displayNameProp
184+ 		$ displayNameProp
185+ 			->expects ($ this once ())
186+ 			->method ('getScope ' )
187+ 			->willReturn (IAccountManager::SCOPE_PUBLISHED );
188+ 
164189		$ this plugin ->handleGetProperties (
165190			$ propFind
166191			$ node
@@ -179,6 +204,101 @@ public function testGetPropertiesForFile(): void {
179204		$ this assertEquals ([], $ propFindget404Properties ());
180205	}
181206
207+ 	public  function  testGetDisplayNamePropertyWhenNotPublished (): void  {
208+ 		/** @var File|\PHPUnit\Framework\MockObject\MockObject $node */ 
209+ 		$ node$ this createTestNode ('\OCA\DAV\Connector\Sabre\File ' );
210+ 
211+ 		$ propFindnew  PropFind (
212+ 			'/dummyPath ' ,
213+ 			[
214+ 				FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME ,
215+ 			],
216+ 			0 
217+ 		);
218+ 
219+ 		$ this userSession ->expects ($ this once ())
220+ 			->method ('getUser ' )
221+ 			->willReturn (null );
222+ 
223+ 		$ user$ this getMockBuilder (User::class)
224+ 			->disableOriginalConstructor ()->getMock ();
225+ 
226+ 		$ user
227+ 			->expects ($ this never ())
228+ 			->method ('getDisplayName ' );
229+ 
230+ 		$ owner$ this getMockBuilder (Account::class)
231+ 			->disableOriginalConstructor ()->getMock ();
232+ 		$ this accountManager ->expects ($ this once ())
233+ 			->method ('getAccount ' )
234+ 			->with ($ user
235+ 			->willReturn ($ owner
236+ 
237+ 		$ nodeexpects ($ this once ())
238+ 			->method ('getOwner ' )
239+ 			->willReturn ($ user
240+ 
241+ 		$ displayNameProp$ this getMockBuilder (AccountProperty::class)
242+ 			->disableOriginalConstructor ()->getMock ();
243+ 		$ owner
244+ 			->expects ($ this once ())
245+ 			->method ('getProperty ' )
246+ 			->with (IAccountManager::PROPERTY_DISPLAYNAME )
247+ 			->willReturn ($ displayNameProp
248+ 		$ displayNameProp
249+ 			->expects ($ this once ())
250+ 			->method ('getScope ' )
251+ 			->willReturn (IAccountManager::SCOPE_PRIVATE );
252+ 
253+ 		$ this plugin ->handleGetProperties (
254+ 			$ propFind
255+ 			$ node
256+ 		);
257+ 
258+ 		$ this assertEquals (null , $ propFindget (FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME ));
259+ 	}
260+ 	
261+ 	public  function  testGetDisplayNamePropertyWhenNotPublishedButLoggedIn (): void  {
262+ 		/** @var File|\PHPUnit\Framework\MockObject\MockObject $node */ 
263+ 		$ node$ this createTestNode ('\OCA\DAV\Connector\Sabre\File ' );
264+ 
265+ 		$ propFindnew  PropFind (
266+ 			'/dummyPath ' ,
267+ 			[
268+ 				FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME ,
269+ 			],
270+ 			0 
271+ 		);
272+ 
273+ 		$ user$ this getMockBuilder (User::class)
274+ 			->disableOriginalConstructor ()->getMock ();
275+ 
276+ 		$ nodeexpects ($ this once ())
277+ 			->method ('getOwner ' )
278+ 			->willReturn ($ user
279+ 
280+ 		$ loggedInUser$ this getMockBuilder (User::class)
281+ 			->disableOriginalConstructor ()->getMock ();
282+ 		$ this userSession ->expects ($ this once ())
283+ 			->method ('getUser ' )
284+ 			->willReturn ($ loggedInUser
285+ 
286+ 		$ user
287+ 			->expects ($ this once ())
288+ 			->method ('getDisplayName ' )
289+ 			->willReturn ('M. Foo ' );
290+ 
291+ 		$ this accountManager ->expects ($ this never ())
292+ 			->method ('getAccount ' );
293+ 
294+ 		$ this plugin ->handleGetProperties (
295+ 			$ propFind
296+ 			$ node
297+ 		);
298+ 
299+ 		$ this assertEquals ('M. Foo ' , $ propFindget (FilesPlugin::OWNER_DISPLAY_NAME_PROPERTYNAME ));
300+ 	}
301+ 
182302	public  function  testGetPropertiesStorageNotAvailable (): void  {
183303		/** @var File|\PHPUnit\Framework\MockObject\MockObject $node */ 
184304		$ node$ this createTestNode ('\OCA\DAV\Connector\Sabre\File ' );
@@ -215,6 +335,7 @@ public function testGetPublicPermissions(): void {
215335			$ this previewManager ,
216336			$ this userSession ,
217337			$ this filenameValidator ,
338+ 			$ this accountManager ,
218339			true ,
219340		);
220341		$ this plugin ->initialize ($ this server );
0 commit comments