/** * @param AcceptanceTester $I */ public function testReply(AcceptanceTester $I) { $I->wantTo('ensure that reply media-comment works'); $replyPage = ReplyPage::openBy($I); $I->amGoingTo('reply media-comment with no content'); $replyPage->submit(''); $I->expectTo('see validation error'); $I->see('Content cannot be blank.', '.help-block'); $I->amGoingTo('reply media-comment with no empty content'); $replyPage->submit('Test reply media-comment'); $I->expect('the reply saved'); $I->see('Update Media Comment 2', 'h1'); MediaComment::deleteAll(['content' => 'Test reply media-comment']); }
/** * Bulk action for MediaComment 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') === MediaComment::COMMENT_APPROVED) { foreach (Yii::$app->request->post('ids') as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => MediaComment::COMMENT_APPROVED]); } } elseif (Yii::$app->request->post('action') === MediaComment::COMMENT_UNAPPROVED) { foreach (Yii::$app->request->post('ids') as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => MediaComment::COMMENT_UNAPPROVED]); } } elseif (Yii::$app->request->post('action') === MediaComment::COMMENT_TRASH) { foreach (Yii::$app->request->post('ids') as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => MediaComment::COMMENT_TRASH]); } } elseif (Yii::$app->request->post('action') === 'delete') { foreach (Yii::$app->request->post('ids') as $id) { $model = $this->findModel($id); $media = $model->commentMedia; if ($model->delete()) { if (!$model->comment_parent) { $media->updateAttributes(['media_comment_count', $media->media_comment_count--]); } MediaComment::deleteAll(['comment_parent' => $model->id]); } } } }
/** * Bulk action for media comments */ public function actionBulkAction() { if ($_POST['action'] === 'delete') { foreach ($_POST['ids'] as $id) { $model = $this->findModel($id); $media = $model->commentMedia; if ($model->delete()) { if (!$model->comment_parent) { $media->media_comment_count--; $media->save(); } MediaComment::deleteAll(['comment_parent' => $model->id]); } } } else { if ($_POST['action'] === MediaComment::COMMENT_APPROVED) { foreach ($_POST['ids'] as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => 'approved']); } } else { if ($_POST['action'] === MediaComment::COMMENT_UNAPPROVED) { foreach ($_POST['ids'] as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => 'unapproved']); } } else { if ($_POST['action'] === MediaComment::COMMENT_TRASH) { foreach ($_POST['ids'] as $id) { $this->findModel($id)->updateAttributes(['comment_approved' => 'trash']); } } } } } }
/** * @param AcceptanceTester $I */ public function testComment(AcceptanceTester $I) { $I->wantTo('ensure that media comment works'); $mediaView = MediaViewPage::openBy($I); // $I->see('Test Media', 'h1'); $I->see('Test Media'); $I->amGoingTo('submit media comment form with no data'); $mediaView->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 media comment form with no correct email'); $mediaView->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 media comment form with correct data'); $mediaView->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'); MediaComment::deleteAll(['comment_author' => 'tester']); Media::findOne(1)->updateAttributes(['media_comment_count' => '1']); }
/** * Bulk action for MediaComment 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') === MediaComment::STATUS_APPROVED) { foreach (Yii::$app->request->post('ids', []) as $id) { $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_APPROVED]); } } elseif (Yii::$app->request->post('action') === MediaComment::STATUS_NOT_APPROVED) { foreach (Yii::$app->request->post('ids', []) as $id) { $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_NOT_APPROVED]); } } elseif (Yii::$app->request->post('action') === MediaComment::STATUS_TRASHED) { foreach (Yii::$app->request->post('ids', []) as $id) { $this->findModel($id)->updateAttributes(['status' => MediaComment::STATUS_TRASHED]); } } elseif (Yii::$app->request->post('action') === 'delete') { foreach (Yii::$app->request->post('ids', []) as $id) { $model = $this->findModel($id); $media = $model->commentMedia; if ($model->delete()) { if (!$model->parent) { $media->updateAttributes(['comment_count', --$media->comment_count]); } MediaComment::deleteAll(['parent' => $model->id]); } } } }