StyleUnformattedTest.php 1.9 KB
Newer Older
Earl Miles's avatar
Earl Miles committed
1
2
3
4
<?php

/**
 * @file
5
 * Definition of Drupal\views\Tests\Plugin\StyleUnformattedTest.
Earl Miles's avatar
Earl Miles committed
6
7
 */

8
namespace Drupal\views\Tests\Plugin;
9

10
11
use Drupal\views\Views;

Earl Miles's avatar
Earl Miles committed
12
13
14
/**
 * Tests the default/unformatted row style.
 */
15
class StyleUnformattedTest extends StyleTestBase {
Earl Miles's avatar
Earl Miles committed
16

17
18
19
20
21
22
23
  /**
   * Views used by this test.
   *
   * @var array
   */
  public static $testViews = array('test_view');

Earl Miles's avatar
Earl Miles committed
24
25
  public static function getInfo() {
    return array(
26
      'name' => 'Style: Unformatted',
Earl Miles's avatar
Earl Miles committed
27
28
29
30
31
32
      'description' => 'Test unformatted style functionality.',
      'group' => 'Views Plugins',
    );
  }

  /**
33
   * Make sure that the default css classes works as expected.
Earl Miles's avatar
Earl Miles committed
34
35
   */
  function testDefaultRowClasses() {
36
    $view = Views::getView('test_view');
37
    $view->setDisplay();
38
39
    $output = $view->preview();
    $this->storeViewPreview(drupal_render($output));
Earl Miles's avatar
Earl Miles committed
40
41
42
43
44
45
46
47

    $rows = $this->elements->body->div->div->div;
    $count = 0;
    $count_result = count($view->result);
    foreach ($rows as $row) {
      $count++;
      $attributes = $row->attributes();
      $class = (string) $attributes['class'][0];
48
49
50
      // Make sure that each row has a row css class.
      $this->assertTrue(strpos($class, "views-row-$count") !== FALSE, 'Make sure that each row has a row css class.');
      // Make sure that the odd/even classes are set right.
Earl Miles's avatar
Earl Miles committed
51
      $odd_even = $count % 2 == 0 ? 'even' : 'odd';
52
      $this->assertTrue(strpos($class, "views-row-$odd_even") !== FALSE, 'Make sure that the odd/even classes are set right.');
Earl Miles's avatar
Earl Miles committed
53
54

      if ($count == 1) {
55
        $this->assertTrue(strpos($class, "views-row-first") !== FALSE, 'Make sure that the first class is set right.');
Earl Miles's avatar
Earl Miles committed
56
      }
57
      elseif ($count == $count_result) {
58
        $this->assertTrue(strpos($class, "views-row-last") !== FALSE, 'Make sure that the last class is set right.');
Earl Miles's avatar
Earl Miles committed
59
60

      }
61
      $this->assertTrue(strpos($class, 'views-row') !== FALSE, 'Make sure that the views row class is set right.');
Earl Miles's avatar
Earl Miles committed
62
63
64
65
    }
  }

}