1<?php 2 3namespace dokuwiki\plugin\struct\test; 4 5use dokuwiki\plugin\struct\meta\Column; 6use dokuwiki\plugin\struct\meta\Value; 7use dokuwiki\plugin\struct\types\Text; 8 9/** 10 * @group plugin_struct 11 * @group plugins 12 */ 13class Value_struct_test extends StructTest 14{ 15 16 /** 17 * @param bool $multi 18 * @return Column 19 */ 20 protected function makeColumn($multi) 21 { 22 return new Column(10, new Text(null, '', $multi)); 23 } 24 25 /** 26 * Test setting and getting multi values 27 */ 28 public function test_multi() 29 { 30 $col = $this->makeColumn(true); 31 $val = new Value($col, array('one', 'two')); 32 $this->assertSame($col, $val->getColumn()); 33 $this->assertEquals(array('one', 'two'), $val->getValue()); 34 35 $val->setValue(array('one', '', 'two', '')); 36 $this->assertEquals(array('one', 'two'), $val->getValue()); 37 38 $val->setValue(array('one', '0', 'two')); 39 $this->assertEquals(array('one', '0', 'two'), $val->getValue()); 40 41 $val->setValue(array('', null, false, " \n")); 42 $this->assertEquals(array(), $val->getValue()); 43 44 $val->setValue(''); 45 $this->assertEquals(array(), $val->getValue()); 46 47 $val->setValue('0'); 48 $this->assertEquals(array('0'), $val->getValue()); 49 50 $val->setValue(0); 51 $this->assertEquals(array('0'), $val->getValue()); 52 53 $val->setValue(array()); 54 $this->assertEquals(array(), $val->getValue()); 55 } 56 57 /** 58 * Test setting and getting single values 59 */ 60 public function test_single() 61 { 62 $col = $this->makeColumn(false); 63 $val = new Value($col, 'one'); 64 $this->assertSame($col, $val->getColumn()); 65 $this->assertEquals('one', $val->getValue()); 66 67 $val->setValue('0'); 68 $this->assertEquals('0', $val->getValue()); 69 70 $val->setValue(''); 71 $this->assertEquals('', $val->getValue()); 72 73 $val->setValue(" \n"); 74 $this->assertEquals('', $val->getValue()); 75 76 $val->setValue(null); 77 $this->assertEquals('', $val->getValue()); 78 79 $val->setValue(false); 80 $this->assertEquals('', $val->getValue()); 81 82 $val->setValue(array('what', 'the', 'foo')); 83 $this->assertEquals('what', $val->getValue()); 84 85 $val->setValue(array()); 86 $this->assertEquals('', $val->getValue()); 87 88 $val->setValue(" * hi\n * ho"); 89 $this->assertEquals(" * hi\n * ho", $val->getValue()); 90 } 91 92 /** 93 * empty values should not render 94 */ 95 public function test_blankrender() 96 { 97 $R = new \Doku_Renderer_xhtml(); 98 99 $val = new Value($this->makeColumn(false), ''); 100 $val->render($R, 'xhtml'); 101 $this->assertEquals('', $R->doc); 102 103 $val = new Value($this->makeColumn(true), array()); 104 $val->render($R, 'xhtml'); 105 $this->assertEquals('', $R->doc); 106 } 107} 108