Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit ce8d54c

Browse files
MSolvdkinzer
authored andcommitted
Dkan patches and test fixes (#114)
* Added DKAN patch * Run build remake * Test file added back * Run DKAN remake
1 parent 5c277bc commit ce8d54c

File tree

10 files changed

+114
-15
lines changed

10 files changed

+114
-15
lines changed

build-dkan.make

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ projects[dkan][download][url] = https://github.com/NuCivic/dkan.git
1111
projects[dkan][download][tag] = 7.x-1.13.1
1212

1313
projects[dkan][patch][1] = https://patch-diff.githubusercontent.com/raw/NuCivic/dkan/pull/1769.diff
14-
14+
projects[dkan][patch][2] = https://patch-diff.githubusercontent.com/raw/NuCivic/dkan/pull/1761.diff

dkan/PATCHES.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The following patches have been applied to this project:
2+
- https://patch-diff.githubusercontent.com/raw/NuCivic/dkan/pull/1769.diff
3+
- https://patch-diff.githubusercontent.com/raw/NuCivic/dkan/pull/1761.diff
4+
5+
This file was automatically generated by Drush Make (http://drupal.org/project/drush).

dkan/libraries/symfonyserializer/Encoder/XmlEncoder.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ private function buildXml(\DOMNode $parentNode, $data, $xmlRootNodeName = null)
372372
if (is_array($data) || ($data instanceof \Traversable && !$this->serializer->supportsNormalization($data, $this->format))) {
373373
foreach ($data as $key => $data) {
374374
//Ah this is the magic @ attribute types.
375-
if (0 === strpos($key, '@') && is_scalar($data) && $this->isElementNameValid($attributeName = substr($key, 1))) {
375+
if (0 === strpos($key, '@') && $this->isElementNameValid($attributeName = substr($key, 1))) {
376+
if (!is_scalar($data)) {
377+
$data = $this->serializer->normalize($data, $this->format, $this->context);
378+
}
376379
$parentNode->setAttribute($attributeName, $data);
377380
} elseif ($key === '#') {
378381
$append = $this->selectNodeType($parentNode, $data);
@@ -477,7 +480,7 @@ private function selectNodeType(\DOMNode $node, $val)
477480
} elseif ($val instanceof \Traversable) {
478481
$this->buildXml($node, $val);
479482
} elseif (is_object($val)) {
480-
return $this->buildXml($node, $this->serializer->normalize($val, $this->format, $this->context));
483+
return $this->selectNodeType($node, $this->serializer->normalize($val, $this->format, $this->context));
481484
} elseif (is_numeric($val)) {
482485
return $this->appendText($node, (string) $val);
483486
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {

dkan/libraries/symfonyserializer/Mapping/Loader/YamlFileLoader.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Serializer\Mapping\AttributeMetadata;
1616
use Symfony\Component\Serializer\Mapping\ClassMetadataInterface;
1717
use Symfony\Component\Yaml\Parser;
18+
use Symfony\Component\Yaml\Yaml;
1819

1920
/**
2021
* YAML File Loader.
@@ -113,7 +114,7 @@ private function getClassesFromYaml()
113114
$this->yamlParser = new Parser();
114115
}
115116

116-
$classes = $this->yamlParser->parse(file_get_contents($this->file));
117+
$classes = $this->yamlParser->parse(file_get_contents($this->file), Yaml::PARSE_KEYS_AS_STRINGS);
117118

118119
if (empty($classes)) {
119120
return array();

dkan/libraries/symfonyserializer/Serializer.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public function supportsNormalization($data, $format = null/*, array $context =
185185
if (__CLASS__ !== get_class($this)) {
186186
$r = new \ReflectionMethod($this, __FUNCTION__);
187187
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
188-
@trigger_error(sprintf('Method %s() will have a third `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
188+
@trigger_error(sprintf('Method %s() will have a third `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
189189
}
190190
}
191191

@@ -206,7 +206,7 @@ public function supportsDenormalization($data, $type, $format = null/*, array $c
206206
if (__CLASS__ !== get_class($this)) {
207207
$r = new \ReflectionMethod($this, __FUNCTION__);
208208
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
209-
@trigger_error(sprintf('Method %s() will have a fourth `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
209+
@trigger_error(sprintf('Method %s() will have a fourth `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
210210
}
211211
}
212212

@@ -306,7 +306,7 @@ public function supportsEncoding($format/*, array $context = array()*/)
306306
if (__CLASS__ !== get_class($this)) {
307307
$r = new \ReflectionMethod($this, __FUNCTION__);
308308
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
309-
@trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
309+
@trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
310310
}
311311
}
312312

@@ -327,7 +327,7 @@ public function supportsDecoding($format/*, array $context = array()*/)
327327
if (__CLASS__ !== get_class($this)) {
328328
$r = new \ReflectionMethod($this, __FUNCTION__);
329329
if (__CLASS__ !== $r->getDeclaringClass()->getName()) {
330-
@trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', get_class($this), __FUNCTION__), E_USER_DEPRECATED);
330+
@trigger_error(sprintf('Method %s() will have a second `$context = array()` argument in version 4.0. Not defining it is deprecated since 3.3.', __METHOD__), E_USER_DEPRECATED);
331331
}
332332
}
333333

dkan/libraries/symfonyserializer/Tests/Encoder/XmlEncoderTest.php

+91
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,17 @@
1919
use Symfony\Component\Serializer\Serializer;
2020
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
2121
use Symfony\Component\Serializer\Normalizer\CustomNormalizer;
22+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2223

2324
class XmlEncoderTest extends TestCase
2425
{
26+
/**
27+
* @var XmlEncoder
28+
*/
2529
private $encoder;
2630

31+
private $exampleDateTimeString = '2017-02-19T15:16:08+0300';
32+
2733
protected function setUp()
2834
{
2935
$this->encoder = new XmlEncoder();
@@ -551,4 +557,89 @@ protected function getObject()
551557

552558
return $obj;
553559
}
560+
561+
public function testEncodeXmlWithBoolValue()
562+
{
563+
$expectedXml = <<<'XML'
564+
<?xml version="1.0"?>
565+
<response><foo>1</foo><bar>0</bar></response>
566+
567+
XML;
568+
569+
$actualXml = $this->encoder->encode(array('foo' => true, 'bar' => false), 'xml');
570+
571+
$this->assertEquals($expectedXml, $actualXml);
572+
}
573+
574+
public function testEncodeXmlWithDateTimeObjectValue()
575+
{
576+
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
577+
578+
$actualXml = $xmlEncoder->encode(array('dateTime' => new \DateTime($this->exampleDateTimeString)), 'xml');
579+
580+
$this->assertEquals($this->createXmlWithDateTime(), $actualXml);
581+
}
582+
583+
public function testEncodeXmlWithDateTimeObjectField()
584+
{
585+
$xmlEncoder = $this->createXmlEncoderWithDateTimeNormalizer();
586+
587+
$actualXml = $xmlEncoder->encode(array('foo' => array('@dateTime' => new \DateTime($this->exampleDateTimeString))), 'xml');
588+
589+
$this->assertEquals($this->createXmlWithDateTimeField(), $actualXml);
590+
}
591+
592+
/**
593+
* @return XmlEncoder
594+
*/
595+
private function createXmlEncoderWithDateTimeNormalizer()
596+
{
597+
$encoder = new XmlEncoder();
598+
$serializer = new Serializer(array($this->createMockDateTimeNormalizer()), array('xml' => new XmlEncoder()));
599+
$encoder->setSerializer($serializer);
600+
601+
return $encoder;
602+
}
603+
604+
/**
605+
* @return \PHPUnit_Framework_MockObject_MockObject|NormalizerInterface
606+
*/
607+
private function createMockDateTimeNormalizer()
608+
{
609+
$mock = $this->getMockBuilder('\Symfony\Component\Serializer\Normalizer\CustomNormalizer')->getMock();
610+
611+
$mock
612+
->expects($this->once())
613+
->method('normalize')
614+
->with(new \DateTime($this->exampleDateTimeString), 'xml', array())
615+
->willReturn($this->exampleDateTimeString);
616+
617+
$mock
618+
->expects($this->once())
619+
->method('supportsNormalization')
620+
->with(new \DateTime($this->exampleDateTimeString), 'xml')
621+
->willReturn(true);
622+
623+
return $mock;
624+
}
625+
626+
/**
627+
* @return string
628+
*/
629+
private function createXmlWithDateTime()
630+
{
631+
return sprintf('<?xml version="1.0"?>
632+
<response><dateTime>%s</dateTime></response>
633+
', $this->exampleDateTimeString);
634+
}
635+
636+
/**
637+
* @return string
638+
*/
639+
private function createXmlWithDateTimeField()
640+
{
641+
return sprintf('<?xml version="1.0"?>
642+
<response><foo dateTime="%s"/></response>
643+
', $this->exampleDateTimeString);
644+
}
554645
}

dkan/libraries/symfonyserializer/composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"php": ">=5.5.9"
2020
},
2121
"require-dev": {
22-
"symfony/yaml": "~3.1",
22+
"symfony/yaml": "~3.3",
2323
"symfony/config": "~2.8|~3.0",
2424
"symfony/property-access": "~2.8|~3.0",
2525
"symfony/http-foundation": "~2.8|~3.0",
@@ -34,7 +34,7 @@
3434
"symfony/dependency-injection": "<3.2",
3535
"symfony/property-access": ">=3.0,<3.0.4|>=2.8,<2.8.4",
3636
"symfony/property-info": "<3.1",
37-
"symfony/yaml": "<3.1"
37+
"symfony/yaml": "<3.3"
3838
},
3939
"suggest": {
4040
"psr/cache-implementation": "For using the metadata cache.",

dkan/test/features/resource.all.feature

+1-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ Feature: Resource
4141

4242
@api
4343
Scenario: View published resource
44-
Given I am on the homepage
45-
And I follow "Datasets"
46-
And I click "Dataset 01"
44+
Given I am on "Dataset 01" page
4745
When I click "Resource 01"
4846
Then I am on the "Resource 01" page
4947

dkan/test/features/topics.feature

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Feature: Topics
2020
And I should see "Topic2 & $p@"
2121
And I should see "icon" in the ".font-icon-select-1-e904" element
2222

23-
@api @Topics
23+
@api @Topics @no-main-menu
2424
Scenario: See topic in the main menu
2525
When I am on the homepage
2626
Then I click on the text "Topics"
2727
Then I should see "Topic1"
2828

29-
@api @Topics
29+
@api @Topics @no-main-menu
3030
Scenario: Check topic facet link
3131
When I am on the homepage
3232
Then I click on the text "Topics"

dkan/test/features/widgets.feature

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ Feature: Widgets
135135
And I wait for "First spot"
136136
Then I should see "First spot" in the "content"
137137

138+
@no-main-menu
138139
Scenario: Adds "New Submenu Widget" block to home page using panels ipe editor
139140
Given the cache has been cleared
140141
When I follow "Submenu"

0 commit comments

Comments
 (0)