home | career | drupal | java | mac | mysql | perl | php | scala | uml | unix

Drupal example source code file (views_glossary.test)

This example Drupal source code file (views_glossary.test) is included in the DevDaily.com "Drupal Source Code Warehouse" project. The intent of this project is to help you "Learn Drupal by Example".

PHP - Drupal tags/keywords

array, as, count, extends, foreach, function, glossary, nodes_per_char, php, public, setting, type, views

The views_glossary.test Drupal example source code

<?php
// $Id: views_glossary.test,v 1.1.4.4 2010/03/14 11:45:38 dereine Exp $
/**
 * @file
 *   Test glossary view ( summary of arguments )
 */

class ViewsGlossaryTestCase extends ViewsSqlTest {
  public static function getInfo() {
    return array(
      'name' => 'Glossary Test',
      'description' => 'Tests glossary functionality of views.',
      'group' => 'Views',
    );
  }

  public function setUp() {
    parent::setUp('views');
  }

  /**
   * Test the default glossary view.
   */
  public function testGlossaryView() {
    // create a contentype and add some nodes, with a non random title.
    $type = $this->drupalCreateContentType();
    $nodes_per_char = array(
      'd' => 1,
      'r' => 4,
      'u' => 10,
      'p' => 2,
      'a' => 3,
      'l' => 6,
    );
    foreach ($nodes_per_char as $char => $count) {
      $setting = array(
        'type' => $type->type
      );
      for ($i = 0; $i < $count; $i++) {
        $node = $setting;
        $node['title'] = $char . $this->randomString(3);
        $this->drupalCreateNode($node);
      }
    }

    // Execute glossary view
    $view = views_get_view('glossary');
    $view->set_display('attachment');
    $view->execute_display('attachment');

    // Check that the amount of nodes per char.
    $result_nodes_per_char = array();
    foreach ($view->result as $item) {
      $this->assertEqual($nodes_per_char[$item->title_truncated], $item->num_records);
    }
  }
}

Other Drupal examples (source code examples)

Here is a short list of links related to this Drupal views_glossary.test source code file:

new blog posts

"Drupal" is a registered trademark of Dries Buytaert.

my drupal tutorials and examples  

Copyright 1998-2016 Alvin Alexander, alvinalexander.com
All Rights Reserved.

Beginning in 2016, a portion of the proceeds from pages under the '/drupal-code-examples/' URI will be donated to charity.