StyleUnformattedTest.php 1.73 KB
Newer Older
merlinofchaos's avatar
merlinofchaos committed
1 2 3 4
<?php

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

8
namespace Drupal\views\Tests\Plugin;
9

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

  public static function getInfo() {
    return array(
17
      'name' => 'Style: Unformatted',
merlinofchaos's avatar
merlinofchaos committed
18 19 20 21 22 23 24 25 26
      'description' => 'Test unformatted style functionality.',
      'group' => 'Views Plugins',
    );
  }

  /**
   * Take sure that the default css classes works as expected.
   */
  function testDefaultRowClasses() {
27
    $view = $this->getView();
merlinofchaos's avatar
merlinofchaos committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
    $rendered_output = $view->preview();
    $this->storeViewPreview($rendered_output);

    $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];
      // Take sure that each row has a row css class.
      $this->assertTrue(strpos($class, "views-row-$count") !== FALSE, 'Take sure that each row has a row css class.');
      // Take sure that the odd/even classes are set right.
      $odd_even = $count % 2 == 0 ? 'even' : 'odd';
      $this->assertTrue(strpos($class, "views-row-$odd_even") !== FALSE, 'Take sure that the odd/even classes are set right.');

      if ($count == 1) {
        $this->assertTrue(strpos($class, "views-row-first") !== FALSE, 'Take sure that the first class is set right.');
      }
47
      elseif ($count == $count_result) {
merlinofchaos's avatar
merlinofchaos committed
48 49 50 51 52 53 54 55
        $this->assertTrue(strpos($class, "views-row-last") !== FALSE, 'Take sure that the last class is set right.');

      }
      $this->assertTrue(strpos($class, 'views-row') !== FALSE, 'Take sure that the views row class is set right.');
    }
  }

}