Source of file RangeFieldTest.php
Size: 6,619 Bytes - Last Modified: 2021-12-24T06:47:32+00:00
/var/www/docs.ssmods.com/process/src/tests/unit/RangeFieldTest.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 | <?php namespace Firesphere\RangeField\Tests; use Firesphere\RangeField\RangeField; use SilverStripe\Dev\SapphireTest; class RangeFieldTest extends SapphireTest { public function testDefault() { $field = RangeField::create('Test', 'Test'); $this->assertEquals([0], $field->getStart()); $this->assertEquals(0, $field->getMin()); $this->assertEquals(100, $field->getMax()); $this->assertFalse($field->isSnap()); $this->assertEquals([], $field->getRange()); $this->assertEquals(2, $field->getdecimalPlaces()); $this->assertEquals('', $field->getUnit()); } public function testRange() { $rangeField = RangeField::create( 'TestInt', 'Test', 50, 25, 75, ['min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75] ); $rangeField->Field([]); $expected = [ 'start' => [50], 'snap' => false, 'animate' => true, 'animationDuration' => 300, 'range' => [ 'min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75 ], 'unit' => '', 'decimalPlaces' => 2, 'pips' => [ // Show a scale with the slider 'mode' => 'steps', 'stepped' => true, 'density' => 4 ] ]; $this->assertEquals($expected, $rangeField->getData()); } public function testSnap() { $rangeField = RangeField::create( 'TestInt', 'Test', 50, 25, 75, ['min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75] ); $rangeField->setSnap(true); $rangeField->Field([]); $expected = [ 'start' => [50], 'snap' => true, 'animate' => true, 'animationDuration' => 300, 'range' => [ 'min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75 ], 'pips' => [ // Show a scale with the slider 'mode' => 'steps', 'stepped' => true, 'density' => 4 ], 'unit' => '', 'decimalPlaces' => 2, ]; $this->assertEquals($expected, $rangeField->getData()); $rangeField->setStep(1); $rangeField->Field([]); $expected = [ 'start' => [50], 'snap' => true, 'animate' => true, 'animationDuration' => 300, 'step' => 1, 'range' => [ 'min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75 ], 'pips' => [ // Show a scale with the slider 'mode' => 'steps', 'stepped' => true, 'density' => 4 ], 'unit' => '', 'decimalPlaces' => 2, ]; $this->assertEquals($expected, $rangeField->getData()); } public function testGetSetMin() { $field = RangeField::create('Test', 'Test'); $field->setMin(10); $this->assertEquals(10, $field->getMin()); } public function testGetSetStep() { $field = RangeField::create('Test', 'Test'); $this->assertNull($field->getStep()); $field->setStep(10); $this->assertEquals(10, $field->getStep()); } public function testGetSetMax() { $field = RangeField::create('Test', 'Test'); $field->setMax(10); $this->assertEquals(10, $field->getMax()); } public function testGetSetRange() { $field = RangeField::create('Test', 'Test'); $this->assertEquals([], $field->getRange()); $field->setRange([ 'min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75 ]); $this->assertEquals([ 'min' => 25, '17%' => 33, '50%' => 50, '83%' => 66, 'max' => 75 ], $field->getRange()); } public function testGetSetDensity() { $field = RangeField::create('Test', 'Test'); $this->assertEquals(4, $field->getDensity()); $field->setDensity(10); $this->assertEquals(10, $field->getDensity()); } public function testIsSetPips() { $field = RangeField::create('Test', 'Test'); $this->assertTrue($field->isShowPips()); $field->setShowPips(false); $this->assertFalse($field->isShowPips()); } public function testIsSetSnap() { $field = RangeField::create('Test', 'Test'); $this->assertFalse($field->isSnap()); $field->setSnap(true); $this->assertTrue($field->isSnap()); } public function testGetSetStart() { $field = RangeField::create('Test', 'Test', [5, 25]); $this->assertEquals([5, 25], $field->getStart()); $field = RangeField::create('Test', 'Test'); $this->assertEquals([0], $field->getStart()); $field->setStart(10); $this->assertEquals([10], $field->getStart()); } public function testGetSetUnit() { $field = RangeField::create('Test', 'Test'); $this->assertEquals('', $field->getUnit()); $field->setUnit('%'); $this->assertEquals('%', $field->getUnit()); } public function testGetSetdecimalPlaces() { $field = RangeField::create('Test', 'Test'); $this->assertEquals(2, $field->getDecimalPlaces()); $field->setDecimalPlaces(1); $this->assertEquals(1, $field->getDecimalPlaces()); } public function testSetFormat() { $field = RangeField::create('Test', 'Test'); $this->assertEquals(2, $field->getDecimalPlaces()); $this->assertEquals('', $field->getUnit()); $field->setFormat('cm', 0); $this->assertEquals(0, $field->getDecimalPlaces()); $this->assertEquals('cm', $field->getUnit()); } } |