You are here

panelizer.admin_settings.test in Panelizer 7.3

Test the admin functionality for Panelizer.

File

tests/panelizer.admin_settings.test
View source
<?php

/**
 * @file
 * Test the admin functionality for Panelizer.
 */

/**
 * Test file administration page functionality.
 */
class PanelizerAdminTest extends PanelizerTestHelper {

  /**
   * {@inheritdoc}
   */
  public static function getInfo() {
    return array(
      'name' => 'Panelizer administration',
      'description' => 'Test panelizer administration page functionality.',
      'group' => 'Panelizer',
    );
  }

  /**
   * {@inheritdoc}
   */
  function setUp(array $modules = array()) {
    parent::setUp();
    $perms = array(
      'administer panelizer',
    );
    $admin_user = $this
      ->drupalCreateUser($perms);
    $this
      ->drupalLogin($admin_user);
  }

  /**
   * Tests panelizer overview with different entities.
   */
  function testPanelizerAdminPages() {
    $this
      ->drupalGet('admin/structure/panelizer');
    $edit = array();
    $entity_plugins = panelizer_get_entity_plugins();
    foreach ($entity_plugins as $entity_type => $plugin) {
      $entity_info = entity_get_info($entity_type);
      if ($entity_info) {
        $bundles = $entity_info['bundles'];
        foreach ($bundles as $bundle => $info) {
          $this
            ->assertFieldByXPath('//input[@type="checkbox" and @name="entities[' . $entity_type . '][' . $bundle . '][0][status]"]', FALSE, t('The %bundle bundle of the %entity_type entity type can be panelized.', array(
            '%bundle' => $bundle,
            '%entity_type' => $entity_type,
          )));

          // Collect a list of all of the available entity types + bundles.
          $edit['entities[' . $entity_type . '][' . $bundle . '][0][status]'] = TRUE;
        }
      }
    }

    // Panelize all of the known entity types and their bundles.
    $this
      ->drupalPost('admin/structure/panelizer', $edit, t('Save'));

    // Reset the ctools plugins static cache to include the newly panelized
    // entity types.
    ctools_get_plugins_reset();
    $entity_plugins = panelizer_get_entity_plugins();
    foreach ($entity_plugins as $entity_type => $plugin) {
      $entity_info = entity_get_info($entity_type);
      if ($entity_info) {
        $bundles = $entity_info['bundles'];
        foreach ($bundles as $bundle => $info) {
          if (!empty($plugin['bundles'][$bundle]['status'])) {
            if (!empty($info['admin']['real path'])) {
              $this
                ->assertLinkByHref($info['admin']['real path'] . '/display', 0, t('A link to manage the display for the %bundle bundle of the %entity_type entity type appears on the page.', array(
                '%bundle' => $bundle,
                '%entity_type' => $entity_type,
              )));
            }
            $this
              ->assertLinkByHref('admin/structure/panelizer/' . $entity_type . '/' . $bundle . '/allowed', 0, t('A link to restrict the allowed content for the %bundle bundle of the %entity_type entity type appears on the page.', array(
              '%bundle' => $bundle,
              '%entity_type' => $entity_type,
            )));
          }
          foreach ($plugin['view modes'] as $view_mode => $view_mode_info) {

            // Automatically allow view modes that are part of Panels.
            if (isset($entity_info['view modes'][$view_mode])) {

              // Skip this view mode if it isn't enabled for this bundle.
              if (!empty($bundle)) {
                if (empty($view_mode_settings[$view_mode]['custom_settings'])) {
                  continue;
                }
              }
              else {
                if (isset($entity_info['view modes'][$view_mode]['custom settings']) && empty($entity_info['view modes'][$view_mode]['custom settings'])) {
                  continue;
                }
              }
            }
            if (isset($plugin['view mode status'][$bundle][$view_mode]) && empty($plugin['view mode status'][$bundle][$view_mode])) {

              // continue;
            }
            if (!empty($plugin['bundles'][$bundle]['view modes'][$view_mode]) && is_array($plugin['bundles'][$bundle]['view modes'][$view_mode])) {
              $settings = $plugin['bundles'][$bundle]['view modes'][$view_mode];
            }
            else {
              $settings = array(
                'status' => FALSE,
                'default' => FALSE,
                'choice' => FALSE,
              );
            }
            $this
              ->assertFieldByXPath('//input[@type="checkbox" and @name="entities[' . $entity_type . '][' . $bundle . '][' . $view_mode . '][status]"]', !empty($settings['status']), t('The %view_mode view mode of the %bundle bundle of the %entity_type entity type can be panelized.', array(
              '%view_mode' => $view_mode,
              '%bundle' => $bundle,
              '%entity_type' => $entity_type,
            )));
          }
        }
      }
    }
  }

}

Classes

Namesort descending Description
PanelizerAdminTest Test file administration page functionality.