public function testImapHostGetterAndSetter() { $origin = new UserEmailOrigin(); $this->assertNull($origin->getImapHost()); $origin->setImapHost('test'); $this->assertEquals('test', $origin->getImapHost()); }
/** * In case when user or host field was changed new configuration should be created * and old one will be not active */ public function testCreatingNewConfiguration() { $type = new ConfigurationType($this->encryptor, $this->securityFacade, $this->translator); $form = $this->factory->create($type); $entity = new UserEmailOrigin(); $entity->setImapHost('someHost'); $this->assertTrue($entity->isActive()); $form->setData($entity); $form->submit(array('imapHost' => 'someHost', 'imapPort' => '123', 'smtpHost' => '', 'smtpPort' => '', 'imapEncryption' => 'ssl', 'smtpEncryption' => 'ssl', 'user' => 'someUser', 'password' => 'somPassword')); $this->assertNotSame($entity, $form->getData()); $this->assertInstanceOf('Oro\\Bundle\\ImapBundle\\Entity\\UserEmailOrigin', $form->getData()); $this->assertTrue($form->getData()->isActive()); }
/** * @param string $type * @param string|null $accessToken * @param string $formParentName * * @return FormInterface */ public function getImapConnectionForm($type, $accessToken, $formParentName) { $oauthEmailOrigin = new UserEmailOrigin(); $oauthEmailOrigin->setAccessToken($accessToken); if ($type === AccountTypeModel::ACCOUNT_TYPE_GMAIL) { $oauthEmailOrigin->setImapHost(GmailImap::DEFAULT_GMAIL_HOST); $oauthEmailOrigin->setImapPort(GmailImap::DEFAULT_GMAIL_PORT); } $accountTypeModel = $this->createAccountModel($type, $oauthEmailOrigin); return $this->prepareForm($formParentName, $accountTypeModel); }
/** * Create object of AccountTypeModel using data of form * * @param array $data * * @return AccountTypeModel|null */ protected function createAccountTypeModelFromData($data) { $imapGmailConfiguration = isset($data['userEmailOrigin']) ? $data['userEmailOrigin'] : []; if (empty($imapGmailConfiguration['user'])) { return null; } $accountTypeModel = new AccountTypeModel(); $accountTypeModel->setAccountType($data['accountType']); $userEmailOrigin = new UserEmailOrigin(); $userEmailOrigin->setImapHost($imapGmailConfiguration['imapHost']); $userEmailOrigin->setImapPort($imapGmailConfiguration['imapPort']); $userEmailOrigin->setImapEncryption($imapGmailConfiguration['imapEncryption']); $userEmailOrigin->setUser($imapGmailConfiguration['user']); if (!empty($imapGmailConfiguration['accessTokenExpiresAt'])) { $newExpireDate = $imapGmailConfiguration['accessTokenExpiresAt']; if (!$newExpireDate instanceof \Datetime) { $utcTimeZone = new \DateTimeZone('UTC'); $accessTokenExpiresAt = $imapGmailConfiguration['accessTokenExpiresAt']; $newExpireDate = new \DateTime('+' . $accessTokenExpiresAt . ' seconds', $utcTimeZone); } $userEmailOrigin->setAccessTokenExpiresAt($newExpireDate); } $accountTypeModel->setUserEmailOrigin($userEmailOrigin); return $accountTypeModel; }
/** * In case when user or host field was changed new configuration should NOT be created if imap and smtp * are inactive. */ public function testNotCreatingNewConfigurationWhenImapInactive() { $type = new ConfigurationType($this->encryptor, $this->securityFacade, $this->translator); $form = $this->factory->create($type); $entity = new UserEmailOrigin(); $entity->setImapHost('someHost'); $this->assertTrue($entity->isActive()); $form->setData($entity); $form->submit(array('useImap' => 0, 'useSmtp' => 0, 'imapHost' => 'someHost', 'imapPort' => '123', 'smtpHost' => '', 'smtpPort' => '', 'imapEncryption' => 'ssl', 'smtpEncryption' => 'ssl', 'user' => 'someUser', 'password' => 'somPassword')); $this->assertNotSame($entity, $form->getData()); $this->assertNull($form->getData()); }