Issue #2864035 by alexpott, nlisgo, mpdonadio, vaplas, GoZ, naveenvalecha, dawehner, Lendude: Convert web tests to browser tests for rdf module
							parent
							
								
									64640c24f0
								
							
						
					
					
						commit
						98093bef2e
					
				| 
						 | 
				
			
			@ -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'));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,50 +0,0 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\rdf\Tests;
 | 
			
		||||
 | 
			
		||||
use Drupal\simpletest\WebTestBase;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Confirm that the serialization of RDF namespaces in present in the HTML
 | 
			
		||||
 * markup.
 | 
			
		||||
 *
 | 
			
		||||
 * @group rdf
 | 
			
		||||
 */
 | 
			
		||||
class GetNamespacesTest extends WebTestBase {
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Modules to enable.
 | 
			
		||||
   *
 | 
			
		||||
   * @var array
 | 
			
		||||
   */
 | 
			
		||||
  public static $modules = ['rdf', 'rdf_test_namespaces'];
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Tests RDF namespaces.
 | 
			
		||||
   */
 | 
			
		||||
  public function testGetRdfNamespaces() {
 | 
			
		||||
    // Fetches the front page and extracts RDFa 1.1 prefixes.
 | 
			
		||||
    $this->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.');
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\rdf\Tests\Field;
 | 
			
		||||
namespace Drupal\rdf_test;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Contains methods for test data conversions.
 | 
			
		||||
| 
						 | 
				
			
			@ -1,10 +1,10 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\rdf\Tests;
 | 
			
		||||
namespace Drupal\Tests\rdf\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\comment\CommentInterface;
 | 
			
		||||
use Drupal\comment\CommentManagerInterface;
 | 
			
		||||
use Drupal\comment\Tests\CommentTestBase;
 | 
			
		||||
use Drupal\Tests\comment\Functional\CommentTestBase;
 | 
			
		||||
use Drupal\user\RoleInterface;
 | 
			
		||||
use Drupal\comment\Entity\Comment;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
 | 
			
		||||
namespace Drupal\Tests\rdf\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\file\Tests\FileFieldTestBase;
 | 
			
		||||
use Drupal\Tests\file\Functional\FileFieldTestBase;
 | 
			
		||||
use Drupal\file\Entity\File;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,6 +22,25 @@ class GetRdfNamespacesTest extends BrowserTestBase {
 | 
			
		|||
   * Tests getting RDF namespaces.
 | 
			
		||||
   */
 | 
			
		||||
  public function testGetRdfNamespaces() {
 | 
			
		||||
    // Fetches the front page and extracts RDFa 1.1 prefixes.
 | 
			
		||||
    $this->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();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,11 +1,12 @@
 | 
			
		|||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Drupal\rdf\Tests;
 | 
			
		||||
namespace Drupal\Tests\rdf\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\image\Entity\ImageStyle;
 | 
			
		||||
use Drupal\image\Tests\ImageFieldTestBase;
 | 
			
		||||
use Drupal\Tests\image\Functional\ImageFieldTestBase;
 | 
			
		||||
use Drupal\node\Entity\Node;
 | 
			
		||||
use Drupal\file\Entity\File;
 | 
			
		||||
use Drupal\Tests\TestFileCreationTrait;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests the RDFa markup of imagefields.
 | 
			
		||||
| 
						 | 
				
			
			@ -14,6 +15,10 @@ use Drupal\file\Entity\File;
 | 
			
		|||
 */
 | 
			
		||||
class ImageFieldAttributesTest extends ImageFieldTestBase {
 | 
			
		||||
 | 
			
		||||
  use TestFileCreationTrait {
 | 
			
		||||
    getTestFiles as drupalGetTestFiles;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Modules to enable.
 | 
			
		||||
   *
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,7 @@
 | 
			
		|||
 | 
			
		||||
namespace Drupal\Tests\rdf\Functional;
 | 
			
		||||
 | 
			
		||||
use Drupal\node\Tests\NodeTestBase;
 | 
			
		||||
use Drupal\Tests\node\Functional\NodeTestBase;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests the RDFa markup of Nodes.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase {
 | 
			
		|||
  /**
 | 
			
		||||
   * {@inheritdoc}
 | 
			
		||||
   */
 | 
			
		||||
  public static $modules = ['text', 'filter'];
 | 
			
		||||
  public static $modules = ['text', 'filter', 'rdf_test'];
 | 
			
		||||
 | 
			
		||||
  protected function setUp() {
 | 
			
		||||
    parent::setUp();
 | 
			
		||||
| 
						 | 
				
			
			@ -33,7 +33,7 @@ class FieldRdfaDatatypeCallbackTest extends FieldRdfaTestBase {
 | 
			
		|||
    $mapping->setFieldMapping($this->fieldName, [
 | 
			
		||||
      'properties' => ['schema:interactionCount'],
 | 
			
		||||
      'datatype_callback' => [
 | 
			
		||||
        'callable' => 'Drupal\rdf\Tests\Field\TestDataConverter::convertFoo',
 | 
			
		||||
        'callable' => 'Drupal\rdf_test\TestDataConverter::convertFoo',
 | 
			
		||||
      ],
 | 
			
		||||
    ])->save();
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue