Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / tests / Drupal / Tests / Component / Serialization / YamlTest.php
index becd7c0221c4c15fe82c70f1360c0c80256c696d..686681458997dabd555f747ed2dd8ad89103b9c0 100644 (file)
@@ -77,20 +77,46 @@ class YamlTest extends TestCase {
   }
 
   /**
-   * Ensures that decoding php objects is similar for PECL and Symfony.
+   * Ensures that decoding php objects does not work in PECL.
    *
    * @requires extension yaml
+   *
+   * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledSymfony()
    */
-  public function testObjectSupportDisabled() {
+  public function testObjectSupportDisabledPecl() {
     $object = new \stdClass();
     $object->foo = 'bar';
     // In core all Yaml encoding is done via Symfony and it does not support
-    // objects so in order to encode an object we hace to use the PECL
+    // objects so in order to encode an object we have to use the PECL
     // extension.
     // @see \Drupal\Component\Serialization\Yaml::encode()
     $yaml = YamlPecl::encode([$object]);
     $this->assertEquals(['O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'], YamlPecl::decode($yaml));
-    $this->assertEquals(['!php/object "O:8:\"stdClass\":1:{s:3:\"foo\";s:3:\"bar\";}"'], YamlSymfony::decode($yaml));
+  }
+
+  /**
+   * Ensures that decoding php objects does not work in Symfony.
+   *
+   * @requires extension yaml
+   *
+   * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledPecl()
+   */
+  public function testObjectSupportDisabledSymfony() {
+    if (method_exists($this, 'setExpectedExceptionRegExp')) {
+      $this->setExpectedExceptionRegExp(InvalidDataTypeException::class, '/^Object support when parsing a YAML file has been disabled/');
+    }
+    else {
+      $this->expectException(InvalidDataTypeException::class);
+      $this->expectExceptionMessageRegExp('/^Object support when parsing a YAML file has been disabled/');
+    }
+    $object = new \stdClass();
+    $object->foo = 'bar';
+    // In core all Yaml encoding is done via Symfony and it does not support
+    // objects so in order to encode an object we have to use the PECL
+    // extension.
+    // @see \Drupal\Component\Serialization\Yaml::encode()
+    $yaml = YamlPecl::encode([$object]);
+    YamlSymfony::decode($yaml);
   }
 
   /**
@@ -101,8 +127,8 @@ class YamlTest extends TestCase {
     $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/../../../../../', \RecursiveDirectoryIterator::FOLLOW_SYMLINKS));
     foreach ($dirs as $dir) {
       $pathname = $dir->getPathname();
-      // Exclude vendor.
-      if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../vendor') === FALSE) {
+      // Exclude core/node_modules.
+      if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../node_modules') === FALSE) {
         if (strpos($dir->getRealPath(), 'invalid_file') !== FALSE) {
           // There are some intentionally invalid files provided for testing
           // library API behaviours, ignore them.