Example #1
0
 /**
  * Tests that new accounts can be created successfully.
  */
 public function testCreatingNewAccount()
 {
     /** @var NostoAccount $account */
     /** @var NostoAccountMetaData $meta */
     $meta = new NostoAccountMetaData();
     $account = NostoAccount::create($meta);
     $this->specify('account was created', function () use($account, $meta) {
         $this->assertInstanceOf('NostoAccount', $account);
         $this->assertEquals($meta->getPlatform() . '-' . $meta->getName(), $account->getName());
     });
     $this->specify('account has api token sso', function () use($account, $meta) {
         $token = $account->getApiToken('sso');
         $this->assertInstanceOf('NostoApiToken', $token);
         $this->assertEquals('sso', $token->getName());
         $this->assertNotEmpty($token->getValue());
     });
     $this->specify('account has api token products', function () use($account, $meta) {
         $token = $account->getApiToken('products');
         $this->assertInstanceOf('NostoApiToken', $token);
         $this->assertEquals('products', $token->getName());
         $this->assertNotEmpty($token->getValue());
     });
     $this->specify('account is connected to nosto', function () use($account, $meta) {
         $this->assertTrue($account->isConnectedToNosto());
     });
 }
 /**
  * Creates a new Nosto account for the current scope using the Nosto API.
  */
 public function createAccountAction()
 {
     $this->getResponse()->setHeader('Content-type', 'application/json', true);
     /** @var Nosto_Tagging_Helper_Account $accountHelper */
     $accountHelper = Mage::helper('nosto_tagging/account');
     $store = $this->getSelectedStore();
     if ($this->getRequest()->isPost() && $store !== null) {
         try {
             $email = $this->getRequest()->getPost('email');
             $details = $this->getRequest()->getPost('details');
             $meta = $accountHelper->getMetaData($store);
             if (Zend_Validate::is($email, 'EmailAddress')) {
                 $meta->getOwner()->setEmail($email);
             }
             if (!empty($details)) {
                 $meta->setDetails(json_decode($details));
             }
             $account = NostoAccount::create($meta);
             if ($accountHelper->save($account, $store)) {
                 $accountHelper->updateCurrencyExchangeRates($account, $store);
                 $responseBody = array('success' => true, 'redirect_url' => $accountHelper->getIframeUrl($store, $account, array('message_type' => NostoMessage::TYPE_SUCCESS, 'message_code' => NostoMessage::CODE_ACCOUNT_CREATE)));
             }
         } catch (NostoException $e) {
             Mage::log("\n" . $e->__toString(), Zend_Log::ERR, Nosto_Tagging_Model_Base::LOG_FILE_NAME);
         }
     }
     if (!isset($responseBody)) {
         $responseBody = array('success' => false, 'redirect_url' => $accountHelper->getIframeUrl($store, null, array('message_type' => NostoMessage::TYPE_ERROR, 'message_code' => NostoMessage::CODE_ACCOUNT_CREATE)));
     }
     $this->getResponse()->setBody(json_encode($responseBody));
 }