permissionHelperMock = $this->createMock(PermissionHelper::class); $this->modelMock = $this->createMock(Ontology::class); $this->resourceMock = $this->createMock(core_kernel_classes_Resource::class); $this->class = $this->createMock(core_kernel_classes_Class::class); $this->modelMock ->method('getResource') ->willReturn($this->resourceMock); $this->resourceMock ->method('getUri') ->willReturn('uri1'); $this->resourceMock ->method('getLabel') ->willReturn('label'); $this->modelMock ->method('getClass') ->willReturn($this->class); $this->resourceMock ->method('getTypes') ->willReturn([$this->class]); $this->class ->method('getParentClasses') ->willReturn( [ $this->class ] ); $this->subject = new ResultAccessChecker(); $this->subject->setServiceLocator( $this->getServiceLocatorMock( [ PermissionHelper::class => $this->permissionHelperMock ] ) ); $this->subject->setModel($this->modelMock); } public function testHasReadAccess() { $this->getSampleValues(); $this->permissionHelperMock ->method('filterByPermission') ->willReturn( [ 'uri1', ] ); $result = $this->subject->hasReadAccess($this->result, $this->permissionHelperMock); $this->assertTrue($result); } public function testHasNoReadAccess() { $this->getSampleValues(); $this->permissionHelperMock ->method('filterByPermission') ->willReturn([]); $result = $this->subject->hasReadAccess($this->result, $this->permissionHelperMock); $this->assertFalse($result); } private function getSampleValues(): array { return $this->result = [ [ 'id' => 'uri1', 'label' => 'label1' ] ]; } }