- <?php
- * @file
- * Definition of ViewsHandlerFieldMath.
- */
-
- require_once BACKDROP_ROOT . '/core/modules/views/tests/views_query.test';
-
- * Tests the core views_handler_field_math handler.
- */
- class ViewsHandlerFieldMath extends ViewsSqlTest {
-
-
- * {@inheritdoc}
- */
- protected $profile = 'testing';
-
-
- * {@inheritdoc}
- */
- protected function viewsData() {
- $data = parent::viewsData();
- return $data;
- }
-
-
- * Test basic field functionality.
- */
- protected function testFieldCustom() {
- $view = $this->getBasicView();
-
-
- $rand1 = rand(0, 100);
- $rand2 = rand(0, 100);
- $view->display['default']->handler->override_option('fields', array(
- 'expression' => array(
- 'id' => 'expression',
- 'table' => 'views',
- 'field' => 'expression',
- 'relationship' => 'none',
- 'expression' => $rand1 . ' + ' . $rand2,
- ),
- ));
-
- $this->executeView($view);
-
- $this->assertEqual($rand1 + $rand2, $view->style_plugin->get_field(0, 'expression'));
- }
-
-
- * Test rendering of float values in "Global: Math expression" fields.
- */
- protected function testMathFloatRender() {
-
- $type = $this->backdropCreateContentType();
- $this->backdropCreateNode(array(
- 'type' => $type->type,
- ));
- $view = views_get_view('floatval_check');
- $this->executeView($view);
- $result = $view->result[0];
-
- foreach ($view->field as $name => $view_field) {
- if ($name == 'nid') {
- continue;
- }
-
-
- $label = $view->field[$name]->label();
- $render = $view->field[$name]->advanced_render($result);
- $this->assertIdentical($label, $render, format_string('Expected rendered output to be %label, got %render', array(
- '%label' => $label,
- '%render' => $render,
- )));
- }
- }
-
- }