/**
  * Tests the widget.
  */
 protected function testWidget()
 {
     $user = $this->drupalCreateUser(['administer user fields']);
     $this->drupalLogin($user);
     // Test the widget when setting a default field value.
     $field_name = strtolower($this->randomMachineName());
     $selectable_plugin_type_id = 'block';
     $field_type = 'plugin:' . $selectable_plugin_type_id;
     $default_selected_plugin_id = 'broken';
     $this->drupalPostForm('admin/config/people/accounts/fields/add-field', ['label' => $this->randomString(), 'field_name' => $field_name, 'new_storage_type' => $field_type], t('Save and continue'));
     $this->drupalPostForm(NULL, [], t('Save field settings'));
     $this->drupalPostForm(NULL, [sprintf('default_value_input[field_%s][0][plugin_selector][container][select][container][plugin_id]', $field_name) => $default_selected_plugin_id], t('Choose'));
     $this->drupalPostForm(NULL, [], t('Save settings'));
     \Drupal::entityManager()->clearCachedFieldDefinitions();
     // Get all plugin fields.
     $field_storage_id = 'user.field_' . $field_name;
     $field_storage = FieldStorageConfig::load($field_storage_id);
     $this->assertNotNull($field_storage);
     $field_id = 'user.user.field_' . $field_name;
     /** @var \Drupal\field\FieldConfigInterface $field */
     $field = FieldConfig::load($field_id);
     $this->assertNotNull($field);
     $this->assertEqual($field->getDefaultValueLiteral()[0]['plugin_type_id'], $selectable_plugin_type_id);
     $this->assertEqual($field->getDefaultValueLiteral()[0]['plugin_id'], $default_selected_plugin_id);
     $this->assertTrue(is_array($field->getDefaultValueLiteral()[0]['plugin_configuration']));
     // Test the widget when creating an entity.
     $entity_selected_plugin_id = 'system_breadcrumb_block';
     $this->drupalPostForm('user/' . $user->id() . '/edit', [sprintf('field_%s[0][plugin_selector][container][select][container][plugin_id]', $field_name) => $entity_selected_plugin_id], t('Choose'));
     $this->drupalPostForm(NULL, [], t('Save'));
     // Test whether the widget displays field values.
     /** @var \Drupal\Core\Entity\ContentEntityInterface $user */
     $user = entity_load_unchanged('user', $user->id());
     $this->assertEqual($user->get('field_' . $field_name)->get(0)->get('plugin_type_id')->getValue(), $selectable_plugin_type_id);
     $this->assertEqual($user->get('field_' . $field_name)->get(0)->get('plugin_id')->getValue(), $entity_selected_plugin_id);
 }
Esempio n. 2
0
 /**
  * Tests the Drupal 6 files to Drupal 8 migration.
  */
 public function testFiles()
 {
     /** @var \Drupal\file\FileInterface $file */
     $file = entity_load('file', 1);
     $this->assertIdentical('Image1.png', $file->getFilename());
     $this->assertIdentical('39325', $file->getSize());
     $this->assertIdentical('public://image-1.png', $file->getFileUri());
     $this->assertIdentical('image/png', $file->getMimeType());
     // It is pointless to run the second half from MigrateDrupal6Test.
     if (empty($this->standalone)) {
         return;
     }
     // Test that we can re-import and also test with file_directory_path set.
     db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_file');
     $dumps = array($this->getDumpDirectory() . '/Variable.php');
     $this->prepare($migration, $dumps);
     // Update the file_directory_path.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize('files/test')))->condition('name', 'file_directory_path')->execute();
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize($this->getTempFilesDirectory())))->condition('name', 'file_directory_temp')->execute();
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $file = entity_load('file', 2);
     $this->assertIdentical('public://core/modules/simpletest/files/image-2.jpg', $file->getFileUri());
     // Ensure that a temporary file has been migrated.
     $file = entity_load('file', 6);
     $this->assertIdentical('temporary://' . static::getUniqueFilename(), $file->getFileUri());
 }
 /**
  * Tests the form.
  */
 function testForm()
 {
     $user = $this->drupalCreateUser(array('currency.currency_locale.delete'));
     $this->drupalLogin($user);
     $currency_locale = entity_create('currency_locale', array('locale' => 'zz_ZZ'));
     $currency_locale->save();
     $this->drupalPostForm('admin/config/regional/currency-formatting/locale/' . $currency_locale->id() . '/delete', array(), t('Delete'));
     $this->assertFalse(entity_load_unchanged('currency_locale', $currency_locale->id()));
 }
 /**
  * Tests the form.
  */
 function testForm()
 {
     $user = $this->drupalCreateUser(array('currency.currency.delete'));
     $this->drupalLogin($user);
     $currency = entity_create('currency', array('currencyCode' => 'ABC'));
     $currency->save();
     $this->drupalPostForm('admin/config/regional/currency/' . $currency->id() . '/delete', array(), t('Delete'));
     $this->assertFalse((bool) entity_load_unchanged('currency', $currency->id()));
 }
Esempio n. 5
0
 /**
  * Test the [entity:original:*] tokens.
  */
 function testEntityOriginal()
 {
     $node = Node::create(['type' => 'page', 'title' => 'Original title']);
     $node->save();
     $tokens = array('nid' => $node->id(), 'title' => 'Original title', 'original' => NULL, 'original:nid' => NULL);
     $this->assertTokens('node', array('node' => $node), $tokens);
     // Emulate the original entity property that would be available from
     // node_save() and change the title for the node.
     $node->original = entity_load_unchanged('node', $node->id());
     $node->title = 'New title';
     $tokens = array('nid' => $node->id(), 'title' => 'New title', 'original' => 'Original title', 'original:nid' => $node->id());
     $this->assertTokens('node', array('node' => $node), $tokens);
 }
