Project

General

Profile

Paste
Download (4 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / file_entity / file_entity_views.test @ a8cee257

1
<?php
2

    
3
/**
4
 * @file
5
 * Definition of FileEntityViewsFieldLinkUsageHandlerTest.
6
 */
7

    
8
/**
9
 * Tests for file_entity views file usage handlers.
10
 */
11
class FileEntityViewsFieldLinkUsageHandlerTest extends FileEntityTestHelper {
12

    
13
  /**
14
   * {@inheritdoc}
15
   */
16
  public function setUp() {
17
    parent::setUp('views');
18
  }
19

    
20
  /**
21
   * {@inheritdoc}
22
   */
23
  public static function getInfo() {
24
    return array(
25
      'name' => 'File entity views integration: file link usage',
26
      'description' => 'Test file usage Views field.',
27
      'group' => 'File entity',
28
    );
29
  }
30

    
31
  /**
32
   * Test views file usage handlers.
33
   */
34
  public function testViewsUsageField() {
35
    $file = $this->createFileEntity();
36
    file_usage_add($file, 'foo', 'bar', 1,1);
37
    file_usage_add($file, 'foo', 'bar', 1,2);
38
    $file2 = $this->createFileEntity();
39
    file_usage_add($file2, 'foo', 'bar', 1, 99);
40

    
41
    $view = $this->getTestView();
42
    $view->set_display();
43
    $view->pre_execute();
44
    $view->execute();
45

    
46
    $row = $view->result[0];
47
    $render = $view->field['usage']->render_link($row, $row);
48
    $this->assertEqual($render, '1 place');
49

    
50
    $row = $view->result[1];
51
    $render = $view->field['usage']->render_link($row, $row);
52
    $this->assertEqual($render, '1 place');
53

    
54
    $view->field['usage']->options['count_entities_once'] = 0;
55

    
56
    $row = $view->result[0];
57
    $render = $view->field['usage']->render_link($row, $row);
58
    $this->assertEqual($render, '3 places');
59

    
60
    $row = $view->result[1];
61
    $render = $view->field['usage']->render_link($row, $row);
62
    $this->assertEqual($render, '99 places');
63
  }
64

    
65
  /**
66
   * Creates a test view containing a file usage field.
67
   */
68
  protected function getTestView() {
69
    $view = new view();
70
    $view->name = 'file_list';
71
    $view->description = '';
72
    $view->tag = 'default';
73
    $view->base_table = 'file_managed';
74
    $view->human_name = 'File List';
75
    $view->core = 7;
76
    $view->api_version = '3.0';
77
    $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
78

    
79
    /* Display: Master */
80
    $handler = $view->new_display('default', 'Master', 'default');
81
    $handler->display->display_options['title'] = 'File List';
82
    $handler->display->display_options['use_more_always'] = FALSE;
83
    $handler->display->display_options['access']['type'] = 'perm';
84
    $handler->display->display_options['cache']['type'] = 'none';
85
    $handler->display->display_options['query']['type'] = 'views_query';
86
    $handler->display->display_options['exposed_form']['type'] = 'basic';
87
    $handler->display->display_options['pager']['type'] = 'none';
88
    $handler->display->display_options['style_plugin'] = 'default';
89
    $handler->display->display_options['row_plugin'] = 'fields';
90
    /* Field: File: Name */
91
    $handler->display->display_options['fields']['filename']['id'] = 'filename';
92
    $handler->display->display_options['fields']['filename']['table'] = 'file_managed';
93
    $handler->display->display_options['fields']['filename']['field'] = 'filename';
94
    $handler->display->display_options['fields']['filename']['label'] = '';
95
    $handler->display->display_options['fields']['filename']['alter']['word_boundary'] = FALSE;
96
    $handler->display->display_options['fields']['filename']['alter']['ellipsis'] = FALSE;
97
    /* Field: File: Usage link */
98
    $handler->display->display_options['fields']['usage']['id'] = 'usage';
99
    $handler->display->display_options['fields']['usage']['table'] = 'file_managed';
100
    $handler->display->display_options['fields']['usage']['field'] = 'usage';
101
    $handler->display->display_options['fields']['usage']['count_entities_once'] = 1;
102
    /* Field: File Usage: Use count */
103
    $handler->display->display_options['fields']['count']['id'] = 'count';
104
    $handler->display->display_options['fields']['count']['table'] = 'file_usage';
105
    $handler->display->display_options['fields']['count']['field'] = 'count';
106

    
107
    /* Display: Page */
108
    $handler = $view->new_display('page', 'Page', 'page');
109
    $handler->display->display_options['path'] = 'file-list';
110

    
111
    return $view;
112
  }
113

    
114
}