diff --git a/fivestar.info.yml b/fivestar.info.yml index 38a88d7..dd6f2c0 100644 --- a/fivestar.info.yml +++ b/fivestar.info.yml @@ -2,7 +2,7 @@ name: Fivestar type: module description: 'Enables fivestar ratings on content, users, etc.' package: Voting -core_version_requirement: ^8.8.2 || ^9 +core_version_requirement: ^8.8.2 || ^9 || ^10 dependencies: - votingapi:votingapi diff --git a/fivestar.libraries.yml b/fivestar.libraries.yml index 1e829b7..90123d1 100644 --- a/fivestar.libraries.yml +++ b/fivestar.libraries.yml @@ -7,9 +7,9 @@ fivestar.base: js/fivestar.js: {} dependencies: - - core/jquery - core/drupal - - core/jquery.once + - core/jquery + - core/once - core/drupal.ajax fivestar.admin: @@ -18,15 +18,6 @@ fivestar.admin: component: css/fivestar-admin.css: {} -fivestar.ajax: - version: VERSION - js: - js/fivestar.ajax.js: {} - dependencies: - - core/jquery - - core/drupal - - core/jquery.once - # Widgets # Right now does not include RTL handling basic: diff --git a/js/fivestar.js b/js/fivestar.js index c1b7ac1..973e229 100644 --- a/js/fivestar.js +++ b/js/fivestar.js @@ -20,7 +20,7 @@ } }); - $(context).find('div.fivestar-form-item').once('fivestar').each(function() { + $(once('fivestar', 'div.fivestar-form-item', context)).each(function() { var $cancel, $container, $options, $select, $this, index; $this = $(this); $container = $('
'); @@ -89,21 +89,4 @@ } } }; -})(jQuery); - - -/** - * @file - * - * Fivestar AJAX for updating fivestar widgets. - */ - -/** - * Create a degradeable star rating interface out of a simple form structure. - */ -(function($) { - Drupal.AjaxCommands.prototype.fivestarUpdate = function(ajax, response, status) { - response.selector = $('.fivestar-form-item', ajax.element.form); - ajax.commands.insert(ajax, response, status); - }; -})(jQuery); +})(jQuery, once); diff --git a/test/fivestar.base.test b/test/fivestar.base.test index 95cee23..33ad2d9 100644 --- a/test/fivestar.base.test +++ b/test/fivestar.base.test @@ -24,7 +24,7 @@ class FivestarBaseTestCase extends AJAXTestCase { /** * */ - public function setUp() { + public function setUp(): void { parent::setUp(['fivestar', 'dblog']); $type = $this->drupalCreateContentType(['type' => 'test_node_type', 'name' => 'test_node_type']); @@ -38,7 +38,7 @@ class FivestarBaseTestCase extends AJAXTestCase { * @param $options * An associative array of options for the field and instance. */ - public function createFivestarField($options = []) { + public function createFivestarField($options = []): void { $options = $options + [ 'content_type' => 'test_node_type', 'widget_type' => 'stars', diff --git a/test/fivestar.field.test b/test/fivestar.field.test index 547b107..91d3a66 100644 --- a/test/fivestar.field.test +++ b/test/fivestar.field.test @@ -13,7 +13,7 @@ class FivestarTestCase extends FivestarBaseTestCase { /** * */ - public static function getInfo() { + public static function getInfo(): array { return [ 'name' => 'Fivestar widgets', 'description' => 'Make sure fivestar widgets can be created and used.', @@ -24,7 +24,7 @@ class FivestarTestCase extends FivestarBaseTestCase { /** * Test that users can rate content with exposed widgets. */ - public function testViewerRating() { + public function testViewerRating(): void { $this->createFivestarField(['widget_type' => 'exposed']); // Add an test_node_type to rate. $node = $this->drupalCreateNode(['type' => 'test_node_type']); @@ -71,7 +71,7 @@ class FivestarTestCase extends FivestarBaseTestCase { /** * Test that users can rate content with exposed widgets. */ - public function testViewerRatingAjax() { + public function testViewerRatingAjax(): void { // Add a viewer-rated fivestar field to the test_node_type content type. $this->createFivestarField(['widget_type' => 'exposed']); // Add an test_node_type to rate. @@ -94,7 +94,7 @@ class FivestarTestCase extends FivestarBaseTestCase { * Test that we can switch the fivestar widgets around for the exposed * widget type. */ - public function testExposedWidgetDisplay() { + public function testExposedWidgetDisplay(): void { // Lets add an exposed widget but display the static widget. // It's simpler to compare the display type using the static widget. $this->createFivestarField([ diff --git a/tests/src/Functional/FivestarTest.php b/tests/src/Functional/FivestarTest.php index 7f69f0b..4bf4765 100644 --- a/tests/src/Functional/FivestarTest.php +++ b/tests/src/Functional/FivestarTest.php @@ -22,7 +22,7 @@ class FivestarTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected $defaultTheme = 'classy'; + protected $defaultTheme = 'stark'; /** * The entity display repository. @@ -48,7 +48,7 @@ class FivestarTest extends BrowserTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create content type for testing. @@ -74,7 +74,7 @@ class FivestarTest extends BrowserTestBase { /** * Tests that authors can rate their own content. */ - public function testAuthorRating() { + public function testAuthorRating(): void { $this->drupalLogin($this->adminUser); // Add an author-rated fivestar field to the test_node_type content type. $this->createFivestarField([ @@ -104,7 +104,7 @@ class FivestarTest extends BrowserTestBase { $this->submitForm($edit, 'Save'); // Make sure the two-star rating shows on the node view. - $elements = $this->xpath("//div[contains(@class, 'field--name-fivestar-test')]//div[contains(@class,'star-first')]/span"); + $elements = $this->xpath("//div[contains(@class, 'fivestar-widget-static-vote')]//div[contains(@class,'star-first')]/span"); $this->assertEquals('2', $elements[0]->getText(), 'Content authors can rate their own content using the stars widget.'); } @@ -114,7 +114,7 @@ class FivestarTest extends BrowserTestBase { * Tests that users cannot rate content with exposed widgets that has the * exposed display setting set to FALSE. */ - public function testViewerNonRating() { + public function testViewerNonRating(): void { // Add an exposed field, with the 'exposed' display settings set to FALSE. $this->createFivestarField([ 'widget_type' => 'exposed', @@ -142,7 +142,7 @@ class FivestarTest extends BrowserTestBase { // Rate the test_node_type. $this->drupalLogin($this->voterUser); $this->drupalGet('node/' . $node->id()); - $this->assertRaw('No votes yet', 'Fivestar field has no votes.'); + $this->assertSession()->pageTextContains('No votes yet'); $this->assertEmpty($this->xpath("//form[contains(@class, 'fivestar-widget')]")); // Check if node with attached fivestar field can be save. diff --git a/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php b/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php index 82487e4..bf980eb 100644 --- a/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php +++ b/tests/src/FunctionalJavascript/FivestarAjaxTestBase.php @@ -21,7 +21,7 @@ abstract class FivestarAjaxTestBase extends WebDriverTestBase { /** * {@inheritdoc} */ - protected $defaultTheme = 'classy'; + protected $defaultTheme = 'stark'; /** * The entity display repository. @@ -47,7 +47,7 @@ abstract class FivestarAjaxTestBase extends WebDriverTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); // Create content type for testing. diff --git a/tests/src/Kernel/HookFivestarWidgetsAlterTest.php b/tests/src/Kernel/HookFivestarWidgetsAlterTest.php index 53c0c45..f2b2e04 100644 --- a/tests/src/Kernel/HookFivestarWidgetsAlterTest.php +++ b/tests/src/Kernel/HookFivestarWidgetsAlterTest.php @@ -30,7 +30,7 @@ class HookFivestarWidgetsAlterTest extends KernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->widgetManager = $this->container->get('fivestar.widget_manager'); @@ -39,7 +39,7 @@ class HookFivestarWidgetsAlterTest extends KernelTestBase { /** * Tests that fivestar_widget_provider_fivestar_widgets_alter() was called. */ - public function testWidgetAlter() { + public function testWidgetAlter(): void { // Invoke the hook and collect all defined and altered widgets. $widgets = $this->widgetManager->getWidgets(); diff --git a/tests/src/Kernel/HookFivestarWidgetsTest.php b/tests/src/Kernel/HookFivestarWidgetsTest.php index 88bc193..10b5578 100644 --- a/tests/src/Kernel/HookFivestarWidgetsTest.php +++ b/tests/src/Kernel/HookFivestarWidgetsTest.php @@ -30,7 +30,7 @@ class HookFivestarWidgetsTest extends KernelTestBase { /** * {@inheritdoc} */ - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->widgetManager = $this->container->get('fivestar.widget_manager'); @@ -39,7 +39,7 @@ class HookFivestarWidgetsTest extends KernelTestBase { /** * Tests finding widgets defined by hook_fivestar_widgets(). */ - public function testWidgetDiscovery() { + public function testWidgetDiscovery(): void { $expected = [ // Awesome Stars is defined in the fivestar_widget_provider module. 'awesome' => [