示例#1
0
 /**
  * Tries to find a matching user provided value and, when found, assigns it
  * to the parameter, and removes it from the raw values. Returns a boolean
  * indicating if there was any user value set or not.
  * 
  * @since 0.4
  * 
  * @return boolean
  */
 protected function attemptToSetUserValue(Parameter $parameter)
 {
     if (array_key_exists($parameter->getName(), $this->rawParameters)) {
         $parameter->setUserValue($parameter->getName(), $this->rawParameters[$parameter->getName()]);
         unset($this->rawParameters[$parameter->getName()]);
         return true;
     } else {
         foreach ($parameter->getAliases() as $alias) {
             if (array_key_exists($alias, $this->rawParameters)) {
                 $parameter->setUserValue($alias, $this->rawParameters[$alias]);
                 unset($this->rawParameters[$alias]);
                 return true;
             }
         }
     }
     return false;
 }
	/**
	 * Tests CriterionNotEmpty.
	 */
	public function testCriterionNotEmpty() {
		$tests = array(
			array( true, 'a' ),
			array( true, ' a ' ),
			array( false, '' ),
			array( false, '  ' ),
			array( false, "\n" ),
			array( false, " \n " ),
			array( true, " \n ." ),
		);
		
		foreach ( $tests as $test ) {
			$c = new CriterionNotEmpty();
			$p = new Parameter( 'test' );
			$p->setUserValue( 'test', $test[1] );
			
			$this->assertEquals(
				$test[0],
				$c->validate( $p, array() )->isValid(),
				'Value "'. $test[1]. '" should ' . ( !$test[0] ? '' : 'not ' ) . " be empty."
			);
		}
	}