/** * @dataProvider provideProviderAllowsAuthenticationDataChange * @param string $type * @param bool|null $allow * @param StatusValue $expect */ public function testProviderAllowsAuthenticationDataChange($type, $allow, $expect) { $domains = $type instanceof PasswordDomainAuthenticationRequest ? ['foo', 'bar'] : []; $plugin = $this->getMock('AuthPlugin'); $plugin->expects($this->any())->method('domainList')->willReturn($domains); $plugin->expects($allow === null ? $this->never() : $this->once())->method('allowPasswordChange')->will($this->returnValue($allow)); $plugin->expects($this->any())->method('validDomain')->willReturnCallback(function ($d) use($domains) { return in_array($d, $domains, true); }); $provider = new AuthPluginPrimaryAuthenticationProvider($plugin); if (is_object($type)) { $req = $type; } else { $req = $this->getMock($type); } $req->action = AuthManager::ACTION_CHANGE; $req->username = '******'; $req->password = '******'; $req->retype = 'Pa$$w0Rd!!!'; $this->assertEquals($expect, $provider->providerAllowsAuthenticationDataChange($req)); }
/** * @dataProvider provideProviderAllowsAuthenticationDataChange * @param string $type * @param bool|null $allow * @param StatusValue $expect */ public function testProviderAllowsAuthenticationDataChange($type, $allow, $expect) { $plugin = $this->getMock('AuthPlugin'); $plugin->expects($this->any())->method('domainList')->willReturn([]); $plugin->expects($allow === null ? $this->never() : $this->once())->method('allowPasswordChange')->will($this->returnValue($allow)); $provider = new AuthPluginPrimaryAuthenticationProvider($plugin); if ($type === PasswordAuthenticationRequest::class) { $req = new $type(); } else { $req = $this->getMock($type); } $req->action = AuthManager::ACTION_CHANGE; $req->username = '******'; $req->password = '******'; $req->retype = 'Pa$$w0Rd!!!'; $this->assertEquals($expect, $provider->providerAllowsAuthenticationDataChange($req)); }