Esempio n. 6
0
 /**
  * Tests the Drupal 6 menu to Drupal 8 migration.
  */
 public function testMenu()
 {
     $navigation_menu = entity_load('menu', 'navigation');
     $this->assertEqual($navigation_menu->id(), 'navigation');
     $this->assertEqual($navigation_menu->label(), 'Navigation');
     $this->assertEqual($navigation_menu->description, 'The navigation menu is provided by Drupal and is the main interactive menu for any site. It is usually the only menu that contains personalized links for authenticated users, and is often not even visible to anonymous users.');
     // Test that we can re-import using the ConfigEntityBase destination.
     Database::getConnection('default', 'migrate')->update('menu_custom')->fields(array('title' => 'Home Navigation'))->condition('menu_name', 'navigation')->execute();
     db_truncate(entity_load('migration', 'd6_menu')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_menu');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $navigation_menu = entity_load_unchanged('menu', 'navigation');
     $this->assertEqual($navigation_menu->label(), 'Home Navigation');
 }
Esempio n. 7
0
 /**
  * Get original entity
  *
  * @return EntityInterface
  */
 public function getOriginalEntity()
 {
     $entity = $this->getEntity();
     if ($entity->isNew()) {
         throw new \LogicException(sprintf('entity is new for event %s', $this->getEventName()));
     }
     if (isset($entity->original)) {
         return $entity->original;
     }
     // No entity, attempt original entity load
     $original = entity_load_unchanged($this->getEntityType(), $this->getEntityId());
     if ($original) {
         return $original;
     }
     throw new \LogicException(sprintf('there is no original entity for event %s', $this->getEventName()));
 }
 /**
  * Tests the field.
  */
 protected function testField()
 {
     // Create the field and field instance.
     $field_name = strtolower($this->randomMachineName());
     entity_create('field_storage_config', ['cardinality' => FieldStorageConfigInterface::CARDINALITY_UNLIMITED, 'entity_type' => 'user', 'field_name' => $field_name, 'type' => 'payment_form'])->save();
     entity_create('field_config', ['bundle' => 'user', 'entity_type' => 'user', 'field_name' => $field_name, 'settings' => ['currency_code' => 'EUR']])->save();
     // Set a field value on an entity and test getting it.
     $user = entity_create('user', ['name' => $this->randomString()]);
     foreach (Generate::createPaymentLineItems() as $line_item) {
         $user->get($field_name)->appendItem(['plugin_id' => $line_item->getPluginId(), 'plugin_configuration' => $line_item->getConfiguration()]);
     }
     $this->assertFieldValue($user, $field_name);
     // Save the entity, load it from storage and test getting the field value.
     $user->save();
     $user = entity_load_unchanged('user', $user->id());
     $this->assertFieldValue($user, $field_name);
 }
Esempio n. 9
0
 /**
  * Tests the Drupal 6 date formats to Drupal 8 migration.
  */
 public function testDateFormats()
 {
     $short_date_format = entity_load('date_format', 'short');
     $this->assertIdentical('\\S\\H\\O\\R\\T m/d/Y - H:i', $short_date_format->getPattern());
     $medium_date_format = entity_load('date_format', 'medium');
     $this->assertIdentical('\\M\\E\\D\\I\\U\\M D, m/d/Y - H:i', $medium_date_format->getPattern());
     $long_date_format = entity_load('date_format', 'long');
     $this->assertIdentical('\\L\\O\\N\\G l, F j, Y - H:i', $long_date_format->getPattern());
     // Test that we can re-import using the EntityDateFormat destination.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize('\\S\\H\\O\\R\\T d/m/Y - H:i')))->condition('name', 'date_format_short')->execute();
     db_truncate(entity_load('migration', 'd6_date_formats')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_date_formats');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $short_date_format = entity_load('date_format', 'short');
     $this->assertIdentical('\\S\\H\\O\\R\\T d/m/Y - H:i', $short_date_format->getPattern());
 }
Esempio n. 10
0
 /**
  * Tests Drupal 6 search settings to Drupal 8 search page entity migration.
  */
 public function testSearchPage()
 {
     $id = 'node_search';
     /** @var \Drupal\search\Entity\SearchPage $search_page */
     $search_page = entity_load('search_page', $id);
     $this->assertIdentical($id, $search_page->id());
     $configuration = $search_page->getPlugin()->getConfiguration();
     $this->assertIdentical($configuration['rankings'], array('comments' => 5, 'relevance' => 2, 'sticky' => 8, 'views' => 1));
     $this->assertIdentical('node', $search_page->getPath());
     // Test that we can re-import using the EntitySearchPage destination.
     Database::getConnection('default', 'migrate')->update('variable')->fields(array('value' => serialize(4)))->condition('name', 'node_rank_comments')->execute();
     $migration = entity_load_unchanged('migration', 'd6_search_page');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $search_page = entity_load('search_page', $id);
     $configuration = $search_page->getPlugin()->getConfiguration();
     $this->assertIdentical(4, $configuration['rankings']['comments']);
 }
 /**
  * Tests CRUD();
  */
 protected function testCRUD()
 {
     $database = \Drupal::database();
     $user = $this->drupalCreateUser();
     $payment_type_configuration = array($this->randomMachineName() => $this->randomMachineName());
     $payment_method = Payment::methodManager()->createInstance('payment_basic:no_payment_required');
     // Test creating a payment.
     $payment = Generate::createPayment($user->id(), $payment_method);
     $payment->getPaymentType()->setConfiguration($payment_type_configuration);
     $this->assertTrue($payment instanceof PaymentInterface);
     // @todo The ID should be an integer, but for some reason the entity field
     //   API returns a string.
     $this->assertTrue(is_numeric($payment->getOwnerId()));
     $this->assertEqual(count($payment->validate()), 0);
     $this->assertTrue($payment->getPaymentType() instanceof PaymentTypeInterface);
     // Test saving a payment.
     $this->assertFalse($payment->id());
     // Set an extra status, so we can test for status IDs later.
     $payment->setPaymentStatus(Payment::statusManager()->createInstance('payment_success'));
     $payment->save();
     // @todo The ID should be an integer, but for some reason the entity field
     //   API returns a string.
     $this->assertTrue(is_numeric($payment->id()));
     $this->assertTrue(strlen($payment->uuid()));
     // @todo The ID should be an integer, but for some reason the entity field
     //   API returns a string.
     $this->assertTrue(is_numeric($payment->getOwnerId()));
     // Check references to other tables.
     $payment_data = $database->select('payment', 'p')->fields('p', array('current_payment_status_delta'))->condition('id', $payment->id())->execute()->fetchAssoc();
     $this->assertEqual($payment_data['current_payment_status_delta'], 1);
     /** @var \Drupal\payment\Entity\PaymentInterface $payment_loaded */
     $payment_loaded = entity_load_unchanged('payment', $payment->id());
     $this->assertEqual(count($payment_loaded->getLineItems()), count($payment->getLineItems()));
     foreach ($payment_loaded->getLineItems() as $line_item) {
         $this->assertTrue($line_item instanceof PaymentLineItemInterface);
     }
     $this->assertEqual(count($payment_loaded->getPaymentStatuses()), count($payment->getPaymentStatuses()));
     foreach ($payment_loaded->getPaymentStatuses() as $status) {
         $this->assertTrue($status instanceof PaymentStatusInterface);
     }
     $this->assertEqual($payment_loaded->getPaymentMethod()->getConfiguration(), $payment->getPaymentMethod()->getConfiguration());
     $this->assertEqual($payment_loaded->getPaymentType()->getConfiguration(), $payment->getPaymentType()->getConfiguration());
 }
 /**
  * Test the url alias migration.
  */
 public function testUrlAlias()
 {
     $migration = entity_load('migration', 'd6_url_alias');
     // Test that the field exists.
     $conditions = array('source' => '/node/1', 'alias' => '/alias-one', 'langcode' => 'en');
     $path = \Drupal::service('path.alias_storage')->load($conditions);
     $this->assertNotNull($path, "Path alias for node/1 successfully loaded.");
     $this->assertIdentical($migration->getIdMap()->lookupDestinationID(array($path['pid'])), array('1'), "Test IdMap");
     $conditions = array('source' => '/node/2', 'alias' => '/alias-two', 'langcode' => 'en');
     $path = \Drupal::service('path.alias_storage')->load($conditions);
     $this->assertNotNull($path, "Path alias for node/2 successfully loaded.");
     // Test that we can re-import using the UrlAlias destination.
     Database::getConnection('default', 'migrate')->update('url_alias')->fields(array('dst' => 'new-url-alias'))->condition('src', 'node/2')->execute();
     db_update($migration->getIdMap()->mapTableName())->fields(array('source_row_status' => MigrateIdMapInterface::STATUS_NEEDS_UPDATE))->execute();
     $migration = entity_load_unchanged('migration', 'd6_url_alias');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $path = \Drupal::service('path.alias_storage')->load(array('pid' => $path['pid']));
     $this->assertIdentical('/new-url-alias', $path['alias']);
 }
 /**
  * Tests enabling/disabling.
  */
 protected function doTestEnableDisable()
 {
     $this->drupalLogout();
     // Confirm that there are no enable/disable links without the required
     // permissions.
     $this->drupalLogin($this->drupalCreateUser(array('payment.payment_method_configuration.view.any')));
     $this->drupalGet('admin/config/services/payment/method/configuration');
     $this->assertNoLink(t('Enable'));
     $this->assertNoLink(t('Disable'));
     /** @var \Drupal\payment\Entity\PaymentMethodConfigurationInterface $payment_method */
     $payment_method = entity_load('payment_method_configuration', 'collect_on_delivery');
     $this->assertFalse($payment_method->status());
     $this->drupalLogin($this->drupalCreateUser(array('payment.payment_method_configuration.view.any', 'payment.payment_method_configuration.update.any')));
     $this->drupalGet('admin/config/services/payment/method/configuration');
     $this->clickLink(t('Enable'));
     $payment_method = entity_load_unchanged('payment_method_configuration', 'collect_on_delivery');
     $this->assertTrue($payment_method->status());
     $this->clickLink(t('Disable'));
     $payment_method = entity_load_unchanged('payment_method_configuration', 'collect_on_delivery');
     $this->assertFalse($payment_method->status());
 }
 /**
  * Tests the field.
  */
 protected function testField()
 {
     // Create the field and field instance.
     $field_name = strtolower($this->randomMachineName());
     entity_create('field_storage_config', array('cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED, 'entity_type' => 'user', 'field_name' => $field_name, 'type' => 'payment_reference'))->save();
     entity_create('field_config', array('bundle' => 'user', 'entity_type' => 'user', 'field_name' => $field_name, 'settings' => array('currency_code' => 'EUR', 'line_items_data' => [])))->save();
     $payment = Generate::createPayment(mt_rand());
     $payment->setPaymentStatus(Payment::statusManager()->createInstance('payment_success'));
     $payment->save();
     PaymentReference::queue()->save('user.' . $field_name, $payment->id());
     $this->assertEqual(PaymentReference::queue()->loadPaymentIds('user.' . $field_name, $payment->getOwnerId()), array($payment->id()));
     // Set a field value on an entity and test getting it.
     /** @var \Drupal\user\UserInterface $user */
     $user = entity_create('user', array('name' => $this->randomString()));
     $user->get($field_name)->appendItem($payment->id());
     $this->assertEqual($user->get($field_name)->first()->entity->id(), $payment->id());
     // Save the entity, load it from storage and test getting the field value.
     $user->save();
     $user = entity_load_unchanged('user', $user->id());
     $this->assertEqual($user->{$field_name}[0]->target_id, $payment->id());
     $this->assertEqual(PaymentReference::queue()->loadPaymentIds('user.' . $field_name, $payment->getOwnerId()), []);
 }
 /**
  * Tests the Drupal 6 files to Drupal 8 migration.
  */
 public function testFiles()
 {
     /** @var \Drupal\file\FileInterface $file */
     $file = entity_load('file', 1);
     $this->assertEqual($file->getFilename(), 'Image1.png');
     $this->assertEqual($file->getSize(), 39325);
     $this->assertEqual($file->getFileUri(), 'public://image-1.png');
     $this->assertEqual($file->getMimeType(), 'image/png');
     // It is pointless to run the second half from MigrateDrupal6Test.
     if (empty($this->standalone)) {
         return;
     }
     // Test that we can re-import and also test with file_directory_path set.
     db_truncate(entity_load('migration', 'd6_file')->getIdMap()->mapTableName())->execute();
     $migration = entity_load_unchanged('migration', 'd6_file');
     $dumps = array($this->getDumpDirectory() . '/Drupal6SystemFile.php');
     $this->loadDumps($dumps, 'loadMigrateFileStandalone');
     $executable = new MigrateExecutable($migration, $this);
     $executable->import();
     $file = entity_load('file', 2);
     $this->assertEqual($file->getFileUri(), 'public://core/modules/simpletest/files/image-2.jpg');
 }
 /**
  * Overrides Entity::save().
  *
  * Maintains the role, adding or removing it from the owner when necessary.
  */
 public function save()
 {
     if ($this->uid && $this->product_id) {
         $role = $this->wrapper->product->commerce_license_role->value();
         $owner = $this->wrapper->owner->value();
         $save_owner = FALSE;
         if (!empty($this->license_id)) {
             $this->original = entity_load_unchanged('commerce_license', $this->license_id);
             // A plan change occurred. Remove the previous role.
             if ($this->original->product_id && $this->product_id != $this->original->product_id) {
                 $previous_role = $this->original->wrapper->product->commerce_license_role->value();
                 if (isset($owner->roles[$previous_role])) {
                     unset($owner->roles[$previous_role]);
                     $save_owner = TRUE;
                 }
             }
         }
         // The owner of an active license must have the role.
         if ($this->status == COMMERCE_LICENSE_ACTIVE) {
             if (!isset($owner->roles[$role])) {
                 $owner->roles[$role] = $role;
                 $save_owner = TRUE;
             }
         } elseif ($this->status > COMMERCE_LICENSE_ACTIVE) {
             // The owner of an inactive license must not have the role.
             if (isset($owner->roles[$role])) {
                 unset($owner->roles[$role]);
                 $save_owner = TRUE;
             }
         }
         // If a role was added or removed, save the owner.
         if ($save_owner) {
             user_save($owner);
         }
     }
     parent::save();
 }
Esempio n. 17
0
function api_node_save($node)
{
    $transaction = db_transaction();
    try {
        // Load the stored entity, if any.
        if (!empty($node->nid) && !isset($node->original)) {
            $node->original = entity_load_unchanged('node', $node->nid);
        }
        field_attach_presave('node', $node);
        global $user;
        // Determine if we will be inserting a new node.
        if (!isset($node->is_new)) {
            $node->is_new = empty($node->nid);
        }
        /*
            // Set the timestamp fields.
            if (empty($node->created)) {
              $node->created = REQUEST_TIME;
            }
            // The changed timestamp is always updated for bookkeeping purposes,
            // for example: revisions, searching, etc.
            $node->changed = REQUEST_TIME;
        
            $node->timestamp = REQUEST_TIME;
        */
        $update_node = TRUE;
        // Let modules modify the node before it is saved to the database.
        module_invoke_all('node_presave', $node);
        module_invoke_all('entity_presave', $node, 'node');
        if ($node->is_new || !empty($node->revision)) {
            // When inserting either a new node or a new node revision, $node->log
            // must be set because {node_revision}.log is a text column and therefore
            // cannot have a default value. However, it might not be set at this
            // point (for example, if the user submitting a node form does not have
            // permission to create revisions), so we ensure that it is at least an
            // empty string in that case.
            // @todo: Make the {node_revision}.log column nullable so that we can
            // remove this check.
            if (!isset($node->log)) {
                $node->log = '';
            }
        } elseif (!isset($node->log) || $node->log === '') {
            // If we are updating an existing node without adding a new revision, we
            // need to make sure $node->log is unset whenever it is empty. As long as
            // $node->log is unset, drupal_write_record() will not attempt to update
            // the existing database column when re-saving the revision; therefore,
            // this code allows us to avoid clobbering an existing log entry with an
            // empty one.
            unset($node->log);
        }
        // When saving a new node revision, unset any existing $node->vid so as to
        // ensure that a new revision will actually be created, then store the old
        // revision ID in a separate property for use by node hook implementations.
        if (!$node->is_new && !empty($node->revision) && $node->vid) {
            $node->old_vid = $node->vid;
            unset($node->vid);
        }
        // Save the node and node revision.
        if ($node->is_new) {
            // For new nodes, save new records for both the node itself and the node
            // revision.
            drupal_write_record('node', $node);
            _node_save_revision($node, $user->uid);
            $op = 'insert';
        } else {
            // For existing nodes, update the node record which matches the value of
            // $node->nid.
            drupal_write_record('node', $node, 'nid');
            // Then, if a new node revision was requested, save a new record for
            // that; otherwise, update the node revision record which matches the
            // value of $node->vid.
            if (!empty($node->revision)) {
                _node_save_revision($node, $user->uid);
            } else {
                _node_save_revision($node, $user->uid, 'vid');
                $update_node = FALSE;
            }
            $op = 'update';
        }
        if ($update_node) {
            db_update('node')->fields(array('vid' => $node->vid))->condition('nid', $node->nid)->execute();
        }
        // Call the node specific callback (if any). This can be
        // node_invoke($node, 'insert') or
        // node_invoke($node, 'update').
        node_invoke($node, $op);
        // Save fields.
        $function = "field_attach_{$op}";
        $function('node', $node);
        module_invoke_all('node_' . $op, $node);
        module_invoke_all('entity_' . $op, $node, 'node');
        // Update the node access table for this node.
        node_access_acquire_grants($node);
        // Clear internal properties.
        unset($node->is_new);
        unset($node->original);
        // Clear the static loading cache.
        entity_get_controller('node')->resetCache(array($node->nid));
        // Ignore slave server temporarily to give time for the
        // saved node to be propagated to the slave.
        db_ignore_slave();
    } catch (Exception $e) {
        $transaction->rollback();
        watchdog_exception('node', $e);
        throw $e;
    }
}
Esempio n. 18
0
 /**
  * Test the page callbacks to create jobs and check them out.
  *
  * This includes
  * - Varying checkout situations with form detail values.
  * - Unsupported checkout situations where translator is not available.
  * - Exposed filters for job overview
  * - Deleting a job
  *
  * @todo Separate the exposed filter admin overview test.
  */
 function testCheckoutForm()
 {
     // Add a first item to the job. This will auto-create the job.
     $job = tmgmt_job_match_item('en', '');
     $job->addItem('test_source', 'test', 1);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Test primary buttons.
     $this->assertRaw('Save job" class="button js-form-submit form-submit"');
     // Check checkout form.
     $this->assertText('test_source:test:1');
     // Add two more job items.
     $job->addItem('test_source', 'test', 2);
     $job->addItem('test_source', 'test', 3);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('test_source:test:1');
     $this->assertText('test_source:test:2');
     $this->assertText('test_source:test:3');
     // @todo: Test ajax functionality.
     // Attempt to translate into greek.
     $edit = array('target_language' => 'el', 'settings[action]' => 'translate');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('@translator can not translate from @source to @target.', array('@translator' => 'Test provider', '@source' => 'English', '@target' => 'Greek')));
     // Job still needs to be in state new.
     /** @var \Drupal\tmgmt\JobInterface $job */
     $job = \Drupal::entityTypeManager()->getStorage('tmgmt_job')->loadUnchanged($job->id());
     $this->assertTrue($job->isUnprocessed());
     // The owner must be the one that submits the job.
     $this->assertTrue($job->isAuthor());
     $this->drupalLogin($this->translator_user);
     $this->drupalGet('admin/tmgmt/jobs/' . $job->id());
     $edit = array('target_language' => 'es', 'settings[action]' => 'translate');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     /** @var \Drupal\tmgmt\JobInterface $job */
     $job = \Drupal::entityTypeManager()->getStorage('tmgmt_job')->loadUnchanged($job->id());
     $this->assertTrue($job->isAuthor());
     // Job needs to be in state active.
     $job = \Drupal::entityTypeManager()->getStorage('tmgmt_job')->loadUnchanged($job->id());
     $this->assertTrue($job->isActive());
     foreach ($job->getItems() as $job_item) {
         /* @var $job_item \Drupal\tmgmt\JobItemInterface */
         $this->assertTrue($job_item->isNeedsReview());
     }
     $this->assertText(t('Test translation created'));
     $this->assertNoText(t('Test provider called'));
     // Test redirection.
     $this->assertText(t('Job overview'));
     // Another job.
     $previous_tjid = $job->id();
     $job = tmgmt_job_match_item('en', '');
     $job->addItem('test_source', 'test', 9);
     $this->assertNotEqual($job->id(), $previous_tjid);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:9');
     $edit = array('target_language' => 'es', 'settings[action]' => 'submit');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('Test submit'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isActive());
     // Another job.
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 10);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:10');
     $edit = array('settings[action]' => 'reject');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('This is not supported'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isRejected());
     // Check displayed job messages.
     $args = array('@view' => 'view-tmgmt-job-messages');
     $this->assertEqual(2, count($this->xpath('//div[contains(@class, @view)]//tbody/tr', $args)));
     // Check that the author for each is the current user.
     $message_authors = $this->xpath('////div[contains(@class, @view)]//td[contains(@class, @field)]/span', $args + array('@field' => 'views-field-name'));
     $this->assertEqual(2, count($message_authors));
     foreach ($message_authors as $message_author) {
         $this->assertEqual((string) $message_author, $this->translator_user->getUsername());
     }
     // Make sure that rejected jobs can be re-submitted.
     $this->assertTrue($job->isSubmittable());
     $edit = array('settings[action]' => 'translate');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('Test translation created'));
     // HTML tags count.
     \Drupal::state()->set('tmgmt.test_source_data', array('title' => array('deep_nesting' => array('#text' => '<p><em><strong>Six dummy HTML tags in the title.</strong></em></p>', '#label' => 'Title')), 'body' => array('deep_nesting' => array('#text' => '<p>Two dummy HTML tags in the body.</p>', '#label' => 'Body')), 'phantom' => array('deep_nesting' => array('#text' => 'phantom text', '#label' => 'phantom label', '#translate' => FALSE, '#format' => 'filtered_html'))));
     $item4 = $job->addItem('test_source', 'test', 4);
     // Manually active the item as the test expects that.
     $item4->active();
     $this->drupalGet('admin/tmgmt/items/' . $item4->id());
     // Test if the phantom wrapper is not displayed because of #translate FALSE.
     $this->assertNoRaw('tmgmt-ui-element-phantom-wrapper');
     // Test primary buttons.
     $this->assertRaw('Save" class="button button--primary js-form-submit form-submit"');
     $this->drupalPostForm(NULL, NULL, t('Save'));
     $this->clickLink('View');
     $this->assertRaw('Save as completed" class="button button--primary js-form-submit form-submit"');
     $this->drupalPostForm(NULL, NULL, t('Save'));
     $this->assertRaw('Save job" class="button button--primary js-form-submit form-submit"');
     $this->drupalPostForm(NULL, NULL, t('Save job'));
     $this->drupalGet('admin/tmgmt/jobs');
     // Total number of tags should be 8.
     $tags = trim((int) $this->xpath('//table[@class="views-table views-view-table cols-10"]/tbody/tr')[0]->td[7]);
     $this->assertEqual($tags, 8);
     // Another job.
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 11);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:11');
     $edit = array('settings[action]' => 'fail');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     $this->assertText(t('Service not reachable'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isUnprocessed());
     // Verify that we are still on the form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     // Another job.
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 12);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:12');
     $edit = array('settings[action]' => 'not_translatable');
     $this->drupalPostForm(NULL, $edit, t('Submit to provider'));
     // @todo Update to correct failure message.
     $this->assertText(t('Fail'));
     $job = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job->isUnprocessed());
     // Test default settings.
     $this->default_translator->setSetting('action', 'reject');
     $this->default_translator->save();
     $job = tmgmt_job_match_item('en', 'es');
     $job->addItem('test_source', 'test', 13);
     // Go to checkout form.
     $redirects = tmgmt_job_checkout_multiple(array($job));
     $this->drupalGet(reset($redirects));
     // Check checkout form.
     $this->assertText('You can provide a label for this job in order to identify it easily later on.');
     $this->assertText('test_source:test:13');
     // The action should now default to reject.
     $this->drupalPostForm(NULL, array(), t('Submit to provider'));
     $this->assertText(t('This is not supported.'));
     $job4 = entity_load_unchanged('tmgmt_job', $job->id());
     $this->assertTrue($job4->isRejected());
     // Test for job checkout form, if the target language is supported,
     // the test translator should say it is supported.
     $job = tmgmt_job_create('en', 'de', 0);
     $job->save();
     $edit = array('target_language' => 'de');
     $this->drupalPostAjaxForm('admin/tmgmt/jobs/' . $job->id(), $edit, 'target_language');
     $this->assertFieldByXPath('//select[@id="edit-translator"]/option[1]', 'Test provider');
     $this->drupalGet('admin/tmgmt/jobs');
     // Test if sources languages are correct.
     $sources = $this->xpath('//table[@class="views-table views-view-table cols-10"]/tbody/tr/td[@class="views-field views-field-source-language-1"][contains(., "English")]');
     $this->assertEqual(count($sources), 5);
     // Test if targets languages are correct.
     $targets = $this->xpath('//table[@class="views-table views-view-table cols-10"]/tbody/tr/td[@class="views-field views-field-target-language"][contains(., "Spanish") or contains(., "German")]');
     $this->assertEqual(count($targets), 5);
     // Check that the first action is 'manage'.
     $first_action = $this->xpath('//tbody/tr[2]/td[10]/div/div/ul/li[1]/a');
     $this->assertEqual($first_action[0][0], 'Manage');
     // Test for Unavailable/Unconfigured Translators.
     $this->default_translator->setSetting('action', 'not_translatable');
     $this->default_translator->save();
     $this->drupalGet('admin/tmgmt/jobs/' . $job->id());
     $this->drupalPostForm(NULL, array(), t('Submit to provider'));
     $this->assertText(t('Test provider can not translate from English to German.'));
     // Test for Unavailable/Unconfigured Translators.
     $this->default_translator->setSetting('action', 'not_available');
     $this->default_translator->save();
     $this->drupalGet('admin/tmgmt/jobs/' . $job->id());
     $this->assertText(t('Test provider is not available. Make sure it is properly configured.'));
     $this->drupalPostForm(NULL, array(), t('Submit to provider'));
     $this->assertText(t('@translator is not available. Make sure it is properly configured.', array('@translator' => 'Test provider')));
     // Login as administrator to delete a job.
     $this->loginAsAdmin();
     $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'All')));
     // Translated languages should now be listed as Needs review.
     $start_rows = $this->xpath('//tbody/tr');
     $this->assertEqual(count($start_rows), 5);
     $this->drupalGet($job4->urlInfo('delete-form'));
     $this->assertText('Are you sure you want to delete the translation job test_source:test:11 and 2 more?');
     $this->drupalPostForm(NULL, array(), t('Delete'));
     $this->drupalGet('admin/tmgmt/jobs', array('query' => array('state' => 'All')));
     $end_rows = $this->xpath('//tbody/tr');
     $this->assertEqual(count($end_rows), 4);
 }
 /**
  * Tests the payment UI.
  */
 protected function testPaymentUi()
 {
     $this->drupalPlaceBlock('local_tasks_block');
     $payment_method = Payment::methodManager()->createInstance('payment_test');
     // Create just enough payments for three pages
     $count_payments = 50 * 2 + 1;
     foreach (range(0, $count_payments) as $i) {
         $payment = Generate::createPayment(2, $payment_method);
         $payment->save();
         $payment = entity_load_unchanged('payment', $payment->id());
     }
     // View the administrative listing.
     $this->drupalLogin($this->drupalCreateUser(array('access administration pages')));
     $this->drupalGet('admin/content');
     $this->assertResponse('200');
     $this->assertNoLinkByHref('admin/content/payment');
     $this->drupalGet('admin/content/payment');
     $this->assertResponse('403');
     $this->drupalLogin($this->drupalCreateUser(array('access administration pages', 'payment.payment.view.any')));
     $this->drupalGet('admin/content');
     $this->clickLink(t('Payments'));
     if ($this->assertResponse('200')) {
         $this->assertTitle(t('Payments | Drupal'));
         $this->assertText(t('Last updated'));
         $this->assertText(t('Payment method'));
         $this->assertText(t('Enter a comma separated list of user names.'));
         $this->assertText(t('EUR 24.20'));
         $this->assertText($payment_method->getPluginLabel());
         $count_pages = ceil($count_payments / 50);
         if ($count_pages) {
             foreach (range(1, $count_pages - 1) as $page) {
                 $this->assertLinkByHref('&page=' . $page);
             }
             $this->assertNoLinkByHref('&page=' . ($page + 1));
         }
         $this->assertLinkByHref('payment/1');
         $this->clickLinkPartialName('Next');
         $this->assertUrl('admin/content/payment?changed_after=&changed_before=&=Apply&page=1');
     }
     $this->drupalLogout();
     // View the payment.
     $path = 'payment/' . $payment->id();
     $this->drupalGet($path);
     $this->assertResponse('403');
     $this->drupalLogin($this->drupalCreateUser(array('payment.payment.view.any')));
     $this->drupalGet($path);
     if ($this->assertResponse('200')) {
         $this->assertText(t('Payment method'));
         $this->assertText(t('Status'));
     }
     // Delete a payment.
     $path = 'payment/' . $payment->id() . '/delete';
     $this->drupalGet($path);
     $this->assertResponse('403');
     $this->drupalLogin($this->drupalCreateUser(array('payment.payment.delete.any', 'payment.payment.view.any')));
     $this->drupalGet($path);
     if ($this->assertResponse('200')) {
         $this->clickLink(t('Cancel'));
         $this->assertUrl('payment/' . $payment->id());
         $this->drupalGet($path);
         $this->drupalPostForm(NULL, [], t('Delete'));
         $this->assertResponse('200');
         $this->assertFalse((bool) \Drupal::entityManager()->getStorage('payment')->loadUnchanged($payment->id()));
     }
 }
 /**
  * Save a card on file object
  */
 public function saveCard($card, $billing_profile = NULL, $new_values = array())
 {
     // Remove metadata values
     if (!empty($new_values)) {
         unset($new_values['no_store']);
     }
     // If new card ...
     if (empty($card->card_id)) {
         if (!empty($new_values)) {
             foreach ($new_values as $prop => $new_value) {
                 $card->{$prop} = $new_value;
             }
         }
         // Ensure number is always sanitized
         $card->card_number = !empty($card->card_number) ? substr($card->card_number, -4) : 'XXXX';
         // Save the new card
         return commerce_cardonfile_save($card, $billing_profile);
     }
     // Update to an existing card
     if (empty($new_values)) {
         return 3;
     }
     // Load original card
     $card_original = entity_load_unchanged('commerce_cardonfile', $card->card_id);
     // Detect property changes
     $changes = array();
     foreach ($new_values as $prop => $new_value) {
         if ($card_original->{$prop} != $new_value) {
             $card->{$prop} = $new_value;
             $changes[] = $prop;
         }
     }
     // Detect if billing address changed
     $billing_updated = FALSE;
     if (!empty($billing_profile) && !empty($card->commerce_cardonfile_profile[LANGUAGE_NONE][0]['profile_id'])) {
         if (empty($billing_profile->profile_id) || $billing_profile->profile_id != $card->commerce_cardonfile_profile[LANGUAGE_NONE][0]['profile_id']) {
             $billing_updated = TRUE;
         }
     }
     // No changes
     if (empty($changes) && !$billing_updated) {
         return 3;
     }
     // Create new card if immutable property changed or billing updated
     if (array_intersect($changes, $this->cardImmutableProperties()) || $billing_updated) {
         // Disable the original card
         $card_original->status = 0;
         $card_original->changed = REQUEST_TIME;
         commerce_cardonfile_save($card_original);
         // Save the new card
         unset($card->card_id);
         $card->created = REQUEST_TIME;
         $card->changed = REQUEST_TIME;
     }
     // Ensure number is always sanitized
     $card->card_number = !empty($card->card_number) ? substr($card->card_number, -4) : 'XXXX';
     // Save the updated card
     if ($billing_updated) {
         return commerce_cardonfile_save($card, $billing_profile);
     }
     return commerce_cardonfile_save($card);
 }
 public function save($entity)
 {
     $entity = (object) $entity;
     // Determine if we will be inserting a new entity.
     $entity->is_new = !(isset($entity->fpid) && is_numeric($entity->fpid));
     $transaction = db_transaction();
     // Load the stored entity, if any.
     if (!empty($entity->fpid) && !isset($entity->original)) {
         $entity->original = entity_load_unchanged('fieldable_panels_pane', $entity->fpid);
     }
     // Set the timestamp fields.
     if (empty($entity->created)) {
         $entity->created = REQUEST_TIME;
     }
     // Only change revision timestamp if it doesn't exist.
     if (empty($entity->timestamp)) {
         $entity->timestamp = REQUEST_TIME;
     }
     $entity->changed = REQUEST_TIME;
     field_attach_presave('fieldable_panels_pane', $entity);
     module_invoke_all('fieldable_panels_pane_presave', $entity);
     module_invoke_all('entity_presave', $entity, 'fieldable_panels_pane');
     // When saving a new entity revision, unset any existing $entity->vid
     // to ensure a new revision will actually be created and store the old
     // revision ID in a separate property for entity hook implementations.
     if (!$entity->is_new && !empty($entity->revision) && $entity->vid) {
         $entity->old_vid = $entity->vid;
         unset($entity->vid);
         $entity->timestamp = REQUEST_TIME;
     }
     try {
         if (!$entity->is_new) {
             // Since we already have an fpid, write the revision to ensure the
             // vid is the most up to date, then write the record.
             $this->saveRevision($entity);
             drupal_write_record('fieldable_panels_panes', $entity, 'fpid');
             field_attach_update('fieldable_panels_pane', $entity);
             module_invoke_all('fieldable_panels_pane_update', $entity);
             module_invoke_all('entity_update', $entity, 'fieldable_panels_pane');
         } else {
             // If this is new, write the record first so we have an fpid,
             // then save the revision so that we have a vid. This means we
             // then have to write the vid again.
             drupal_write_record('fieldable_panels_panes', $entity);
             $this->saveRevision($entity);
             db_update('fieldable_panels_panes')->fields(array('vid' => $entity->vid))->condition('fpid', $entity->fpid)->execute();
             field_attach_insert('fieldable_panels_pane', $entity);
             module_invoke_all('fieldable_panels_pane_insert');
             module_invoke_all('entity_insert', $entity, 'fieldable_panels_pane');
         }
         return $entity;
     } catch (Exception $e) {
         $transaction->rollback();
         watchdog_exception('fieldable_panels_pane', $e);
     }
     return FALSE;
 }
