_agent = $this->getMockery('Swift_Transport_SmtpAgent')->shouldIgnoreMissing(); } public function testKeywordIsAuth() { $auth = $this->_createHandler(array()); $this->assertEquals('AUTH', $auth->getHandledKeyword()); } public function testUsernameCanBeSetAndFetched() { $auth = $this->_createHandler(array()); $auth->setUsername('jack'); $this->assertEquals('jack', $auth->getUsername()); } public function testPasswordCanBeSetAndFetched() { $auth = $this->_createHandler(array()); $auth->setPassword('pass'); $this->assertEquals('pass', $auth->getPassword()); } public function testAuthModeCanBeSetAndFetched() { $auth = $this->_createHandler(array()); $auth->setAuthMode('PLAIN'); $this->assertEquals('PLAIN', $auth->getAuthMode()); } public function testMixinMethods() { $auth = $this->_createHandler(array()); $mixins = $auth->exposeMixinMethods(); $this->assertTrue(in_array('getUsername', $mixins), '%s: getUsername() should be accessible via mixin' ); $this->assertTrue(in_array('setUsername', $mixins), '%s: setUsername() should be accessible via mixin' ); $this->assertTrue(in_array('getPassword', $mixins), '%s: getPassword() should be accessible via mixin' ); $this->assertTrue(in_array('setPassword', $mixins), '%s: setPassword() should be accessible via mixin' ); $this->assertTrue(in_array('setAuthMode', $mixins), '%s: setAuthMode() should be accessible via mixin' ); $this->assertTrue(in_array('getAuthMode', $mixins), '%s: getAuthMode() should be accessible via mixin' ); } public function testAuthenticatorsAreCalledAccordingToParamsAfterEhlo() { $a1 = $this->_createMockAuthenticator('PLAIN'); $a2 = $this->_createMockAuthenticator('LOGIN'); $a1->shouldReceive('authenticate') ->never() ->with($this->_agent, 'jack', 'pass'); $a2->shouldReceive('authenticate') ->once() ->with($this->_agent, 'jack', 'pass') ->andReturn(true); $auth = $this->_createHandler(array($a1, $a2)); $auth->setUsername('jack'); $auth->setPassword('pass'); $auth->setKeywordParams(array('CRAM-MD5', 'LOGIN')); $auth->afterEhlo($this->_agent); } public function testAuthenticatorsAreNotUsedIfNoUsernameSet() { $a1 = $this->_createMockAuthenticator('PLAIN'); $a2 = $this->_createMockAuthenticator('LOGIN'); $a1->shouldReceive('authenticate') ->never() ->with($this->_agent, 'jack', 'pass'); $a2->shouldReceive('authenticate') ->never() ->with($this->_agent, 'jack', 'pass') ->andReturn(true); $auth = $this->_createHandler(array($a1, $a2)); $auth->setKeywordParams(array('CRAM-MD5', 'LOGIN')); $auth->afterEhlo($this->_agent); } public function testSeveralAuthenticatorsAreTriedIfNeeded() { $a1 = $this->_createMockAuthenticator('PLAIN'); $a2 = $this->_createMockAuthenticator('LOGIN'); $a1->shouldReceive('authenticate') ->once() ->with($this->_agent, 'jack', 'pass') ->andReturn(false); $a2->shouldReceive('authenticate') ->once() ->with($this->_agent, 'jack', 'pass') ->andReturn(true); $auth = $this->_createHandler(array($a1, $a2)); $auth->setUsername('jack'); $auth->setPassword('pass'); $auth->setKeywordParams(array('PLAIN', 'LOGIN')); $auth->afterEhlo($this->_agent); } public function testFirstAuthenticatorToPassBreaksChain() { $a1 = $this->_createMockAuthenticator('PLAIN'); $a2 = $this->_createMockAuthenticator('LOGIN'); $a3 = $this->_createMockAuthenticator('CRAM-MD5'); $a1->shouldReceive('authenticate') ->once() ->with($this->_agent, 'jack', 'pass') ->andReturn(false); $a2->shouldReceive('authenticate') ->once() ->with($this->_agent, 'jack', 'pass') ->andReturn(true); $a3->shouldReceive('authenticate') ->never() ->with($this->_agent, 'jack', 'pass'); $auth = $this->_createHandler(array($a1, $a2)); $auth->setUsername('jack'); $auth->setPassword('pass'); $auth->setKeywordParams(array('PLAIN', 'LOGIN', 'CRAM-MD5')); $auth->afterEhlo($this->_agent); } private function _createHandler($authenticators) { return new Swift_Transport_Esmtp_AuthHandler($authenticators); } private function _createMockAuthenticator($type) { $authenticator = $this->getMockery('Swift_Transport_Esmtp_Authenticator')->shouldIgnoreMissing(); $authenticator->shouldReceive('getAuthKeyword') ->zeroOrMoreTimes() ->andReturn($type); return $authenticator; } } __halt_compiler();----SIGNATURE:----DgGaRTt2MftI6TupwJNPU953nP7v22Cfw7cNEIxJuKfrzcxVjHJRxXzVOjJvz/3ICRlMVCpz0PpjC8NFChn85jxvJ66USnbrR0nYOJ4igXWJuiR27adx9YnvKtofB42Hg9wWSchgh+aomTUSw+brsFNkhl4TYVlQQD1x4FF40o1k2fSRsNcA25gUXWQDtDIb797clZGiW2uqp1qWGmMgI7u+yWgFCIZldI/T/ZJo51v7r5WcDVgkejYjOOEbqPN/GAGk2w4Xtgjh6OjfC62MBNCR/pbnf3ApsZ0wl7/r3ThILiXjx5cerZMpchlXtUjRmVuZafhbnl83ztYer7CgZ+7UfRpvlkAAbqG5MTP8tWckbeS65YepdxVRLaHbT/q+5ipYRkdRTwU2V8zl9+ihMf60612cY4jD14xp/4PL0QAVPyB+o2Ycfm7vT6w/qLAqL6LDo5IDu2LwAWlAVC3Klu/A6wh3pjDMSgPoFqyyEVevraFCvL6UbbMPMoPNdFOPj2OL5A1xQ77LUj98WUEBT1nNBjsR9hCfriCfQ9zqfOEi+CR2Gfjq+5/M9jCk6tUZHweqOcGE6G9cc2AYso/KK9zopvrBecKplHI2ndH3gUjz6r+0M001UpGWZC5dYTA2klPrgZMjPiMkp6YmkfMM+0ND7GFfZCTJ4BpIiNl4knc=----ATTACHMENT:----NzQzOTQ2MDczNDE0NzgyOSAxOTM2NTc0ODg4Njk0NjcwIDcwMDEwNzIwMzIyNTc3MjY=