$renderer =
$this->container->
get('renderer'
);
$view = Views::
getView('test_field_classes'
);
$view->
initHandlers();
// Tests whether the default field classes are added.
$id_field =
$view->field
['id'
];
$id_field->options
['element_default_classes'
] = FALSE;
// Setup some kind of label by default.
$id_field->options
['label'
] =
$this->
randomMachineName();
$output =
$view->
preview();
$output =
$renderer->
renderRoot($output);
$this->
assertEmpty($this->
xpathContent($output, '//div[contains(@class, :class)]',
[':class' => 'field-content'
]));
$this->
assertEmpty($this->
xpathContent($output, '//div[contains(@class, :class)]',
[':class' => 'field__label'
]));
$id_field->options
['element_default_classes'
] = TRUE;
$output =
$view->
preview();
$output =
$renderer->
renderRoot($output);
// Per default the label and the element of the field are spans.
$this->
assertNotEmpty($this->
xpathContent($output, '//span[contains(@class, :class)]',
[':class' => 'field-content'
]));
$this->
assertNotEmpty($this->
xpathContent($output, '//span[contains(@class, :class)]',
[':class' => 'views-label'
]));
$this->
assertNotEmpty($this->
xpathContent($output, '//div[contains(@class, :class)]',
[':class' => 'views-field'
]));