Changeset 7107
- Timestamp:
- 01/20/08 08:32:10 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/view/sfEscapedViewParameterHolder.class.php
r6723 r7107 63 63 * 64 64 * @return array An array of view parameters 65 * 66 * @throws InvalidArgumentException 65 67 */ 66 68 public function toArray() … … 71 73 { 72 74 case 'on': 73 $escapedData = sfOutputEscaper::escape($this->getEscapingMethod(), $this->getAll()); 74 $attributes['sf_data'] = $escapedData; 75 $attributes['sf_data'] = sfOutputEscaper::escape($this->getEscapingMethod(), $this->getAll()); 75 76 break; 76 77 case 'bc': 77 $escapedData = sfOutputEscaper::escape($this->getEscapingMethod(), $this->getAll());78 78 $attributes = $this->getAll(); 79 $attributes['sf_data'] = $escapedData;79 $attributes['sf_data'] = sfOutputEscaper::escape($this->getEscapingMethod(), $this->getAll()); 80 80 break; 81 81 case 'both': 82 $ escapedData= sfOutputEscaper::escape($this->getEscapingMethod(), $this->getAll());83 foreach ($ escapedDataas $key => $value)82 $attributes['sf_data'] = sfOutputEscaper::escape($this->getEscapingMethod(), $this->getAll()); 83 foreach ($attributes['sf_data'] as $key => $value) 84 84 { 85 85 $attributes[$key] = $value; 86 86 } 87 $attributes['sf_data'] = $escapedData;88 87 break; 89 88 case 'off': 90 89 $attributes = $this->getAll(); 91 90 break; 91 default: 92 throw new InvalidArgumentException(sprintf('Unknown strategy "%s".', $this->getEscaping())); 92 93 } 93 94 … … 108 109 109 110 /** 110 * Sets the escape c aracter mode.111 * Sets the escape character strategy. 111 112 * 112 113 * @param string Escape code … … 122 123 * If the escaping method is empty, then that is returned. The default value 123 124 * specified by the sub-class will be used. If the method does not exist (in 124 * the sense there is no define associated with the method) andexception is125 * the sense there is no define associated with the method), an exception is 125 126 * thrown. 126 127 * 127 128 * @return string The escaping method as the name of the function to use 128 129 * 129 * @throws <b>sfConfigurationException</b>If the method does not exist130 * @throws InvalidArgumentException If the method does not exist 130 131 */ 131 132 public function getEscapingMethod() … … 138 139 if (!defined($this->escapingMethod)) 139 140 { 140 throw new sfConfigurationException(sprintf('The escaping method "%s" is not available.', $this->escapingMethod));141 throw new InvalidArgumentException(sprintf('The escaping method "%s" is not available.', $this->escapingMethod)); 141 142 } 142 143 branches/1.1/test/unit/view/sfEscapedViewParameterHolderTest.php
r5018 r7107 12 12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 13 13 14 $t = new lime_test( 10, new lime_output_color());14 $t = new lime_test(27, new lime_output_color()); 15 15 16 16 define('ESC_ENTITIES', 'esc_entities'); … … 69 69 $t->is($p->getEscapingMethod(), ESC_RAW, '->initialize() takes an array of options as its third argument'); 70 70 71 // ->isEscaped() 72 $t->diag('->isEscaped()'); 73 $t->is($p->isEscaped(), true, '->isEscaped() always returns true'); 74 71 75 // ->getEscaping() ->setEscaping() 72 76 $t->diag('->getEscaping() ->setEscaping()'); … … 80 84 $t->is($p->getEscapingMethod(), ESC_RAW, '->setEscapingMethod() changes the escaping method'); 81 85 86 $p->setEscapingMethod(''); 87 $t->is($p->getEscapingMethod(), '', '->getEscapingMethod() returns an empty value if the method is empty'); 88 89 try 90 { 91 $p->setEscapingMethod('nonexistant'); 92 $p->getEscapingMethod(); 93 $t->fail('->getEscapingMethod() throws an InvalidArgumentException if the escaping method does not exist'); 94 } 95 catch (InvalidArgumentException $e) 96 { 97 $t->pass('->getEscapingMethod() throws an InvalidArgumentException if the escaping method does not exist'); 98 } 99 82 100 // ->toArray() 83 101 $t->diag('->toArray()'); … … 86 104 $t->is($a['foo'], 'bar', '->toArray() returns an array representation of the parameter holder'); 87 105 106 // escaping strategies 107 $p = new sfEscapedViewParameterHolder(); 108 $p->initialize(new sfEventDispatcher(), array('foo' => 'bar')); 109 110 $t->diag('Escaping strategy to on'); 111 $p->setEscaping('on'); 112 $values = $p->toArray(); 113 $t->is(count($values), 1, '->toArray() knows about the "on" strategy'); 114 $t->is(count($values['sf_data']), 1, '->toArray() knows about the "on" strategy'); 115 $t->is($values['sf_data']['foo'], '-ESCAPED-bar-ESCAPED-', '->toArray() knows about the "on" strategy'); 116 117 try 118 { 119 $p->setEscaping('null'); 120 $p->toArray(); 121 $t->fail('->toArray() throws an InvalidArgumentException if the escaping strategy does not exist'); 122 } 123 catch (InvalidArgumentException $e) 124 { 125 $t->pass('->toArray() throws an InvalidArgumentException if the escaping strategy does not exist'); 126 } 127 128 $t->diag('Escaping strategy to bc'); 129 $p->setEscaping('bc'); 130 $values = $p->toArray(); 131 $t->is(count($values), 2, '->toArray() knows about the "bc" strategy'); 132 $t->is(count($values['sf_data']), 1, '->toArray() knows about the "bc" strategy'); 133 $t->is($values['foo'], 'bar', '->toArray() knows about the "bc" strategy'); 134 $t->is($values['sf_data']['foo'], '-ESCAPED-bar-ESCAPED-', '->toArray() knows about the "bc" strategy'); 135 136 $t->diag('Escaping strategy to both'); 137 $p->setEscaping('both'); 138 $values = $p->toArray(); 139 $t->is(count($values), 2, '->toArray() knows about the "both" strategy'); 140 $t->is(count($values['sf_data']), 1, '->toArray() knows about the "both" strategy'); 141 $t->is($values['foo'], '-ESCAPED-bar-ESCAPED-', '->toArray() knows about the "both" strategy'); 142 $t->is($values['sf_data']['foo'], '-ESCAPED-bar-ESCAPED-', '->toArray() knows about the "both" strategy'); 143 144 $t->diag('Escaping strategy to off'); 145 $p->setEscaping('off'); 146 $values = $p->toArray(); 147 $t->is(count($values), 1, '->toArray() knows about the "off" strategy'); 148 $t->is($values['foo'], 'bar', '->toArray() knows about the "off" strategy'); 149 88 150 // ->serialize() / ->unserialize() 89 151 $t->diag('->serialize() / ->unserialize()'); branches/1.1/test/unit/view/sfViewParameterHolderTest.php
r5018 r7107 12 12 require_once($_test_dir.'/unit/sfContextMock.class.php'); 13 13 14 $t = new lime_test( 4, new lime_output_color());14 $t = new lime_test(5, new lime_output_color()); 15 15 16 16 class myRequest … … 46 46 $t->is($p->get('foo'), 'bar', '->initialize() takes an array of default parameters as its second argument'); 47 47 48 // ->isEscaped() 49 $t->diag('->isEscaped()'); 50 $t->is($p->isEscaped(), false, '->isEscaped() always returns false'); 51 48 52 // ->toArray() 49 53 $t->diag('->toArray()');