public function testDelete() { $type = ProductRatingType::getNewInstance(Category::getRootNode()); $type->save(); $type2 = ProductRatingType::getNewInstance(Category::getRootNode()); $type2->save(); for ($k = 0; $k <= 1; $k++) { $review = ProductReview::getNewInstance($this->product, $this->user); $review->save(); $rating = ProductRating::getNewInstance($this->product, $type); $rating->rating->set(6 + $k); $rating->review->set($review); $rating->save(); $rating = ProductRating::getNewInstance($this->product, $type2); $rating->rating->set(4 + $k); $rating->review->set($review); $rating->save(); } $this->product->reload(); $this->assertEqual($this->product->ratingCount->get(), 4); $this->assertEqual($this->product->ratingSum->get(), 22); $this->assertEqual($this->product->rating->get(), 5.5); // delete last review $review->delete(); $this->product->reload(); $this->assertEqual($this->product->ratingCount->get(), 2); $this->assertEqual($this->product->ratingSum->get(), 10); $this->assertEqual($this->product->rating->get(), 5); // check rating summaries $summary = ProductRatingSummary::getInstance($this->product, $type2); $this->assertEqual($summary->rating->get(), 4); }
public function testRatingTypes() { $type = ProductRatingType::getNewInstance(Category::getRootNode()); $type->save(); $rating = ProductRating::getNewInstance($this->product, $type); $rating->rating->set(6); $rating->save(); $this->product->reload(); $this->assertEqual($this->product->ratingCount->get(), 1); $this->assertEqual($this->product->ratingSum->get(), 6); $this->assertEqual($this->product->rating->get(), 6); ActiveRecord::clearPool(); $summary = ProductRatingSummary::getInstance($this->product, $type); $summary->reload(); $this->assertEqual($summary->ratingCount->get(), 1); $this->assertEqual($summary->ratingSum->get(), 6); $this->assertEqual($summary->rating->get(), 6); $type2 = ProductRatingType::getNewInstance(Category::getRootNode()); $type2->save(); $rating = ProductRating::getNewInstance($this->product, $type2); $rating->rating->set(4); $rating->save(); $this->product->reload(); $this->assertEqual($this->product->ratingCount->get(), 2); $this->assertEqual($this->product->ratingSum->get(), 10); $this->assertEqual($this->product->rating->get(), 5); ActiveRecord::clearPool(); $summary = ProductRatingSummary::getInstance($this->product, $type2); $summary->reload(); $this->assertEqual($summary->ratingCount->get(), 1); $this->assertEqual($summary->ratingSum->get(), 4); $this->assertEqual($summary->rating->get(), 4); }
public function testPositions() { $type1 = ProductRatingType::getNewInstance(Category::getRootNode()); $type1->save(); $type2 = ProductRatingType::getNewInstance(Category::getRootNode()); $type2->save(); $this->assertEqual($type1->position->get(), 1); $this->assertEqual($type2->position->get(), 2); }
/** * @role update */ public function save() { $validator = $this->buildValidator(); if (!$validator->isValid()) { return new JSONResponse(array('err' => $validator->getErrorList())); } $post = $this->request->get('id') ? ActiveRecordModel::getInstanceById('ProductRatingType', $this->request->get('id'), ActiveRecordModel::LOAD_DATA) : ProductRatingType::getNewInstance(Category::getInstanceByID($this->request->get('categoryId'), Category::LOAD_DATA)); $post->loadRequestData($this->request); $post->save(); return new JSONResponse($post->toArray()); }
public function testRatingTypes() { $types = array(); for ($k = 1; $k <= 3; $k++) { $type = ProductRatingType::getNewInstance(Category::getRootNode()); $type->save(); $types[$k] = $type; $this->request->set('rating_' . $type->getID(), $k); } $this->controller->rate(); $this->product->reload(); $response = $this->controller->index(); $ratings = $response->get('rating'); $this->assertEqual(count($ratings), 3); foreach ($ratings as $key => $rating) { $this->assertEqual($key + 1, $rating['rating']); } }