CurrencyViewsHandlerFieldWebTestCase.test in Currency 7.2
Contains class CurrencyViewsHandlerFieldWebTestCase.
File
currency/tests/CurrencyViewsHandlerFieldWebTestCase.testView source
<?php
/**
* @file
* Contains class CurrencyViewsHandlerFieldWebTestCase.
*/
/**
* Tests CurrencyAmountViewsHandlerField.
*/
class CurrencyViewsHandlerFieldWebTestCase extends ViewsSqlTest {
/**
* Implements DrupalTestCase::getInfo().
*/
static function getInfo() {
return array(
'description' => '',
'name' => 'CurrencyViewsFieldHandler',
'group' => 'Currency',
'dependencies' => array(
'views',
),
);
}
/**
* Overrides parent::setUp().
*/
function setUp() {
$this->profile = 'testing';
parent::setUp();
module_enable(array(
'currency',
'views',
));
}
/**
* Overrides parent::schemaDefinition.
*/
protected function schemaDefinition() {
$schema['views_test'] = array(
'fields' => array(
'currency_code' => array(
'type' => 'varchar',
'length' => '3',
),
),
);
return $schema;
}
/**
* Overrides parent::viewsData();
*/
function viewsData() {
// Declaration of the base table.
$data['views_test']['table'] = array(
'group' => t('Views test'),
'base' => array(
'field' => 'id',
'title' => t('Views test'),
),
);
// Declaration of fields.
$data['views_test']['currency_sign'] = array(
'real field' => 'currency_code',
'title' => t('Currency code'),
'help' => t('Currency code'),
'field' => array(
'handler' => 'CurrencyViewsHandlerField',
'currency_property' => 'sign',
),
);
$data['views_test']['currency_subunits'] = array(
'real field' => 'currency_code',
'title' => t('Currency code'),
'help' => t('Currency code'),
'field' => array(
'handler' => 'CurrencyViewsHandlerField',
'currency_property' => 'subunits',
),
);
return $data;
}
/**
* Overrides parent::dataSet();
*/
protected function dataSet() {
return array(
array(
'currency_code' => 'EUR',
),
);
}
/**
* Overrides parent::getBasicView().
*/
protected function getBasicView() {
views_include('view');
// Create the basic view.
$view = new view();
$view->name = 'test_view';
$view
->add_display('default');
$view->base_table = 'views_test';
// Set up the fields we need.
$display = $view
->new_display('default', 'Master', 'default');
$display
->override_option('fields', array(
'currency_sign' => array(
'id' => 'currency_sign',
'table' => 'views_test',
'field' => 'currency_sign',
'relationship' => 'none',
),
'currency_subunits' => array(
'id' => 'currency_subunits',
'table' => 'views_test',
'field' => 'currency_subunits',
'relationship' => 'none',
),
));
return $view;
}
/**
* Tests CurrencyAmountViewsHandlerField.
*/
public function testCurrencyAmountViewsHandlerField() {
$view = $this
->getBasicView();
$view
->save();
// Test view display.
$view = views_get_view($view->name);
$this
->executeView($view);
$this
->assertEqual($view->field['currency_sign']
->advanced_render($view->result[0]), '€');
$this
->assertEqual($view->field['currency_subunits']
->advanced_render($view->result[0]), '100');
}
}
Classes
Name | Description |
---|---|
CurrencyViewsHandlerFieldWebTestCase | Tests CurrencyAmountViewsHandlerField. |