Skip to content
Snippets Groups Projects
Select Git revision
  • 3a27db99bb9d19a5368f959349aa4a19d5725b37
  • 11.x default protected
  • 10.5.x protected
  • 10.6.x protected
  • 11.2.x protected
  • 11.1.x protected
  • 10.4.x protected
  • 11.0.x protected
  • 10.3.x protected
  • 7.x protected
  • 10.2.x protected
  • 10.1.x protected
  • 9.5.x protected
  • 10.0.x protected
  • 9.4.x protected
  • 9.3.x protected
  • 9.2.x protected
  • 9.1.x protected
  • 8.9.x protected
  • 9.0.x protected
  • 8.8.x protected
  • 10.5.2 protected
  • 11.2.3 protected
  • 10.5.1 protected
  • 11.2.2 protected
  • 11.2.1 protected
  • 11.2.0 protected
  • 10.5.0 protected
  • 11.2.0-rc2 protected
  • 10.5.0-rc1 protected
  • 11.2.0-rc1 protected
  • 10.4.8 protected
  • 11.1.8 protected
  • 10.5.0-beta1 protected
  • 11.2.0-beta1 protected
  • 11.2.0-alpha1 protected
  • 10.4.7 protected
  • 11.1.7 protected
  • 10.4.6 protected
  • 11.1.6 protected
  • 10.3.14 protected
41 results

theme.inc

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    ViewsConfigDependenciesIntegrationTest.php 2.02 KiB
    <?php
    
    namespace Drupal\Tests\views\Kernel;
    
    use Drupal\field\Entity\FieldConfig;
    use Drupal\field\Entity\FieldStorageConfig;
    use Drupal\image\Entity\ImageStyle;
    use Drupal\views\Entity\View;
    
    /**
     * Tests integration of views with other modules.
     *
     * @group views
     */
    class ViewsConfigDependenciesIntegrationTest extends ViewsKernelTestBase {
    
      /**
       * {@inheritdoc}
       */
      public static $modules = ['field', 'file', 'image', 'entity_test'];
    
      /**
       * {@inheritdoc}
       */
      public static $testViews = ['entity_test_fields'];
    
      /**
       * Tests integration with image module.
       */
      public function testImage() {
        /** @var \Drupal\image\ImageStyleInterface $style */
        $style = ImageStyle::create(['name' => 'foo']);
        $style->save();
    
        // Create a new image field 'bar' to be used in 'entity_test_fields' view.
        FieldStorageConfig::create([
          'entity_type' => 'entity_test',
          'field_name' => 'bar',
          'type' => 'image',
        ])->save();
        FieldConfig::create([
          'entity_type' => 'entity_test',
          'bundle' => 'entity_test',
          'field_name' => 'bar',
        ])->save();
    
        /** @var \Drupal\views\ViewEntityInterface $view */
        $view = View::load('entity_test_fields');
        $display =& $view->getDisplay('default');
    
        // Add the 'bar' image field to 'entity_test_fields' view.
        $display['display_options']['fields']['bar'] = [
          'id' => 'bar',
          'field' => 'bar',
          'plugin_id' => 'field',
          'table' => 'entity_test__bar',
          'entity_type' => 'entity_test',
          'entity_field' => 'bar',
          'type' => 'image',
          'settings' => ['image_style' => 'foo', 'image_link' => ''],
        ];
        $view->save();
    
        $dependencies = $view->getDependencies() + ['config' => []];
    
        // Checks that style 'foo' is a dependency of view 'entity_test_fields'.
        $this->assertTrue(in_array('image.style.foo', $dependencies['config']));
    
        // Delete the 'foo' image style.
        $style->delete();
    
        // Checks that the view has been deleted too.
        $this->assertNull(View::load('entity_test_fields'));
      }
    
    }