예제 #1
0
 /**
  * Tests the creation of entity_browser.
  */
 protected function createTests()
 {
     $plugin = ['name' => 'test_browser', 'label' => 'Testing entity browser instance', 'display' => 'standalone', 'display_configuration' => ['path' => 'test-browser-test'], 'selection_display' => 'no_display', 'selection_display_configuration' => [], 'widget_selector' => 'single', 'widget_selector_configuration' => [], 'widgets' => [$this->widgetUUID => ['id' => 'view', 'label' => 'View widget', 'uuid' => $this->widgetUUID, 'weight' => 0, 'settings' => ['view' => 'test_view', 'view_display' => 'test_display']]]];
     foreach (['display' => 'getDisplay', 'selection_display' => 'getSelectionDisplay', 'widget_selector' => 'getWidgetSelector'] as $plugin_type => $function_name) {
         $current_plugin = $plugin;
         unset($current_plugin[$plugin_type]);
         // Attempt to create an entity_browser without required plugin.
         try {
             $entity = $this->controller->create($current_plugin);
             $entity->{$function_name}();
             $this->fail('An entity browser without required ' . $plugin_type . ' created with no exception thrown.');
         } catch (PluginException $e) {
             $this->assertEquals('The "" plugin does not exist.', $e->getMessage(), 'An exception was thrown when an entity_browser was created without a ' . $plugin_type . ' plugin.');
         }
     }
     // Try to create an entity browser w/o the ID.
     $current_plugin = $plugin;
     unset($current_plugin['name']);
     try {
         $entity = $this->controller->create($current_plugin);
         $entity->save();
         $this->fail('An entity browser without required name created with no exception thrown.');
     } catch (EntityMalformedException $e) {
         $this->assertEquals('The entity does not have an ID.', $e->getMessage(), 'An exception was thrown when an entity_browser was created without a name.');
     }
     // Create an entity_browser with required values.
     $entity = $this->controller->create($plugin);
     $entity->save();
     $this->assertTrue($entity instanceof EntityBrowserInterface, 'The newly created entity is an Entity browser.');
     // Verify all of the properties.
     $actual_properties = $this->container->get('config.factory')->get('entity_browser.browser.test_browser')->get();
     $this->assertTrue(!empty($actual_properties['uuid']), 'The entity browser UUID is set.');
     unset($actual_properties['uuid']);
     // Ensure that default values are filled in.
     $expected_properties = ['langcode' => $this->container->get('language_manager')->getDefaultLanguage()->getId(), 'status' => TRUE, 'dependencies' => [], 'name' => 'test_browser', 'label' => 'Testing entity browser instance', 'display' => 'standalone', 'display_configuration' => ['path' => 'test-browser-test'], 'selection_display' => 'no_display', 'selection_display_configuration' => [], 'widget_selector' => 'single', 'widget_selector_configuration' => [], 'widgets' => [$this->widgetUUID => ['id' => 'view', 'label' => 'View widget', 'uuid' => $this->widgetUUID, 'weight' => 0, 'settings' => ['view' => 'test_view', 'view_display' => 'test_display']]]];
     $this->assertEquals($actual_properties, $expected_properties, 'Actual config properties are structured as expected.');
     // Ensure that rebuilding routes works.
     $route = $this->routeProvider->getRoutesByPattern('/test-browser-test');
     $this->assertTrue($route, 'Route exists.');
 }
 /**
  * Tests the creation of blocks.
  */
 protected function createTests()
 {
     // Attempt to create a block without a plugin.
     try {
         $entity = $this->controller->create(array());
         $entity->getPlugin();
         $this->fail('A block without a plugin was created with no exception thrown.');
     } catch (PluginException $e) {
         $this->assertEqual('The block \'\' did not specify a plugin.', $e->getMessage(), 'An exception was thrown when a block was created without a plugin.');
     }
     // Create a block with only required values.
     $entity = $this->controller->create(array('id' => 'test_block', 'theme' => 'stark', 'plugin' => 'test_html'));
     $entity->save();
     $this->assertTrue($entity instanceof Block, 'The newly created entity is a Block.');
     // Verify all of the block properties.
     $actual_properties = $this->config('block.block.test_block')->get();
     $this->assertTrue(!empty($actual_properties['uuid']), 'The block UUID is set.');
     unset($actual_properties['uuid']);
     // Ensure that default values are filled in.
     $expected_properties = array('langcode' => \Drupal::languageManager()->getDefaultLanguage()->getId(), 'status' => TRUE, 'dependencies' => array('module' => array('block_test'), 'theme' => array('stark')), 'id' => 'test_block', 'theme' => 'stark', 'region' => '-1', 'weight' => NULL, 'provider' => NULL, 'plugin' => 'test_html', 'settings' => array('id' => 'test_html', 'label' => '', 'provider' => 'block_test', 'label_display' => BlockInterface::BLOCK_LABEL_VISIBLE), 'visibility' => array());
     $this->assertIdentical($actual_properties, $expected_properties);
     $this->assertTrue($entity->getPlugin() instanceof TestHtmlBlock, 'The entity has an instance of the correct block plugin.');
 }
예제 #3
0
  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $this->container->get('entity_type.manager');
    $this->cropStorage = $entity_type_manager->getStorage('crop');
    $this->cropTypeStorage = $entity_type_manager->getStorage('crop_type');
    $this->imageStyleStorage = $entity_type_manager->getStorage('image_style');
    $this->fileStorage = $entity_type_manager->getStorage('file');

    // Create DB schemas.
    /** @var \Drupal\Core\Entity\EntityTypeListenerInterface $entity_type_listener */
    $entity_type_listener = $this->container->get('entity_type.listener');
    $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('user'));
    $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('image_style'));
    $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('crop'));
    $entity_type_listener->onEntityTypeCreate($entity_type_manager->getDefinition('file'));

    // Create test image style.
    $uuid = $this->container->get('uuid')->generate();
    $this->testStyle = $this->imageStyleStorage->create([
      'name' => 'test',
      'label' => 'Test image style',
      'effects' => [
        $uuid => [
          'id' => 'crop_crop',
          'data' => ['crop_type' => 'test_type'],
          'weight' => 0,
          'uuid' => $uuid,
        ]
      ],
    ]);
    $this->testStyle->save();

    // Create test crop type.
    $this->cropType = $this->cropTypeStorage->create([
      'id' => 'test_type',
      'label' => 'Test crop type',
      'description' => 'Some nice desc.',
    ]);
    $this->cropType->save();
  }