templateInt = new TemplateInt(); $this->templateInt->importable = "true"; $this->templateInt->label = "LBL_TEST"; $this->templateInt->name = "bug_c"; $this->templateInt->no_default = 1; $this->templateInt->reportable = "1"; $this->templateInt->supports_unified_search = true; $this->templateInt->vname = $this->templateInt->label; $this->bean = new SugarBean(); $this->javascript = new javascript56694(); $this->javascript->setSugarBean($this->bean); } /** * Test asserts that after addField call validator is not added * * @group 56694 */ public function testAddFieldForFieldWithoutValidator() { $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def(); $this->javascript->addField($this->templateInt->name, $this->templateInt->required); $this->assertEmpty($this->javascript->getData(), 'Validator is added'); } /** * Test asserts that after addField call validator is added with empty values * * @group 56694 */ public function testAddFieldForFieldWithoutRealValidator() { $this->templateInt->min = 5; $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def(); $this->bean->field_name_map[$this->templateInt->name]['validation']['min'] = null; $this->bean->field_name_map[$this->templateInt->name]['validation']['max'] = null; $this->javascript->addField($this->templateInt->name, $this->templateInt->required); $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added'); $actual = $this->javascript->getData(); $this->assertSame(array(false, false), $actual, 'Values are incorrect'); } /** * Test asserts that after addField call validator is added only for min value, max value should be false * * @group 56694 */ public function testAddFieldForFieldWithMinOnly() { $this->templateInt->min = 5; $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def(); $this->javascript->addField($this->templateInt->name, $this->templateInt->required); $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added'); $actual = $this->javascript->getData(); $this->assertSame(array($this->templateInt->min,false), $actual, 'Values are incorrect'); } /** * Test asserts that after addField call validator is added only to max value, min value should be false * * @group 56694 */ public function testAddFieldForFieldWithMaxOnly() { $this->templateInt->max = 5; $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def(); $this->javascript->addField($this->templateInt->name, $this->templateInt->required); $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added'); $actual = $this->javascript->getData(); $this->assertSame(array(false, $this->templateInt->max), $actual, 'Values are incorrect'); } /** * Test asserts that after addField call validator is added with both values * * @group 56694 */ public function testAddFieldForFieldWithMaxMin() { $this->templateInt->min = 5; $this->templateInt->max = 6; $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def(); $this->javascript->addField($this->templateInt->name, $this->templateInt->required); $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added'); $actual = $this->javascript->getData(); $this->assertEquals(array($this->templateInt->min, $this->templateInt->max), $actual, 'Values are incorrect'); } /** * Test asserts that after addField call validator added to both values and has min value, because of min value more than max * * @group 56694 */ public function testAddFieldForFieldWithInvertedMaxMin() { $this->templateInt->min = 6; $this->templateInt->max = 5; $this->bean->field_name_map[$this->templateInt->name] = $this->templateInt->get_field_def(); $this->javascript->addField($this->templateInt->name, $this->templateInt->required); $this->assertNotEmpty($this->javascript->getData(), 'Validator is not added'); $actual = $this->javascript->getData(); $this->assertSame(array($this->templateInt->min, $this->templateInt->min), $actual, 'Min value is incorrect'); } } /** * Mock of javascript class */ class javascript56694 extends javascript { /** * @var array */ protected $data = array(); /** * @return array */ public function getData() { return $this->data; } public function addFieldRange($field, $type, $displayName, $required, $prefix = '', $min, $max) { $this->data = array($min, $max); } }