Drupal 8.0.0 beta 12. More info: https://www.drupal.org/node/2514176
This commit is contained in:
commit
9921556621
13277 changed files with 1459781 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
name: 'Forum test views'
|
||||
type: module
|
||||
description: 'Provides default views for views forum tests.'
|
||||
package: Testing
|
||||
version: VERSION
|
||||
core: 8.x
|
||||
dependencies:
|
||||
- forum
|
||||
- views
|
|
@ -0,0 +1,149 @@
|
|||
langcode: en
|
||||
status: true
|
||||
dependencies: { }
|
||||
id: test_forum_index
|
||||
label: test_forum_index
|
||||
module: views
|
||||
description: ''
|
||||
tag: ''
|
||||
base_table: forum_index
|
||||
base_field: nid
|
||||
core: 8.x
|
||||
display:
|
||||
default:
|
||||
display_plugin: default
|
||||
id: default
|
||||
display_title: Master
|
||||
position: null
|
||||
display_options:
|
||||
access:
|
||||
type: none
|
||||
cache:
|
||||
type: tag
|
||||
query:
|
||||
type: views_query
|
||||
exposed_form:
|
||||
type: basic
|
||||
pager:
|
||||
type: full
|
||||
style:
|
||||
type: default
|
||||
row:
|
||||
type: fields
|
||||
fields:
|
||||
nid:
|
||||
table: forum_index
|
||||
field: nid
|
||||
id: nid
|
||||
sticky:
|
||||
id: sticky
|
||||
table: forum_index
|
||||
field: sticky
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: Sticky
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
type: yes-no
|
||||
type_custom_true: ''
|
||||
type_custom_false: ''
|
||||
not: false
|
||||
plugin_id: boolean
|
||||
comment_count:
|
||||
id: comment_count
|
||||
table: forum_index
|
||||
field: comment_count
|
||||
relationship: none
|
||||
group_type: group
|
||||
admin_label: ''
|
||||
label: 'Comment count'
|
||||
exclude: false
|
||||
alter:
|
||||
alter_text: false
|
||||
text: ''
|
||||
make_link: false
|
||||
path: ''
|
||||
absolute: false
|
||||
external: false
|
||||
replace_spaces: false
|
||||
path_case: none
|
||||
trim_whitespace: false
|
||||
alt: ''
|
||||
rel: ''
|
||||
link_class: ''
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
target: ''
|
||||
nl2br: false
|
||||
max_length: 0
|
||||
word_boundary: true
|
||||
ellipsis: true
|
||||
more_link: false
|
||||
more_link_text: ''
|
||||
more_link_path: ''
|
||||
strip_tags: false
|
||||
trim: false
|
||||
preserve_tags: ''
|
||||
html: false
|
||||
element_type: ''
|
||||
element_class: ''
|
||||
element_label_type: ''
|
||||
element_label_class: ''
|
||||
element_label_colon: true
|
||||
element_wrapper_type: ''
|
||||
element_wrapper_class: ''
|
||||
element_default_classes: true
|
||||
empty: ''
|
||||
hide_empty: false
|
||||
empty_zero: false
|
||||
hide_alter_empty: true
|
||||
set_precision: false
|
||||
precision: 0
|
||||
decimal: .
|
||||
separator: ','
|
||||
format_plural: false
|
||||
format_plural_string: "1\x03@count"
|
||||
prefix: ''
|
||||
suffix: ''
|
||||
plugin_id: numeric
|
||||
filters: { }
|
||||
sorts: { }
|
|
@ -0,0 +1,134 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\forum\Unit\Breadcrumb\ForumBreadcrumbBuilderBaseTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\forum\Unit\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase
|
||||
* @group forum
|
||||
*/
|
||||
class ForumBreadcrumbBuilderBaseTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests ForumBreadcrumbBuilderBase::__construct().
|
||||
*
|
||||
* @covers ::__construct
|
||||
*/
|
||||
public function testConstructor() {
|
||||
// Make some test doubles.
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$config_factory = $this->getConfigFactoryStub(
|
||||
array(
|
||||
'forum.settings' => array('IAmATestKey' => 'IAmATestValue'),
|
||||
)
|
||||
);
|
||||
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
|
||||
|
||||
// Make an object to test.
|
||||
$builder = $this->getMockForAbstractClass(
|
||||
'Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase',
|
||||
// Constructor array.
|
||||
array(
|
||||
$entity_manager,
|
||||
$config_factory,
|
||||
$forum_manager,
|
||||
)
|
||||
);
|
||||
|
||||
// Reflect upon our properties, except for config which is a special case.
|
||||
$property_names = array(
|
||||
'entityManager' => $entity_manager,
|
||||
'forumManager' => $forum_manager,
|
||||
);
|
||||
foreach ($property_names as $property_name => $property_value) {
|
||||
$this->assertAttributeEquals(
|
||||
$property_value, $property_name, $builder
|
||||
);
|
||||
}
|
||||
|
||||
// Test that the constructor made a config object with our info in it.
|
||||
$reflector = new \ReflectionClass($builder);
|
||||
$ref_property = $reflector->getProperty('config');
|
||||
$ref_property->setAccessible(TRUE);
|
||||
$config = $ref_property->getValue($builder);
|
||||
$this->assertEquals('IAmATestValue', $config->get('IAmATestKey'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ForumBreadcrumbBuilderBase::build().
|
||||
*
|
||||
* @see \Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase::build()
|
||||
*
|
||||
* @covers ::build
|
||||
*/
|
||||
public function testBuild() {
|
||||
// Build all our dependencies, backwards.
|
||||
$forum_manager = $this->getMockBuilder('Drupal\forum\ForumManagerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$vocab_item = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocab_item->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Fora_is_the_plural_of_forum'));
|
||||
|
||||
$vocab_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
$vocab_storage->expects($this->any())
|
||||
->method('load')
|
||||
->will($this->returnValueMap(array(
|
||||
array('forums', $vocab_item),
|
||||
)));
|
||||
|
||||
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$entity_manager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->will($this->returnValueMap(array(
|
||||
array('taxonomy_vocabulary', $vocab_storage),
|
||||
)));
|
||||
|
||||
$config_factory = $this->getConfigFactoryStub(
|
||||
array(
|
||||
'forum.settings' => array(
|
||||
'vocabulary' => 'forums',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Build a breadcrumb builder to test.
|
||||
$breadcrumb_builder = $this->getMockForAbstractClass(
|
||||
'Drupal\forum\Breadcrumb\ForumBreadcrumbBuilderBase',
|
||||
// Constructor array.
|
||||
array(
|
||||
$entity_manager,
|
||||
$config_factory,
|
||||
$forum_manager,
|
||||
)
|
||||
);
|
||||
|
||||
// Add a translation manager for t().
|
||||
$translation_manager = $this->getStringTranslationStub();
|
||||
$breadcrumb_builder->setStringTranslation($translation_manager);
|
||||
|
||||
// Our empty data set.
|
||||
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
|
||||
|
||||
// Expected result set.
|
||||
$expected = array(
|
||||
Link::createFromRoute('Home', '<front>'),
|
||||
Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
|
||||
);
|
||||
|
||||
// And finally, the test.
|
||||
$this->assertEquals($expected, $breadcrumb_builder->build($route_match));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,212 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\forum\Unit\Breadcrumb\ForumListingBreadcrumbBuilderTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\forum\Unit\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder
|
||||
* @group forum
|
||||
*/
|
||||
class ForumListingBreadcrumbBuilderTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests ForumListingBreadcrumbBuilder::applies().
|
||||
*
|
||||
* @param bool $expected
|
||||
* ForumListingBreadcrumbBuilder::applies() expected result.
|
||||
* @param string|null $route_name
|
||||
* (optional) A route name.
|
||||
* @param array $parameter_map
|
||||
* (optional) An array of parameter names and values.
|
||||
*
|
||||
* @dataProvider providerTestApplies
|
||||
* @covers ::applies
|
||||
*/
|
||||
public function testApplies($expected, $route_name = NULL, $parameter_map = array()) {
|
||||
// Make some test doubles.
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$config_factory = $this->getConfigFactoryStub(array());
|
||||
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
|
||||
|
||||
// Make an object to test.
|
||||
$builder = $this->getMockBuilder('Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder')
|
||||
->setConstructorArgs(array(
|
||||
$entity_manager,
|
||||
$config_factory,
|
||||
$forum_manager,
|
||||
))
|
||||
->setMethods(NULL)
|
||||
->getMock();
|
||||
|
||||
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
|
||||
$route_match->expects($this->once())
|
||||
->method('getRouteName')
|
||||
->will($this->returnValue($route_name));
|
||||
$route_match->expects($this->any())
|
||||
->method('getParameter')
|
||||
->will($this->returnValueMap($parameter_map));
|
||||
|
||||
$this->assertEquals($expected, $builder->applies($route_match));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for testApplies().
|
||||
*
|
||||
* @return array
|
||||
* Array of datasets for testApplies(). Structured as such:
|
||||
* - ForumListBreadcrumbBuilder::applies() expected result.
|
||||
* - ForumListBreadcrumbBuilder::applies() $attributes input array.
|
||||
*/
|
||||
public function providerTestApplies() {
|
||||
// Send a Node mock, because NodeInterface cannot be mocked.
|
||||
$mock_term = $this->getMockBuilder('Drupal\taxonomy\Entity\Term')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
return array(
|
||||
array(
|
||||
FALSE,
|
||||
),
|
||||
array(
|
||||
FALSE,
|
||||
'NOT.forum.page',
|
||||
),
|
||||
array(
|
||||
FALSE,
|
||||
'forum.page',
|
||||
),
|
||||
array(
|
||||
TRUE,
|
||||
'forum.page',
|
||||
array(array('taxonomy_term', 'anything')),
|
||||
),
|
||||
array(
|
||||
TRUE,
|
||||
'forum.page',
|
||||
array(array('taxonomy_term', $mock_term)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ForumListingBreadcrumbBuilder::build().
|
||||
*
|
||||
* @see \Drupal\forum\ForumListingBreadcrumbBuilder::build()
|
||||
*
|
||||
* @covers ::build
|
||||
*/
|
||||
public function testBuild() {
|
||||
// Build all our dependencies, backwards.
|
||||
$term1 = $this->getMockBuilder('Drupal\taxonomy\Entity\Term')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$term1->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Something'));
|
||||
$term1->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$term2 = $this->getMockBuilder('Drupal\taxonomy\Entity\Term')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$term2->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Something else'));
|
||||
$term2->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(2));
|
||||
|
||||
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
|
||||
$forum_manager->expects($this->at(0))
|
||||
->method('getParents')
|
||||
->will($this->returnValue(array($term1)));
|
||||
$forum_manager->expects($this->at(1))
|
||||
->method('getParents')
|
||||
->will($this->returnValue(array($term1, $term2)));
|
||||
|
||||
// The root forum.
|
||||
$vocab_item = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocab_item->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Fora_is_the_plural_of_forum'));
|
||||
$vocab_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
$vocab_storage->expects($this->any())
|
||||
->method('load')
|
||||
->will($this->returnValueMap(array(
|
||||
array('forums', $vocab_item),
|
||||
)));
|
||||
|
||||
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$entity_manager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->will($this->returnValueMap(array(
|
||||
array('taxonomy_vocabulary', $vocab_storage),
|
||||
)));
|
||||
|
||||
$config_factory = $this->getConfigFactoryStub(
|
||||
array(
|
||||
'forum.settings' => array(
|
||||
'vocabulary' => 'forums',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Build a breadcrumb builder to test.
|
||||
$breadcrumb_builder = $this->getMock(
|
||||
'Drupal\forum\Breadcrumb\ForumListingBreadcrumbBuilder', NULL, array(
|
||||
$entity_manager,
|
||||
$config_factory,
|
||||
$forum_manager,
|
||||
)
|
||||
);
|
||||
|
||||
// Add a translation manager for t().
|
||||
$translation_manager = $this->getStringTranslationStub();
|
||||
$breadcrumb_builder->setStringTranslation($translation_manager);
|
||||
|
||||
// The forum listing we need a breadcrumb back from.
|
||||
$forum_listing = $this->getMockBuilder('Drupal\taxonomy\Entity\Term')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$forum_listing->tid = 23;
|
||||
$forum_listing->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('You_should_not_see_this'));
|
||||
|
||||
// Our data set.
|
||||
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
|
||||
$route_match->expects($this->exactly(2))
|
||||
->method('getParameter')
|
||||
->with('taxonomy_term')
|
||||
->will($this->returnValue($forum_listing));
|
||||
|
||||
// First test.
|
||||
$expected1 = array(
|
||||
Link::createFromRoute('Home', '<front>'),
|
||||
Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
|
||||
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
|
||||
);
|
||||
$this->assertEquals($expected1, $breadcrumb_builder->build($route_match));
|
||||
|
||||
// Second test.
|
||||
$expected2 = array(
|
||||
Link::createFromRoute('Home', '<front>'),
|
||||
Link::createFromRoute('Fora_is_the_plural_of_forum', 'forum.index'),
|
||||
Link::createFromRoute('Something else', 'forum.page', array('taxonomy_term' => 2)),
|
||||
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
|
||||
);
|
||||
$this->assertEquals($expected2, $breadcrumb_builder->build($route_match));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,218 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\forum\Unit\Breadcrumb\ForumNodeBreadcrumbBuilderTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\forum\Unit\Breadcrumb;
|
||||
|
||||
use Drupal\Core\Link;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder
|
||||
* @group forum
|
||||
*/
|
||||
class ForumNodeBreadcrumbBuilderTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests ForumNodeBreadcrumbBuilder::applies().
|
||||
*
|
||||
* @param bool $expected
|
||||
* ForumNodeBreadcrumbBuilder::applies() expected result.
|
||||
* @param string|null $route_name
|
||||
* (optional) A route name.
|
||||
* @param array $parameter_map
|
||||
* (optional) An array of parameter names and values.
|
||||
*
|
||||
* @dataProvider providerTestApplies
|
||||
* @covers ::applies
|
||||
*/
|
||||
public function testApplies($expected, $route_name = NULL, $parameter_map = array()) {
|
||||
// Make some test doubles.
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
$config_factory = $this->getConfigFactoryStub(array());
|
||||
|
||||
$forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
|
||||
$forum_manager->expects($this->any())
|
||||
->method('checkNodeType')
|
||||
->will($this->returnValue(TRUE));
|
||||
|
||||
// Make an object to test.
|
||||
$builder = $this->getMockBuilder('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder')
|
||||
->setConstructorArgs(
|
||||
array(
|
||||
$entity_manager,
|
||||
$config_factory,
|
||||
$forum_manager,
|
||||
)
|
||||
)
|
||||
->setMethods(NULL)
|
||||
->getMock();
|
||||
|
||||
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
|
||||
$route_match->expects($this->once())
|
||||
->method('getRouteName')
|
||||
->will($this->returnValue($route_name));
|
||||
$route_match->expects($this->any())
|
||||
->method('getParameter')
|
||||
->will($this->returnValueMap($parameter_map));
|
||||
|
||||
$this->assertEquals($expected, $builder->applies($route_match));
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides test data for testApplies().
|
||||
*
|
||||
* Note that this test is incomplete, because we can't mock NodeInterface.
|
||||
*
|
||||
* @return array
|
||||
* Array of datasets for testApplies(). Structured as such:
|
||||
* - ForumNodeBreadcrumbBuilder::applies() expected result.
|
||||
* - ForumNodeBreadcrumbBuilder::applies() $attributes input array.
|
||||
*/
|
||||
public function providerTestApplies() {
|
||||
// Send a Node mock, because NodeInterface cannot be mocked.
|
||||
$mock_node = $this->getMockBuilder('Drupal\node\Entity\Node')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
return array(
|
||||
array(
|
||||
FALSE,
|
||||
),
|
||||
array(
|
||||
FALSE,
|
||||
'NOT.entity.node.canonical',
|
||||
),
|
||||
array(
|
||||
FALSE,
|
||||
'entity.node.canonical',
|
||||
),
|
||||
array(
|
||||
FALSE,
|
||||
'entity.node.canonical',
|
||||
array(array('node', NULL)),
|
||||
),
|
||||
array(
|
||||
TRUE,
|
||||
'entity.node.canonical',
|
||||
array(array('node', $mock_node)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests ForumNodeBreadcrumbBuilder::build().
|
||||
*
|
||||
* @see \Drupal\forum\ForumNodeBreadcrumbBuilder::build()
|
||||
* @covers ::build
|
||||
*/
|
||||
public function testBuild() {
|
||||
// Build all our dependencies, backwards.
|
||||
$term1 = $this->getMockBuilder('Drupal\Core\Entity\EntityInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$term1->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Something'));
|
||||
$term1->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(1));
|
||||
|
||||
$term2 = $this->getMockBuilder('Drupal\Core\Entity\EntityInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$term2->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Something else'));
|
||||
$term2->expects($this->any())
|
||||
->method('id')
|
||||
->will($this->returnValue(2));
|
||||
|
||||
$forum_manager = $this->getMockBuilder('Drupal\forum\ForumManagerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$forum_manager->expects($this->at(0))
|
||||
->method('getParents')
|
||||
->will($this->returnValue(array($term1)));
|
||||
$forum_manager->expects($this->at(1))
|
||||
->method('getParents')
|
||||
->will($this->returnValue(array($term1, $term2)));
|
||||
|
||||
$vocab_item = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocab_item->expects($this->any())
|
||||
->method('label')
|
||||
->will($this->returnValue('Forums'));
|
||||
$vocab_storage = $this->getMock('Drupal\Core\Entity\EntityStorageInterface');
|
||||
$vocab_storage->expects($this->any())
|
||||
->method('load')
|
||||
->will($this->returnValueMap(array(
|
||||
array('forums', $vocab_item),
|
||||
)));
|
||||
|
||||
$entity_manager = $this->getMockBuilder('Drupal\Core\Entity\EntityManagerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$entity_manager->expects($this->any())
|
||||
->method('getStorage')
|
||||
->will($this->returnValueMap(array(
|
||||
array('taxonomy_vocabulary', $vocab_storage),
|
||||
)));
|
||||
|
||||
$config_factory = $this->getConfigFactoryStub(
|
||||
array(
|
||||
'forum.settings' => array(
|
||||
'vocabulary' => 'forums',
|
||||
),
|
||||
)
|
||||
);
|
||||
|
||||
// Build a breadcrumb builder to test.
|
||||
$breadcrumb_builder = $this->getMock(
|
||||
'Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', NULL, array(
|
||||
$entity_manager,
|
||||
$config_factory,
|
||||
$forum_manager,
|
||||
)
|
||||
);
|
||||
|
||||
// Add a translation manager for t().
|
||||
$translation_manager = $this->getStringTranslationStub();
|
||||
$property = new \ReflectionProperty('Drupal\forum\Breadcrumb\ForumNodeBreadcrumbBuilder', 'stringTranslation');
|
||||
$property->setAccessible(TRUE);
|
||||
$property->setValue($breadcrumb_builder, $translation_manager);
|
||||
|
||||
// The forum node we need a breadcrumb back from.
|
||||
$forum_node = $this->getMockBuilder('Drupal\node\Entity\Node')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
// Our data set.
|
||||
$route_match = $this->getMock('Drupal\Core\Routing\RouteMatchInterface');
|
||||
$route_match->expects($this->exactly(2))
|
||||
->method('getParameter')
|
||||
->with('node')
|
||||
->will($this->returnValue($forum_node));
|
||||
|
||||
// First test.
|
||||
$expected1 = array(
|
||||
Link::createFromRoute('Home', '<front>'),
|
||||
Link::createFromRoute('Forums', 'forum.index'),
|
||||
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
|
||||
);
|
||||
$this->assertEquals($expected1, $breadcrumb_builder->build($route_match));
|
||||
|
||||
// Second test.
|
||||
$expected2 = array(
|
||||
Link::createFromRoute('Home', '<front>'),
|
||||
Link::createFromRoute('Forums', 'forum.index'),
|
||||
Link::createFromRoute('Something else', 'forum.page', array('taxonomy_term' => 2)),
|
||||
Link::createFromRoute('Something', 'forum.page', array('taxonomy_term' => 1)),
|
||||
);
|
||||
$this->assertEquals($expected2, $breadcrumb_builder->build($route_match));
|
||||
}
|
||||
|
||||
}
|
88
core/modules/forum/tests/src/Unit/ForumManagerTest.php
Normal file
88
core/modules/forum/tests/src/Unit/ForumManagerTest.php
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\forum\Unit\ForumManagerTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\forum\Unit;
|
||||
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\forum\ForumManager
|
||||
* @group forum
|
||||
*/
|
||||
class ForumManagerTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* Tests ForumManager::getIndex().
|
||||
*/
|
||||
public function testGetIndex() {
|
||||
$entity_manager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
|
||||
|
||||
$storage = $this->getMockBuilder('\Drupal\taxonomy\VocabularyStorage')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$config_factory = $this->getMock('\Drupal\Core\Config\ConfigFactoryInterface');
|
||||
|
||||
$config = $this->getMockBuilder('\Drupal\Core\Config\Config')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$config_factory->expects($this->once())
|
||||
->method('get')
|
||||
->will($this->returnValue($config));
|
||||
|
||||
$config->expects($this->once())
|
||||
->method('get')
|
||||
->will($this->returnValue('forums'));
|
||||
|
||||
$entity_manager->expects($this->once())
|
||||
->method('getStorage')
|
||||
->will($this->returnValue($storage));
|
||||
|
||||
// This is sufficient for testing purposes.
|
||||
$term = new \stdClass();
|
||||
|
||||
$storage->expects($this->once())
|
||||
->method('create')
|
||||
->will($this->returnValue($term));
|
||||
|
||||
$connection = $this->getMockBuilder('\Drupal\Core\Database\Connection')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$translation_manager = $this->getMockBuilder('\Drupal\Core\StringTranslation\TranslationManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$comment_manager = $this->getMockBuilder('\Drupal\comment\CommentManagerInterface')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$manager = $this->getMock('\Drupal\forum\ForumManager', array('getChildren'), array(
|
||||
$config_factory,
|
||||
$entity_manager,
|
||||
$connection,
|
||||
$translation_manager,
|
||||
$comment_manager,
|
||||
));
|
||||
|
||||
$manager->expects($this->once())
|
||||
->method('getChildren')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
// Get the index once.
|
||||
$index1 = $manager->getIndex();
|
||||
|
||||
// Get it again. This should not return the previously generated index. If
|
||||
// it does not, then the test will fail as the mocked methods will be called
|
||||
// more than once.
|
||||
$index2 = $manager->getIndex();
|
||||
|
||||
$this->assertEquals($index1, $index2);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,247 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Contains \Drupal\Tests\forum\Unit\ForumUninstallValidatorTest.
|
||||
*/
|
||||
|
||||
namespace Drupal\Tests\forum\Unit;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\forum\ForumUninstallValidator
|
||||
* @group forum
|
||||
*/
|
||||
class ForumUninstallValidatorTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\forum\ForumUninstallValidator|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
protected $forumUninstallValidator;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->forumUninstallValidator = $this->getMockBuilder('Drupal\forum\ForumUninstallValidator')
|
||||
->disableOriginalConstructor()
|
||||
->setMethods(['hasForumNodes', 'hasTermsForVocabulary', 'getForumVocabulary'])
|
||||
->getMock();
|
||||
$this->forumUninstallValidator->setStringTranslation($this->getStringTranslationStub());
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateNotForum() {
|
||||
$this->forumUninstallValidator->expects($this->never())
|
||||
->method('hasForumNodes');
|
||||
$this->forumUninstallValidator->expects($this->never())
|
||||
->method('hasTermsForVocabulary');
|
||||
$this->forumUninstallValidator->expects($this->never())
|
||||
->method('getForumVocabulary');
|
||||
|
||||
$module = 'not_forum';
|
||||
$expected = [];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidate() {
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasForumNodes')
|
||||
->willReturn(FALSE);
|
||||
|
||||
$vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('getForumVocabulary')
|
||||
->willReturn($vocabulary);
|
||||
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasTermsForVocabulary')
|
||||
->willReturn(FALSE);
|
||||
|
||||
$module = 'forum';
|
||||
$expected = [];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateHasForumNodes() {
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasForumNodes')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('getForumVocabulary')
|
||||
->willReturn($vocabulary);
|
||||
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasTermsForVocabulary')
|
||||
->willReturn(FALSE);
|
||||
|
||||
$module = 'forum';
|
||||
$expected = [
|
||||
'To uninstall Forum, first delete all <em>Forum</em> content',
|
||||
];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateHasTermsForVocabularyWithNodesAccess() {
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasForumNodes')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('label')
|
||||
->willReturn('Vocabulary label');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('url')
|
||||
->willReturn('/path/to/vocabulary/overview');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('access')
|
||||
->willReturn(TRUE);
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('getForumVocabulary')
|
||||
->willReturn($vocabulary);
|
||||
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasTermsForVocabulary')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$module = 'forum';
|
||||
$expected = [
|
||||
'To uninstall Forum, first delete all <em>Forum</em> content',
|
||||
SafeMarkup::format('To uninstall Forum, first delete all <a href="@url">%vocabulary</a> terms', [
|
||||
'@url' => '/path/to/vocabulary/overview',
|
||||
'%vocabulary' => 'Vocabulary label',
|
||||
]),
|
||||
];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateHasTermsForVocabularyWithNodesNoAccess() {
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasForumNodes')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('label')
|
||||
->willReturn('Vocabulary label');
|
||||
$vocabulary->expects($this->never())
|
||||
->method('url');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('access')
|
||||
->willReturn(FALSE);
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('getForumVocabulary')
|
||||
->willReturn($vocabulary);
|
||||
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasTermsForVocabulary')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$module = 'forum';
|
||||
$expected = [
|
||||
'To uninstall Forum, first delete all <em>Forum</em> content',
|
||||
SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', [
|
||||
'%vocabulary' => 'Vocabulary label',
|
||||
]),
|
||||
];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateHasTermsForVocabularyAccess() {
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasForumNodes')
|
||||
->willReturn(FALSE);
|
||||
|
||||
$vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('url')
|
||||
->willReturn('/path/to/vocabulary/overview');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('label')
|
||||
->willReturn('Vocabulary label');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('access')
|
||||
->willReturn(TRUE);
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('getForumVocabulary')
|
||||
->willReturn($vocabulary);
|
||||
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasTermsForVocabulary')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$module = 'forum';
|
||||
$expected = [
|
||||
SafeMarkup::format('To uninstall Forum, first delete all <a href="@url">%vocabulary</a> terms', [
|
||||
'@url' => '/path/to/vocabulary/overview',
|
||||
'%vocabulary' => 'Vocabulary label',
|
||||
]),
|
||||
];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::validate
|
||||
*/
|
||||
public function testValidateHasTermsForVocabularyNoAccess() {
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasForumNodes')
|
||||
->willReturn(FALSE);
|
||||
|
||||
$vocabulary = $this->getMock('Drupal\taxonomy\VocabularyInterface');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('label')
|
||||
->willReturn('Vocabulary label');
|
||||
$vocabulary->expects($this->never())
|
||||
->method('url');
|
||||
$vocabulary->expects($this->once())
|
||||
->method('access')
|
||||
->willReturn(FALSE);
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('getForumVocabulary')
|
||||
->willReturn($vocabulary);
|
||||
|
||||
$this->forumUninstallValidator->expects($this->once())
|
||||
->method('hasTermsForVocabulary')
|
||||
->willReturn(TRUE);
|
||||
|
||||
$module = 'forum';
|
||||
$expected = [
|
||||
SafeMarkup::format('To uninstall Forum, first delete all %vocabulary terms', [
|
||||
'%vocabulary' => 'Vocabulary label',
|
||||
]),
|
||||
];
|
||||
$reasons = $this->forumUninstallValidator->validate($module);
|
||||
$this->assertSame($expected, $reasons);
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue