From 98093bef2e61ed6e324a85182877d73c473e3992 Mon Sep 17 00:00:00 2001 From: Lee Rowlands Date: Thu, 3 May 2018 07:11:53 +1000 Subject: [PATCH] Issue #2864035 by alexpott, nlisgo, mpdonadio, vaplas, GoZ, naveenvalecha, dawehner, Lendude: Convert web tests to browser tests for rdf module --- .../src/Functional/FileFieldTestBase.php | 10 ++-- .../rdf/src/Tests/GetNamespacesTest.php | 50 ------------------- .../rdf/tests/rdf_test/rdf_test.info.yml | 8 +++ .../rdf_test/src}/TestDataConverter.php | 2 +- .../src/Functional}/CommentAttributesTest.php | 4 +- .../Functional/FileFieldAttributesTest.php | 2 +- .../src/Functional/GetRdfNamespacesTest.php | 19 +++++++ .../Functional}/ImageFieldAttributesTest.php | 9 +++- .../src/Functional/NodeAttributesTest.php | 2 +- .../Field/FieldRdfaDatatypeCallbackTest.php | 4 +- 10 files changed, 48 insertions(+), 62 deletions(-) delete mode 100644 core/modules/rdf/src/Tests/GetNamespacesTest.php create mode 100644 core/modules/rdf/tests/rdf_test/rdf_test.info.yml rename core/modules/rdf/{src/Tests/Field => tests/rdf_test/src}/TestDataConverter.php (92%) rename core/modules/rdf/{src/Tests => tests/src/Functional}/CommentAttributesTest.php (99%) rename core/modules/rdf/{src/Tests => tests/src/Functional}/ImageFieldAttributesTest.php (93%) diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php index f3d1c22b460a..dc2e8becc139 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -7,6 +7,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\file\FileInterface; use Drupal\Tests\BrowserTestBase; use Drupal\file\Entity\File; +use Drupal\Tests\TestFileCreationTrait; /** * Provides methods specifically for testing File module's field handling. @@ -14,6 +15,9 @@ use Drupal\file\Entity\File; abstract class FileFieldTestBase extends BrowserTestBase { use FileFieldCreationTrait; + use TestFileCreationTrait { + getTestFiles as drupalGetTestFiles; + } /** * Modules to enable. @@ -156,7 +160,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { $edit[$name][] = $file_path; } } - $this->drupalPostForm("node/$nid/edit", $edit, t('Save and keep published')); + $this->drupalPostForm("node/$nid/edit", $edit, t('Save')); return $nid; } @@ -172,7 +176,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { ]; $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove')); - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); } /** @@ -185,7 +189,7 @@ abstract class FileFieldTestBase extends BrowserTestBase { ]; $this->drupalPostForm('node/' . $nid . '/edit', [], t('Remove')); - $this->drupalPostForm(NULL, $edit, t('Save and keep published')); + $this->drupalPostForm(NULL, $edit, t('Save')); } /** diff --git a/core/modules/rdf/src/Tests/GetNamespacesTest.php b/core/modules/rdf/src/Tests/GetNamespacesTest.php deleted file mode 100644 index ca46c5cd794c..000000000000 --- a/core/modules/rdf/src/Tests/GetNamespacesTest.php +++ /dev/null @@ -1,50 +0,0 @@ -drupalGet(''); - - $element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [ - ':prefix_binding' => 'rdfs: http://www.w3.org/2000/01/rdf-schema#', - ]); - $this->assertTrue(!empty($element), 'A prefix declared once is displayed.'); - - $element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [ - ':prefix_binding' => 'foaf: http://xmlns.com/foaf/0.1/', - ]); - $this->assertTrue(!empty($element), 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'); - - $element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [ - ':prefix_binding' => 'foaf1: http://xmlns.com/foaf/0.1/', - ]); - $this->assertTrue(!empty($element), 'Two prefixes can be assigned the same namespace.'); - - $element = $this->xpath('//html[contains(@prefix, :prefix_binding)]', [ - ':prefix_binding' => 'dc: http://purl.org/dc/terms/', - ]); - $this->assertTrue(!empty($element), 'When a prefix has conflicting namespaces, the first declared one is used.'); - } - -} diff --git a/core/modules/rdf/tests/rdf_test/rdf_test.info.yml b/core/modules/rdf/tests/rdf_test/rdf_test.info.yml new file mode 100644 index 000000000000..9e6a16bcc693 --- /dev/null +++ b/core/modules/rdf/tests/rdf_test/rdf_test.info.yml @@ -0,0 +1,8 @@ +name: 'RDF test module' +type: module +description: 'Test functionality for the RDF module.' +package: Testing +version: VERSION +core: 8.x +dependencies: + - rdf diff --git a/core/modules/rdf/src/Tests/Field/TestDataConverter.php b/core/modules/rdf/tests/rdf_test/src/TestDataConverter.php similarity index 92% rename from core/modules/rdf/src/Tests/Field/TestDataConverter.php rename to core/modules/rdf/tests/rdf_test/src/TestDataConverter.php index fd30b278a227..08bbdd3f680e 100644 --- a/core/modules/rdf/src/Tests/Field/TestDataConverter.php +++ b/core/modules/rdf/tests/rdf_test/src/TestDataConverter.php @@ -1,6 +1,6 @@ drupalGet(''); + + // We have to use the find() method on the driver directly because //html is + // prepended to all xpath queries otherwise. + $driver = $this->getSession()->getDriver(); + + $element = $driver->find('//html[contains(@prefix, "rdfs: http://www.w3.org/2000/01/rdf-schema#")]'); + $this->assertCount(1, $element, 'A prefix declared once is displayed.'); + + $element = $driver->find('//html[contains(@prefix, "foaf: http://xmlns.com/foaf/0.1/")]'); + $this->assertCount(1, $element, 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.'); + + $element = $driver->find('//html[contains(@prefix, "foaf1: http://xmlns.com/foaf/0.1/")]'); + $this->assertCount(1, $element, 'Two prefixes can be assigned the same namespace.'); + + $element = $driver->find('//html[contains(@prefix, "dc: http://purl.org/dc/terms/")]'); + $this->assertCount(1, $element, 'When a prefix has conflicting namespaces, the first declared one is used.'); + // Get all RDF namespaces. $ns = rdf_get_namespaces(); diff --git a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php b/core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php similarity index 93% rename from core/modules/rdf/src/Tests/ImageFieldAttributesTest.php rename to core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php index d4d7d35948e6..e5707591f70d 100644 --- a/core/modules/rdf/src/Tests/ImageFieldAttributesTest.php +++ b/core/modules/rdf/tests/src/Functional/ImageFieldAttributesTest.php @@ -1,11 +1,12 @@ setFieldMapping($this->fieldName, [ 'properties' => ['schema:interactionCount'], 'datatype_callback' => [ - 'callable' => 'Drupal\rdf\Tests\Field\TestDataConverter::convertFoo', + 'callable' => 'Drupal\rdf_test\TestDataConverter::convertFoo', ], ])->save();