/** * Tests storage methods. */ public function testStorageMethods() { $entity_type = \Drupal::entityManager()->getDefinition('config_test'); // Test the static extractID() method. $expected_id = 'test_id'; $config_name = $entity_type->getConfigPrefix() . '.' . $expected_id; $storage = $this->storage; $this->assertIdentical($storage::getIDFromConfigName($config_name, $entity_type->getConfigPrefix()), $expected_id); // Create three entities, two with the same style. $style = $this->randomMachineName(8); for ($i = 0; $i < 2; $i++) { $entity = $this->storage->create(array('id' => $this->randomMachineName(), 'label' => $this->randomString(), 'style' => $style)); $entity->save(); } $entity = $this->storage->create(array('id' => $this->randomMachineName(), 'label' => $this->randomString(), 'style' => $this->randomMachineName(9))); $entity->save(); // Ensure that the configuration entity can be loaded by UUID. $entity_loaded_by_uuid = entity_load_by_uuid($entity_type->id(), $entity->uuid()); if (!$entity_loaded_by_uuid) { $this->fail(sprintf("Failed to load '%s' entity ID '%s' by UUID '%s'.", $entity_type->id(), $entity->id(), $entity->uuid())); } // Compare UUIDs as the objects are not identical since // $entity->enforceIsNew is FALSE and $entity_loaded_by_uuid->enforceIsNew // is NULL. $this->assertIdentical($entity->uuid(), $entity_loaded_by_uuid->uuid()); $entities = $this->storage->loadByProperties(); $this->assertEqual(count($entities), 3, 'Three entities are loaded when no properties are specified.'); $entities = $this->storage->loadByProperties(array('style' => $style)); $this->assertEqual(count($entities), 2, 'Two entities are loaded when the style property is specified.'); // Assert that both returned entities have a matching style property. foreach ($entities as $entity) { $this->assertIdentical($entity->get('style'), $style, 'The loaded entity has the correct style value specified.'); } }
/** * Tests whether creating an index works correctly. * * @return \Drupal\search_api\IndexInterface * The newly created search index. */ public function indexCreate() { $indexData = array('id' => $this->randomMachineName(), 'name' => $this->randomString(), 'tracker' => 'default'); $index = $this->storage->create($indexData); $this->assertTrue($index instanceof IndexInterface, 'The newly created entity is a search index.'); $index->save(); return $index; }
/** * Tests whether creating an index works correctly. * * @return \Drupal\search_api\IndexInterface * The newly created search index. */ protected function indexCreate() { $indexData = array('id' => 'test', 'name' => 'Index test name'); $index = $this->storage->create($indexData); $this->assertTrue($index instanceof IndexInterface, 'The newly created entity is a search index.'); $index->save(); return $index; }
/** * Tests whether creating a server works correctly. * * @return \Drupal\search_api\ServerInterface * The newly created search server. */ public function serverCreate() { $serverData = array('id' => 'test_server', 'name' => 'Test server', 'backend' => 'search_api_test_backend'); $server = $this->storage->create($serverData); $this->assertTrue($server instanceof ServerInterface, 'The newly created entity is a Search API Server.'); $server->save(); return $server; }
/** * {@inheritdoc} */ public function importEntities(array $country_codes) { foreach ($country_codes as $country_code) { $address_format = $this->externalRepository->get($country_code); $values = ['langcode' => 'en', 'countryCode' => $address_format->getCountryCode(), 'format' => $address_format->getFormat(), 'requiredFields' => $address_format->getRequiredFields(), 'uppercaseFields' => $address_format->getUppercaseFields(), 'administrativeAreaType' => $address_format->getAdministrativeAreaType(), 'localityType' => $address_format->getLocalityType(), 'dependentLocalityType' => $address_format->getDependentLocalityType(), 'postalCodeType' => $address_format->getPostalCodeType(), 'postalCodePattern' => $address_format->getPostalCodePattern(), 'postalCodePrefix' => $address_format->getPostalCodePrefix()]; $entity = $this->storage->create($values); $entity->trustData()->save(); } }
/** * Tests whether creating a server works correctly. * * @return \Drupal\search_api\ServerInterface * The newly created search server. */ public function serverCreate() { $serverData = array('id' => 'test_server', 'name' => 'Test server', 'backend' => 'search_api_test_backend'); $server = $this->storage->create($serverData); $this->assertTrue($server instanceof ServerInterface, 'The newly created entity is a Search API Server.'); $server->save(); $key = 'search_api_test_backend.methods_called.' . $server->id(); $methods_called = \Drupal::state()->get($key, array()); $this->assertNotContains('preUpdate', $methods_called, 'Backend::preUpdate() not called for initial save.'); $this->assertNotContains('postUpdate', $methods_called, 'Backend::postUpdate() not called for initial save.'); return $server; }
/** * Tests block render cache handling. */ public function testBlockViewBuilderCache() { // Verify cache handling for a non-empty block. $this->verifyRenderCacheHandling(); // Create an empty block. $this->block = $this->controller->create(array('id' => 'test_block', 'theme' => 'stark', 'plugin' => 'test_cache')); $this->block->save(); \Drupal::state()->set('block_test.content', NULL); // Verify cache handling for an empty block. $this->verifyRenderCacheHandling(); }