/** * @param AcceptanceTester $I */ public function testReply(AcceptanceTester $I) { $I->wantTo('ensure that reply post-comment works'); $replyPage = ReplyPage::openBy($I); $I->amGoingTo('reply post-comment with no content'); $replyPage->submit(); $I->expectTo('see validation error'); $I->see('Content cannot be blank.', '.help-block'); $I->amGoingTo('reply post-comment with no empty content'); $replyPage->submit('Test reply post-comment'); $I->expect('the reply saved'); $I->see('Update Post Comment: 2', 'h1'); PostComment::deleteAll(['comment_content' => 'Test reply post-comment']); }
/** * @param AcceptanceTester $I */ public function testComment(AcceptanceTester $I) { $I->wantTo('ensure that post comment works'); $postView = PostViewPage::openBy($I); // $I->see('Sample Post', 'h1'); $I->see('Sample Post'); $I->amGoingTo('submit post comment form with no data'); $postView->submitComment([]); $I->expectTo('see validations error'); $I->see('Name cannot be blank.', '.help-block'); $I->see('Email cannot be blank.', '.help-block'); $I->see('Content cannot be blank.', '.help-block'); $I->amGoingTo('submit post comment form with no correct email'); $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => 'tester.email', 'comment_content' => 'New comment']); $I->expectTo('see that email is not correct'); $I->see('Email is not a valid email address.'); $I->dontSee('Name cannot be blank.', '.help-block'); $I->dontSee('Content cannot be blank.', '.help-block'); $I->amGoingTo('submit post comment form with correct data'); $postView->submitComment(['comment_author' => 'tester', 'comment_author_email' => '*****@*****.**', 'comment_content' => 'New comment']); $I->expect('new comment saved'); $I->dontSee('Name cannot be blank.', '.help-block'); $I->dontSee('Email cannot be blank.', '.help-block'); $I->dontSee('Content cannot be blank.', '.help-block'); PostComment::deleteAll(['comment_author' => 'tester']); Post::findOne(1)->updateAttributes(['post_comment_count' => '1']); }
/** * Bulk action for post comments */ public function actionBulkAction() { if ($_POST['action'] === 'delete') { foreach ($_POST['ids'] as $id) { $model = $this->findModel($id); $post = $model->commentPost; if ($model->delete()) { if (!$model->comment_parent) { $post->post_comment_count--; $post->save(); } PostComment::deleteAll(['comment_parent' => $model->id]); } } } else { if ($_POST['action'] === PostComment::COMMENT_APPROVED) { foreach ($_POST['ids'] as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => 'approved']); } } else { if ($_POST['action'] === PostComment::COMMENT_UNAPPROVED) { foreach ($_POST['ids'] as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => 'unapproved']); } } else { if ($_POST['action'] === PostComment::COMMENT_TRASH) { foreach ($_POST['ids'] as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => 'trash']); } } } } } }
/** * Bulk action for PostComment triggered when button 'Apply' clicked. * The action depends on the value of the dropdown next to the button. * Only accept POST HTTP method. */ public function actionBulkAction() { if (Yii::$app->request->post('action') === PostComment::COMMENT_APPROVED) { foreach (Yii::$app->request->post('ids') as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => PostComment::COMMENT_APPROVED]); } } elseif (Yii::$app->request->post('action') === PostComment::COMMENT_UNAPPROVED) { foreach (Yii::$app->request->post('ids') as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => PostComment::COMMENT_UNAPPROVED]); } } elseif (Yii::$app->request->post('action') === PostComment::COMMENT_TRASH) { foreach (Yii::$app->request->post('ids') as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => PostComment::COMMENT_TRASH]); } } elseif (Yii::$app->request->post('action') === 'delete') { foreach (Yii::$app->request->post('ids') as $id) { $model = $this->findModel($id); $post = $model->commentPost; if ($model->delete()) { if (!$model->comment_parent) { $post->updateAttributes(['post_comment_count', $post->post_comment_count--]); } PostComment::deleteAll(['comment_parent' => $model->id]); } } } }
/** * Bulk action for PostComment triggered when button 'Apply' clicked. * The action depends on the value of the dropdown next to the button. * Only accept POST HTTP method. */ public function actionBulkAction() { if (Yii::$app->request->post('action') === PostComment::STATUS_APPROVED) { foreach (Yii::$app->request->post('ids', []) as $id) { $this->findModel($id)->updateAttributes(['status' => PostComment::STATUS_APPROVED]); } } elseif (Yii::$app->request->post('action') === PostComment::STATUS_NOT_APPROVED) { foreach (Yii::$app->request->post('ids', []) as $id) { $this->findModel($id)->updateAttributes(['status' => PostComment::STATUS_NOT_APPROVED]); } } elseif (Yii::$app->request->post('action') === PostComment::STATUS_TRASHED) { foreach (Yii::$app->request->post('ids', []) as $id) { $this->findModel($id)->updateAttributes(['status' => PostComment::STATUS_TRASHED]); } } elseif (Yii::$app->request->post('action') === 'delete') { foreach (Yii::$app->request->post('ids', []) as $id) { $model = $this->findModel($id); $post = $model->commentPost; if ($model->delete()) { if (!$model->parent) { $post->updateAttributes(['comment_count', --$post->comment_count]); } PostComment::deleteAll(['parent' => $model->id]); } } } }