Pull merge.
[yaffs-website] / web / core / modules / views / tests / src / Kernel / ViewExecutableTest.php
index f843892e5da1c2c4cf490dda4b364590a7aaadbb..cb548c0afbaf34880a4f28ec187babe9e00bbb23 100644 (file)
@@ -38,7 +38,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
    *
    * @var array
    */
-  public static $testViews = ['test_destroy', 'test_executable_displays'];
+  public static $testViews = ['test_destroy', 'test_executable_displays', 'test_argument_dependency'];
 
   /**
    * Properties that should be stored in the configuration.
@@ -136,7 +136,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
     // Test the initStyle() method.
     $view->initStyle();
     $this->assertTrue($view->style_plugin instanceof DefaultStyle, 'Make sure a reference to the style plugin is set.');
-    // Test the plugin has been inited and view have references to the view and
+    // Test the plugin has been invited and view have references to the view and
     // display handler.
     $this->assertEqual(spl_object_hash($view->style_plugin->view), $view_hash);
     $this->assertEqual(spl_object_hash($view->style_plugin->displayHandler), $display_hash);
@@ -196,8 +196,13 @@ class ViewExecutableTest extends ViewsKernelTestBase {
     $view->initDisplay();
 
     // Error is triggered while calling the wrong display.
-    $this->setExpectedException(\PHPUnit_Framework_Error::class);
-    $view->setDisplay('invalid');
+    try {
+      $view->setDisplay('invalid');
+      $this->fail('Expected error, when setDisplay() called with invalid display ID');
+    }
+    catch (\PHPUnit_Framework_Error_Warning $e) {
+      $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage());
+    }
 
     $this->assertEqual($view->current_display, 'default', 'If setDisplay is called with an invalid display id the default display should be used.');
     $this->assertEqual(spl_object_hash($view->display_handler), spl_object_hash($view->displayHandlers->get('default')));
@@ -427,7 +432,7 @@ class ViewExecutableTest extends ViewsKernelTestBase {
 
     $count = 0;
     foreach ($view->displayHandlers as $id => $display) {
-      $match = function($value) use ($display) {
+      $match = function ($value) use ($display) {
         return strpos($value, $display->display['display_title']) !== FALSE;
       };
       $this->assertTrue(array_filter($validate[$id], $match), format_string('Error message found for @id display', ['@id' => $id]));
@@ -487,6 +492,52 @@ class ViewExecutableTest extends ViewsKernelTestBase {
     $this->assertIdentical($unserialized->current_display, 'page_1', 'The expected display was set on the unserialized view.');
     $this->assertIdentical($unserialized->args, ['test'], 'The expected argument was set on the unserialized view.');
     $this->assertIdentical($unserialized->getCurrentPage(), 2, 'The expected current page was set on the unserialized view.');
+
+    // Get the definition of node's nid field, for example. Only get it not from
+    // the field manager directly, but from the item data definition. It should
+    // be the same base field definition object (the field and item definitions
+    // refer to each other).
+    // See https://bugs.php.net/bug.php?id=66052
+    $field_manager = $this->container->get('entity_field.manager');
+    $nid_definition_before = $field_manager->getBaseFieldDefinitions('node')['nid']
+      ->getItemDefinition()
+      ->getFieldDefinition();
+
+    // Load and execute a view.
+    $view_entity = View::load('content');
+    $view_executable = $view_entity->getExecutable();
+    $view_executable->execute('page_1');
+
+    // Reset the static cache. Don't use clearCachedFieldDefinitions() since
+    // that clears the persistent cache and we need to get the serialized cache
+    // data.
+    $field_manager->useCaches(FALSE);
+    $field_manager->useCaches(TRUE);
+
+    // Serialize the ViewExecutable as part of other data.
+    unserialize(serialize(['SOMETHING UNEXPECTED', $view_executable]));
+
+    // Make sure the serialisation of the ViewExecutable didn't influence the
+    // field definitions.
+    $nid_definition_after = $field_manager->getBaseFieldDefinitions('node')['nid']
+      ->getItemDefinition()
+      ->getFieldDefinition();
+    $this->assertEquals($nid_definition_before->getPropertyDefinitions(), $nid_definition_after->getPropertyDefinitions());
+  }
+
+  /**
+   * Tests if argument overrides by validators are propagated to tokens.
+   */
+  public function testArgumentValidatorValueOverride() {
+    $view = Views::getView('test_argument_dependency');
+    $view->setDisplay('page_1');
+    $view->setArguments(['1', 'this value should be replaced']);
+    $view->execute();
+    $expected = [
+      '{{ arguments.uid }}' => '1',
+      '{{ raw_arguments.uid }}' => '1',
+    ];
+    $this->assertEquals($expected, $view->build_info['substitutions']);
   }
 
 }