diff --git a/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php b/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php index bc0ed8c..025e6ca 100644 --- a/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php +++ b/core/modules/comment/lib/Drupal/comment/Routing/CommentBundleEnhancer.php @@ -30,6 +30,9 @@ class CommentBundleEnhancer implements RouteEnhancerInterface { /** * Constructs a CommentBundleEnhancer object. + * + * @param \Drupal\Core\Entity\EntityManager $entity_manager + * The entity manager service. */ public function __construct(EntityManager $entity_manager) { $this->entityManager = $entity_manager; diff --git a/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php b/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php index 9511cdb..d86d1ba 100644 --- a/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php +++ b/core/modules/comment/tests/Drupal/comment/Tests/Routing/CommentBundleEnhancerTest.php @@ -21,16 +21,55 @@ public static function getInfo() { return array( 'name' => 'Comment route enhancer test', 'description' => 'Tests the comment route enhancer.', - 'group' => 'Comment' + 'group' => 'Comment', ); } /** + * Data provider for testEnhancer(). + * + * @see testEnhancer() + * + * @return array + * An array of arrays containing strings: + * - The bundle name. + * - The commented entity type. + * - The field name. + */ + public function providerTestEnhancer() { + return array( + array( + 'node__comment', + 'comment', + 'node', + ), + array( + 'node__comment_forum__schnitzel', + 'comment_forum__schnitzel', + 'node', + ), + array( + 'node__field_foobar', + FALSE, + FALSE + ), + ); + } + /** * Tests the enhancer method. * + * @param string $bundle + * The bundle name to test. + * @param string $field_name + * The field name expected to be extracted from the bundle. + * @param string $commented_entity_type + * The entity type expected to be extracted from the bundle. + * * @see \Drupal\comment\Routing\CommentBundleEnhancer::enhancer() + * + * @dataProvider providerTestEnhancer */ - public function testEnhancer() { + public function testEnhancer($bundle, $field_name, $commented_entity_type) { $entityManager = $this->getMockBuilder('\Drupal\Core\Entity\EntityManager') ->disableOriginalConstructor() ->getMock(); @@ -38,23 +77,25 @@ public function testEnhancer() { ->method('getBundleInfo') ->will($this->returnValue(array( 'node__comment' => array(), - 'node__comment_forum' => array(), + // Test two sets of __. + 'node__comment_forum__schnitzel' => array(), ))); $route_enhancer = new CommentBundleEnhancer($entityManager); - // Test with a comment bundle. - $request = new Request(); - $defaults = array('bundle' => 'node__comment'); - $new_defaults = $route_enhancer->enhance($defaults, $request); - $this->assertEquals($new_defaults['field_name'], 'comment'); - $this->assertEquals($new_defaults['commented_entity_type'], 'node'); - - // Test again with a non-comment bundle + // Test the enhancer. $request = new Request(); - $defaults = array('bundle' => 'node__field_foobar'); + $defaults = array('bundle' => $bundle); $new_defaults = $route_enhancer->enhance($defaults, $request); - $this->assertTrue(empty($new_defaults['field_name'])); - $this->assertTrue(empty($new_defaults['commented_entity_type'])); + if ($commented_entity_type) { + // A valid comment bundle. + $this->assertEquals($new_defaults['field_name'], $field_name); + $this->assertEquals($new_defaults['commented_entity_type'], $commented_entity_type); + } + else { + // Non-comment bundle. + $this->assertTrue(empty($new_defaults['field_name'])); + $this->assertTrue(empty($new_defaults['commented_entity_type'])); + } } }