/** * Loads the selected option set. * * @param string $id * * @returns \Drupal\flexslider\Entity\Flexslider * The option set selected in the formatter settings. */ protected function loadOptionset($id) { return \Drupal\flexslider\Entity\Flexslider::load($id); }
/** * Test the option set form. */ public function testOptionSetForm() { // Login with admin user. $this->drupalLogin($this->adminUser); // ------------ Test Option Set Add ------------ // // Load create form. $this->drupalGet('admin/config/media/flexslider/add'); $this->assertResponse(200, t('Administrative user can reach the "Add" form.')); // Save new optionset. $optionset = array(); $optionset['label'] = t('testset'); $optionset['id'] = 'testset'; $this->drupalPostForm('admin/config/media/flexslider/add', $optionset, t('Save')); $this->assertResponse(200); $this->assertText('Created the testset FlexSlider optionset.', t('Successfully saved the new optionset "testset"')); // Attempt to save option set of the same name again. $this->drupalPostForm('admin/config/media/flexslider/add', $optionset, t('Save')); $this->assertResponse(200); $this->assertText('The machine-readable name is already in use. It must be unique.', t('Blocked the creation of duplicate named optionset.')); // ------------ Test Option Set Edit ------------ // // Attempt to save each option value. $options = $this->getTestOptions(); foreach ($options['valid'] as $testset) { $this->drupalPostForm('admin/config/media/flexslider/default', $testset, t('Save')); $this->assertResponse(200); // Test saved values loaded into form. $this->drupalGet('admin/config/media/flexslider/default'); $this->assertResponse(200, t('Default optionset reloaded.')); foreach ($testset as $key => $option) { $this->assertFieldByName($key, $option, t('Value for @key appears in form correctly.', array('@key' => $key))); } } // ------------ Test Option Set Delete ------------ //. $testset = Flexslider::load('testset'); // Test the delete workflow. $this->drupalGet("admin/config/media/flexslider/{$testset->id()}/delete"); $this->assertResponse(200); $this->assertText("Are you sure you want to delete {$testset->label()}?", t('Delete confirmation form loaded.')); $this->drupalPostForm("admin/config/media/flexslider/{$testset->id()}/delete", [], t('Delete')); $this->assertResponse(200); $this->assertText("Deleted the {$testset->label()} FlexSlider optionset.", t('Deleted test set using form.')); }