Exemplo n.º 1
0
 /**
  * Create unique key to view orders
  * @param int $size
  * @return string
  */
 public function createSecretKey($size = 10)
 {
     $result = '';
     $chars = '1234567890qweasdzxcrtyfghvbnuioplkjnm';
     while (mb_strlen($result, 'utf8') < $size) {
         $result .= mb_substr($chars, rand(0, mb_strlen($chars, 'utf8')), 1);
     }
     if (StoreWishlist::model()->countByAttributes(array('key' => $result)) > 0) {
         $this->createSecretKey($size);
     }
     return $result;
 }
 public function testWishlist()
 {
     Yii::import('application.modules.store.models.wishlist.*');
     $wishlist = StoreWishlist::model()->find();
     $product = StoreProduct::model()->active()->find();
     $this->assertTrue($product instanceof StoreProduct);
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->clickAndWait('xpath=//button[contains(.,"Список желаний")]');
     $this->assertTrue($this->isTextPresent('Авторизация'));
     $this->type('id=UserLoginForm_username', 'admin');
     $this->type('id=UserLoginForm_password', 'admin');
     // Click on login button
     $this->clickAndWait('css=input.blue_button');
     $this->open(Yii::app()->createUrl('/store/frontProduct/view', array('url' => $product->url)));
     $this->assertTrue($this->isTextPresent('Список желаний'));
     $this->clickAndWait('xpath=//button[contains(.,"Список желаний")]');
     $this->assertTrue($this->isTextPresent('Продукт успешно добавлен в список желаний.'));
     $this->assertTrue($this->isTextPresent(str_replace('  ', ' ', $product->name)));
     // View wishlist view
     $this->open(Yii::app()->createAbsoluteUrl('/store/wishlist/view', array('key' => $wishlist->key)));
     $this->assertTrue($this->isTextPresent('Список желаний'));
     $this->assertTrue($this->isTextPresent($product->name));
 }
Exemplo n.º 3
0
 /**
  * @param $key
  * @return CActiveRecord
  * @throws CException
  */
 public function loadByKey($key)
 {
     $model = StoreWishlist::model()->findByAttributes(array('key' => $key));
     if ($model === null) {
         throw new CException();
     }
     $this->_model = $model;
     $this->_user_id = $model->user_id;
     return $model;
 }