permissionsServiceMock = $this->createMock(PermissionsService::class); $this->rolePrivilegeRetriever = $this->createMock(RolePrivilegeRetriever::class); $this->permissionsServiceFactory = $this->createMock(PermissionsServiceFactory::class); $this->eventMock = $this->createMock(ResourceMovedEvent::class); $this->resourceMock = $this->createMock(core_kernel_classes_Resource::class); $this->classMock = $this->createMock(core_kernel_classes_Class::class); $this->permissionsServiceFactory ->method('create') ->willReturn($this->permissionsServiceMock); $this->subject = new ResourceUpdateHandler(); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ RolePrivilegeRetriever::class => $this->rolePrivilegeRetriever, PermissionsServiceFactory::class => $this->permissionsServiceFactory ] ) ); } public function testCatchResourceUpdated() { $this->eventMock ->method('getMovedResource') ->willReturn($this->resourceMock); $this->resourceMock ->method('getUri') ->willReturn('resourceUri'); $this->eventMock ->method('getDestinationClass') ->willReturn($this->classMock); $this->classMock ->method('getUri') ->willReturn('classUri'); $this->rolePrivilegeRetriever ->expects($this->once()) ->method('retrieveByResourceIds') ->with( [ 'classUri', 'resourceUri' ] ) ->willReturn( [ 'http://www.tao.lu/Ontologies/TAO.rdf#BackOfficeRole' => [ 'GRANT', 'READ', 'WRITE' ], ] ); $this->permissionsServiceMock ->expects($this->once()) ->method('saveResourcePermissions') ->with( true, $this->resourceMock, [ 'http://www.tao.lu/Ontologies/TAO.rdf#BackOfficeRole' => [ 'GRANT', 'READ', 'WRITE' ], ] ); $this->subject->catchResourceUpdated($this->eventMock); } }