createMock(Packages::class); /** @var CoreParametersHelper&MockObject $coreParametersHelper */ $coreParametersHelper = $this->createMock(CoreParametersHelper::class); $this->assetsHelperMock = new AssetsHelper($packagesMock, $coreParametersHelper); $this->pathsHelperMock = $this->createMock(PathsHelper::class); $this->pathsHelperMock->method('getSystemPath') ->willReturn('http://localhost'); $this->pathsHelperMock->method('getAssetsPath') ->willReturn($root.'/app/assets'); $this->pathsHelperMock->method('getMediaPath') ->willReturn($root.'/media'); $this->assetsHelperMock->setPathsHelper($this->pathsHelperMock); $this->defaultAvatarHelperMock = new DefaultAvatarHelper($this->assetsHelperMock); $this->gravatarHelperMock = new GravatarHelper($this->defaultAvatarHelperMock, $coreParametersHelper, $this->createMock(RequestStack::class)); $this->leadMock = $this->createMock(Lead::class); $this->avatarHelper = new AvatarHelper($this->assetsHelperMock, $this->pathsHelperMock, $this->gravatarHelperMock, $this->defaultAvatarHelperMock); } /** * Test to get gravatar. */ public function testGetAvatarWhenGravatar(): void { $_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.1'; $_SERVER['SERVER_PORT'] = '80'; $_SERVER['SERVER_NAME'] = 'localhost'; $_SERVER['REQUEST_URI'] = 'localhost'; $this->leadMock->method('getPreferredProfileImage') ->willReturn('gravatar'); $this->leadMock->method('getSocialCache') ->willReturn([]); $this->leadMock->method('getEmail') ->willReturn('mautic@acquia.com'); $avatar = $this->avatarHelper->getAvatar($this->leadMock); $this->assertSame('https://www.gravatar.com/avatar/96f1b78c73c1ee806cf6a4168fe9bf77?s=250&d=http%3A%2F%2Flocalhost%2Fimages%2Favatar.svg', $avatar, 'Gravatar image should be returned'); $_SERVER['SERVER_PROTOCOL'] = null; $_SERVER['SERVER_PORT'] = null; $_SERVER['SERVER_NAME'] = null; $_SERVER['REQUEST_URI'] = null; } /** * Test to get default image. */ public function testGetAvatarWhenDefault(): void { $this->leadMock->method('getPreferredProfileImage') ->willReturn('gravatar'); $this->leadMock->method('getSocialCache') ->willReturn([]); $this->leadMock->method('getEmail') ->willReturn(''); $avatar = $this->avatarHelper->getAvatar($this->leadMock); $this->assertSame('http://localhost/images/avatar.svg', $avatar, 'Default image image should be returned'); } }