/** * Tests invalid (stale) form configurations. */ function testInvalidForms() { $forms = ['nonexisting' => 'nonexisting_form', 'user' => 'user_nonexisting_form', 'node' => 'nonexisting_node_form', 'comment' => 'comment_node_nonexisting_form']; $mode = 0; foreach ($forms as $module => $form_id) { $mollom_form = FormController::getProtectedFormDetails($form_id, $module, []); $mollom_form['mode'] = $mode++; $form = Form::create($mollom_form); $form->id = $form_id; $form->save(); } // Just visiting the form administration page is sufficient; it will throw // fatal errors, warnings, and notices. $this->drupalLogin($this->adminUser); $this->drupalGet('admin/config/content/mollom'); // Ensure that unprotecting the forms does not throw any notices either. foreach ($forms as $form_id) { $this->assertNoLinkByHref('admin/config/content/mollom/form/' . $form_id . '/edit'); $this->assertLinkByHref('admin/config/content/mollom/form/' . $form_id . '/delete'); $this->drupalPostForm('admin/config/content/mollom/form/' . $form_id . '/delete', array(), t('Remove Mollom Protection')); $this->assertNoLinkByHref('admin/config/content/mollom/form/' . $form_id . '/delete'); } // Confirm deletion. $configured = \Drupal::entityManager()->getStorage('mollom_form')->loadMultiple(); $this->assertFalse($configured, 'No forms found.'); }
/** * Saves a mollom_form entity to protect a given form with Mollom. * * @param string $form_id * The form id to protect. * @param int $mode * The protection mode defined in \Drupal\mollom\Entity\FormInterface. * Defaults to MOLLOM_MODE_ANALYSIS. * @param array $values * (optional) An associative array of properties to additionally set on the * mollom_form entity. * * @return int * The save status, as returned by mollom_form_save(). */ protected function setProtection($form_id, $mode = FormInterface::MOLLOM_MODE_ANALYSIS, $values = array()) { /* @var $mollom_form \Drupal\mollom\Entity\FormInterface */ if (!($mollom_form = \Drupal::entityManager()->getStorage('mollom_form')->load($form_id))) { $mollom_form = Form::create(); $mollom_form->initialize($form_id); } $mollom_form->setProtectionMode($mode); if ($values) { foreach ($values as $property => $value) { $mollom_form[$property] = $value; } } $status = $mollom_form->save(); return $status; }
/** * Saves a mollom_form entity to protect a given form with Mollom. * * @param string $form_id * The form id to protect. * @param int $mode * The protection mode defined in \Drupal\mollom\Entity\FormInterface. * Defaults to MOLLOM_MODE_ANALYSIS. * @param array $values * (optional) An associative array of properties to additionally set on the * mollom_form entity. * * @return int * The save status, as returned by mollom_form_save(). */ protected function setProtection($form_id, $mode = FormInterface::MOLLOM_MODE_ANALYSIS, $values = array()) { if (!($mollom_form = entity_load('mollom_form', $form_id))) { $mollom_form = Form::create(); $mollom_form->initialize($form_id); } $mollom_form->setProtectionMode($mode); if ($values) { foreach ($values as $property => $value) { $mollom_form[$property] = $value; } } $status = $mollom_form->save(); return $status; }