Esempio n. 22
0
 /**
  * General test to add a style, add/remove/edit effects to it, then delete it.
  */
 function testStyle()
 {
     $admin_path = 'admin/config/media/image-styles';
     // Setup a style to be created and effects to add to it.
     $style_name = strtolower($this->randomMachineName(10));
     $style_label = $this->randomString();
     $style_path = $admin_path . '/manage/' . $style_name;
     $effect_edits = array('image_resize' => array('width' => 100, 'height' => 101), 'image_scale' => array('width' => 110, 'height' => 111, 'upscale' => 1), 'image_scale_and_crop' => array('width' => 120, 'height' => 121), 'image_crop' => array('width' => 130, 'height' => 131, 'anchor' => 'left-top'), 'image_desaturate' => array(), 'image_rotate' => array('degrees' => 5, 'random' => 1, 'bgcolor' => '#FFFF00'));
     // Add style form.
     $edit = array('name' => $style_name, 'label' => $style_label);
     $this->drupalPostForm($admin_path . '/add', $edit, t('Create new style'));
     $this->assertRaw(t('Style %name was created.', array('%name' => $style_label)));
     // Ensure that the expected entity operations are there.
     $this->drupalGet($admin_path);
     $this->assertLinkByHref($style_path);
     $this->assertLinkByHref($style_path . '/flush');
     $this->assertLinkByHref($style_path . '/delete');
     // Add effect form.
     // Add each sample effect to the style.
     foreach ($effect_edits as $effect => $edit) {
         $edit_data = array();
         foreach ($edit as $field => $value) {
             $edit_data['data[' . $field . ']'] = $value;
         }
         // Add the effect.
         $this->drupalPostForm($style_path, array('new' => $effect), t('Add'));
         if (!empty($edit)) {
             $this->drupalPostForm(NULL, $edit_data, t('Add effect'));
         }
     }
     // Load the saved image style.
     $style = ImageStyle::load($style_name);
     // Ensure that third party settings were added to the config entity.
     // These are added by a hook_image_style_presave() implemented in
     // image_module_test module.
     $this->assertEqual('bar', $style->getThirdPartySetting('image_module_test', 'foo'), 'Third party settings were added to the image style.');
     // Ensure that the image style URI matches our expected path.
     $style_uri_path = $style->url();
     $this->assertTrue(strpos($style_uri_path, $style_path) !== FALSE, 'The image style URI is correct.');
     // Confirm that all effects on the image style have settings that match
     // what was saved.
     $uuids = array();
     foreach ($style->getEffects() as $uuid => $effect) {
         // Store the uuid for later use.
         $uuids[$effect->getPluginId()] = $uuid;
         $effect_configuration = $effect->getConfiguration();
         foreach ($effect_edits[$effect->getPluginId()] as $field => $value) {
             $this->assertEqual($value, $effect_configuration['data'][$field], SafeMarkup::format('The %field field in the %effect effect has the correct value of %value.', array('%field' => $field, '%effect' => $effect->getPluginId(), '%value' => $value)));
         }
     }
     // Assert that every effect was saved.
     foreach (array_keys($effect_edits) as $effect_name) {
         $this->assertTrue(isset($uuids[$effect_name]), format_string('A %effect_name effect was saved with ID %uuid', array('%effect_name' => $effect_name, '%uuid' => $uuids[$effect_name])));
     }
     // Image style overview form (ordering and renaming).
     // Confirm the order of effects is maintained according to the order we
     // added the fields.
     $effect_edits_order = array_keys($effect_edits);
     $order_correct = TRUE;
     $index = 0;
     foreach ($style->getEffects() as $effect) {
         if ($effect_edits_order[$index] != $effect->getPluginId()) {
             $order_correct = FALSE;
         }
         $index++;
     }
     $this->assertTrue($order_correct, 'The order of the effects is correctly set by default.');
     // Test the style overview form.
     // Change the name of the style and adjust the weights of effects.
     $style_name = strtolower($this->randomMachineName(10));
     $style_label = $this->randomMachineName();
     $weight = count($effect_edits);
     $edit = array('name' => $style_name, 'label' => $style_label);
     foreach ($style->getEffects() as $uuid => $effect) {
         $edit['effects[' . $uuid . '][weight]'] = $weight;
         $weight--;
     }
     // Create an image to make sure it gets flushed after saving.
     $image_path = $this->createSampleImage($style);
     $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
     $this->drupalPostForm($style_path, $edit, t('Update style'));
     // Note that after changing the style name, the style path is changed.
     $style_path = 'admin/config/media/image-styles/manage/' . $style_name;
     // Check that the URL was updated.
     $this->drupalGet($style_path);
     $this->assertTitle(t('Edit style @name | Drupal', array('@name' => $style_label)));
     $this->assertResponse(200, format_string('Image style %original renamed to %new', array('%original' => $style->id(), '%new' => $style_name)));
     // Check that the image was flushed after updating the style.
     // This is especially important when renaming the style. Make sure that
     // the old image directory has been deleted.
     $this->assertEqual($this->getImageCount($style), 0, format_string('Image style %style was flushed after renaming the style and updating the order of effects.', array('%style' => $style->label())));
     // Load the style by the new name with the new weights.
     $style = ImageStyle::load($style_name);
     // Confirm the new style order was saved.
     $effect_edits_order = array_reverse($effect_edits_order);
     $order_correct = TRUE;
     $index = 0;
     foreach ($style->getEffects() as $effect) {
         if ($effect_edits_order[$index] != $effect->getPluginId()) {
             $order_correct = FALSE;
         }
         $index++;
     }
     $this->assertTrue($order_correct, 'The order of the effects is correctly set by default.');
     // Image effect deletion form.
     // Create an image to make sure it gets flushed after deleting an effect.
     $image_path = $this->createSampleImage($style);
     $this->assertEqual($this->getImageCount($style), 1, format_string('Image style %style image %file successfully generated.', array('%style' => $style->label(), '%file' => $image_path)));
     // Delete the 'image_crop' effect from the style.
     $this->drupalPostForm($style_path . '/effects/' . $uuids['image_crop'] . '/delete', array(), t('Delete'));
     // Confirm that the form submission was successful.
     $this->assertResponse(200);
     $image_crop_effect = $style->getEffect($uuids['image_crop']);
     $this->assertRaw(t('The image effect %name has been deleted.', array('%name' => $image_crop_effect->label())));
     // Confirm that there is no longer a link to the effect.
     $this->assertNoLinkByHref($style_path . '/effects/' . $uuids['image_crop'] . '/delete');
     // Refresh the image style information and verify that the effect was
     // actually deleted.
     $style = entity_load_unchanged('image_style', $style->id());
     $this->assertFalse($style->getEffects()->has($uuids['image_crop']), format_string('Effect with ID %uuid no longer found on image style %style', array('%uuid' => $uuids['image_crop'], '%style' => $style->label())));
     // Additional test on Rotate effect, for transparent background.
     $edit = array('data[degrees]' => 5, 'data[random]' => 0, 'data[bgcolor]' => '');
     $this->drupalPostForm($style_path, array('new' => 'image_rotate'), t('Add'));
     $this->drupalPostForm(NULL, $edit, t('Add effect'));
     $style = entity_load_unchanged('image_style', $style_name);
     $this->assertEqual(count($style->getEffects()), 6, 'Rotate effect with transparent background was added.');
     // Style deletion form.
     // Delete the style.
     $this->drupalPostForm($style_path . '/delete', array(), t('Delete'));
     // Confirm the style directory has been removed.
     $directory = file_default_scheme() . '://styles/' . $style_name;
     $this->assertFalse(is_dir($directory), format_string('Image style %style directory removed on style deletion.', array('%style' => $style->label())));
     $this->assertFalse(ImageStyle::load($style_name), format_string('Image style %style successfully deleted.', array('%style' => $style->label())));
 }
Esempio n. 23
0
 /**
  * {@inheritdoc}
  */
 public function buildEntity(array $form, FormStateInterface $form_state)
 {
     /** @var \Drupal\tmgmt\JobInterface $job */
     $job = parent::buildEntity($form, $form_state);
     if ($job->hasTranslator()) {
         $translator = $job->getTranslator();
         // If requested custom job settings handling, copy values from original job.
         if ($translator->hasCustomSettingsHandling()) {
             $original_job = entity_load_unchanged('tmgmt_job', $job->id());
             $job->settings = $original_job->settings;
         }
     }
     // Make sure that we always store a label as it can be a slow operation to
     // generate the default label.
     if (empty($job->label)) {
         $job->label = $job->label();
     }
     return $job;
 }