/**
  * @dataProvider provideParse
  */
 public function testParse($input, StringNormalizer $normalizer = null, DataValue $expected)
 {
     $parser = new StringParser($normalizer);
     $value = $parser->parse($input);
     $this->assertInstanceOf('DataValues\\StringValue', $value);
     $this->assertEquals($expected->toArray(), $value->toArray());
 }
Beispiel #2
0
 /**
  * @return array
  */
 public function toArray()
 {
     $array = array('snaktype' => $this->type, 'property' => $this->propertyId->getPrefixedId());
     if ($this->dataValue !== null) {
         $array['datavalue'] = $this->dataValue->toArray();
     }
     return $array;
 }
 /**
  * @dataProvider instanceProvider
  * @param DataValue $value
  * @param array $arguments
  */
 public function testToArray(DataValue $value, array $arguments)
 {
     $array = $value->toArray();
     $this->assertInternalType('array', $array);
     $this->assertTrue(array_key_exists('type', $array));
     $this->assertTrue(array_key_exists('value', $array));
     $this->assertEquals($value->getTargetType(), $array['type']);
     $this->assertEquals($value->getValue(), $array['value']);
 }
 /**
  * @dataProvider provideApiRequest
  */
 public function testApiRequest(DataValue $value, $dataType, $format, $options, $pattern)
 {
     $this->setUpEntities();
     $params = array('action' => 'wbformatvalue', 'generate' => $format, 'datatype' => $dataType, 'datavalue' => json_encode($value->toArray()), 'options' => $options === null ? null : json_encode($options));
     list($resultArray, ) = $this->doApiRequest($params);
     $this->assertInternalType('array', $resultArray, 'top level element must be an array');
     $this->assertArrayHasKey('result', $resultArray, 'top level element must have a "result" key');
     $this->assertRegExp($pattern, $resultArray['result']);
 }
 /**
  * @param DataValue|mixed $expected
  * @param DataValue|mixed $actual
  */
 private function assertSmartEquals($expected, $actual)
 {
     if ($this->requireDataValue() || $expected instanceof Comparable) {
         if ($expected instanceof DataValue && $actual instanceof DataValue) {
             $msg = "testing equals():\n" . preg_replace('/\\s+/', ' ', print_r($actual->toArray(), true)) . " should equal\n" . preg_replace('/\\s+/', ' ', print_r($expected->toArray(), true));
         } else {
             $msg = 'testing equals()';
         }
         $this->assertTrue($expected->equals($actual), $msg);
     } else {
         $this->assertEquals($expected, $actual);
     }
 }
 protected function getSerializedDataValue(DataValue $dataValue)
 {
     return $dataValue->toArray();
 }