Loading config/schema/nodeify.schema.yml 0 → 100644 +2 −0 Original line number Diff line number Diff line node.type.*.third_party.nodeify: type: ignore nodeify.routing.yml +1 −1 Original line number Diff line number Diff line Loading @@ -4,4 +4,4 @@ nodeify.notifications.settings: _form: '\Drupal\nodeify\Form\MessageSettingsForm' _title: 'Messages' requirements: _permission: 'administer nodeify notifications' _permission: 'administer nodeify' src/MessageHandler.php +2 −2 Original line number Diff line number Diff line Loading @@ -69,11 +69,11 @@ class MessageHandler extends NotificationHandlerBase { }); foreach ($filtered as $message) { drupal_set_message($message, 'status'); $this->messenger->addStatus($message); } if ($replacement) { drupal_set_message($replacement, 'status'); $this->messenger->addStatus($replacement); } } Loading tests/src/Functional/ConfigTest.php +98 −22 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\nodeify\Functional; use Drupal\node\NodeInterface; use Drupal\Tests\node\Functional\NodeTestBase; /** Loading @@ -20,27 +21,46 @@ class ConfigTest extends NodeTestBase { 'block' ]; public static $messageText = [ 'nodeify[create]' => 'New page created: "[node:title]".', 'nodeify[update]' => '[node:title] has been updated.', 'nodeify[delete]' => '[node:title] deleted.', ]; public static $userPermissions = [ 'bypass node access', 'administer content types', 'administer node fields' ]; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('system_breadcrumb_block'); } /** * Adds messages for update/delete/create and tests node save. * Tests access without administer nodeify permission. * * @throws \Behat\Mink\Exception\ResponseTextException */ public function testNodeTypeEditForm() { public function testUnauthorizedUser() { $assert_session = $this->assertSession(); $this->drupalPlaceBlock('system_breadcrumb_block'); $permissions = ['bypass node access', 'administer content types', 'administer node fields']; $permissions = self::$userPermissions; // User without specific permissions. $web_user = $this->drupalCreateUser($permissions); $this->drupalLogin($web_user); $this->drupalGet('admin/structure/types/manage/page'); $assert_session->pageTextNotContains('Message settings'); } /** * Adds configuration settings and tests node create/update/delete. */ public function testNodeTypeEditForm() { $assert_session = $this->assertSession(); $permissions = self::$userPermissions; $permissions[] = 'administer nodeify'; // User with the correct permission. $web_user = $this->drupalCreateUser($permissions); Loading @@ -48,12 +68,7 @@ class ConfigTest extends NodeTestBase { $this->drupalGet('admin/structure/types/manage/page'); $assert_session->pageTextContains('Message settings'); $message_text = [ 'nodeify[create]' => 'New page created', 'nodeify[update]' => 'Page updated', 'nodeify[delete]' => 'Page deleted', ]; $this->drupalPostForm('admin/structure/types/manage/page', $message_text, t('Save content type')); $this->drupalPostForm('admin/structure/types/manage/page', self::$messageText, t('Save content type')); $edit = [ 'title[0][value]' => 'Test page', Loading @@ -61,28 +76,89 @@ class ConfigTest extends NodeTestBase { ]; $this->drupalPostForm('node/add/page', $edit, t('Save')); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($message_text['nodeify[create]']); /** @var \Drupal\Node\NodeStorageInterface $node_storage */ $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); // Verify forum. $nodes = $node_storage->loadByProperties([ $node = $this->getSavedNode([ 'type' => 'page', 'title' => 'Test page', ]); $node = array_shift($nodes); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($this->getMessageText('create', $node)); $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save')); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($message_text['nodeify[update]']); $assert_session->pageTextContains($this->getMessageText('update', $node)); $this->drupalPostForm('node/' . $node->id() . '/delete', [], t('Delete')); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($message_text['nodeify[delete]']); $assert_session->pageTextContains($this->getMessageText('delete', $node)); // Save settings on the other configuration form. $new_create_message = 'Your basic page: [node:title], has been created.'; return [ 'id' => $node->id(), $this->drupalGet('admin/config/system/nodeify'); $this->drupalPostForm('admin/config/system/nodeify', [ 'page[create]' => $new_create_message, ], 'Save configuration'); $edit = [ 'title[0][value]' => 'Test page 2', 'body[0][value]' => 'Test body text 2', ]; $this->drupalPostForm('node/add/page', $edit, t('Save')); $assert_session->statusCodeEquals(200); $node = $this->getSavedNode([ 'type' => 'page', 'title' => 'Test page 2', ]); $assert_session->pageTextContains($this->replaceTitleToken($new_create_message, $node)); } /** * Fetches a particular node that has been saved by drupalPostForm. * * @param array $properties * * @return \Drupal\node\NodeInterface */ protected function getSavedNode(array $properties) { /** @var \Drupal\Node\NodeStorageInterface $node_storage */ $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); // Verify forum. $nodes = $node_storage->loadByProperties($properties); /** @var \Drupal\node\NodeInterface $node */ $node = array_shift($nodes); return $node; } /** * Gets message text from settings. * * @param $op * @param \Drupal\node\NodeInterface|NULL $node * * @return mixed */ protected function getMessageText($op, NodeInterface $node = NULL) { $message_text = self::$messageText; $text = $message_text["nodeify[$op]"]; if ($node) { $text = $this->replaceTitleToken($text, $node); } return $text; } /** * Replaces the title token for testing. * * @param $text * @param \Drupal\node\NodeInterface $node * * @return mixed */ protected function replaceTitleToken($text, NodeInterface $node) { return str_replace('[node:title]', $node->label(), $text); } } Loading
config/schema/nodeify.schema.yml 0 → 100644 +2 −0 Original line number Diff line number Diff line node.type.*.third_party.nodeify: type: ignore
nodeify.routing.yml +1 −1 Original line number Diff line number Diff line Loading @@ -4,4 +4,4 @@ nodeify.notifications.settings: _form: '\Drupal\nodeify\Form\MessageSettingsForm' _title: 'Messages' requirements: _permission: 'administer nodeify notifications' _permission: 'administer nodeify'
src/MessageHandler.php +2 −2 Original line number Diff line number Diff line Loading @@ -69,11 +69,11 @@ class MessageHandler extends NotificationHandlerBase { }); foreach ($filtered as $message) { drupal_set_message($message, 'status'); $this->messenger->addStatus($message); } if ($replacement) { drupal_set_message($replacement, 'status'); $this->messenger->addStatus($replacement); } } Loading
tests/src/Functional/ConfigTest.php +98 −22 Original line number Diff line number Diff line Loading @@ -2,6 +2,7 @@ namespace Drupal\Tests\nodeify\Functional; use Drupal\node\NodeInterface; use Drupal\Tests\node\Functional\NodeTestBase; /** Loading @@ -20,27 +21,46 @@ class ConfigTest extends NodeTestBase { 'block' ]; public static $messageText = [ 'nodeify[create]' => 'New page created: "[node:title]".', 'nodeify[update]' => '[node:title] has been updated.', 'nodeify[delete]' => '[node:title] deleted.', ]; public static $userPermissions = [ 'bypass node access', 'administer content types', 'administer node fields' ]; /** * {@inheritdoc} */ protected function setUp() { parent::setUp(); $this->drupalPlaceBlock('system_breadcrumb_block'); } /** * Adds messages for update/delete/create and tests node save. * Tests access without administer nodeify permission. * * @throws \Behat\Mink\Exception\ResponseTextException */ public function testNodeTypeEditForm() { public function testUnauthorizedUser() { $assert_session = $this->assertSession(); $this->drupalPlaceBlock('system_breadcrumb_block'); $permissions = ['bypass node access', 'administer content types', 'administer node fields']; $permissions = self::$userPermissions; // User without specific permissions. $web_user = $this->drupalCreateUser($permissions); $this->drupalLogin($web_user); $this->drupalGet('admin/structure/types/manage/page'); $assert_session->pageTextNotContains('Message settings'); } /** * Adds configuration settings and tests node create/update/delete. */ public function testNodeTypeEditForm() { $assert_session = $this->assertSession(); $permissions = self::$userPermissions; $permissions[] = 'administer nodeify'; // User with the correct permission. $web_user = $this->drupalCreateUser($permissions); Loading @@ -48,12 +68,7 @@ class ConfigTest extends NodeTestBase { $this->drupalGet('admin/structure/types/manage/page'); $assert_session->pageTextContains('Message settings'); $message_text = [ 'nodeify[create]' => 'New page created', 'nodeify[update]' => 'Page updated', 'nodeify[delete]' => 'Page deleted', ]; $this->drupalPostForm('admin/structure/types/manage/page', $message_text, t('Save content type')); $this->drupalPostForm('admin/structure/types/manage/page', self::$messageText, t('Save content type')); $edit = [ 'title[0][value]' => 'Test page', Loading @@ -61,28 +76,89 @@ class ConfigTest extends NodeTestBase { ]; $this->drupalPostForm('node/add/page', $edit, t('Save')); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($message_text['nodeify[create]']); /** @var \Drupal\Node\NodeStorageInterface $node_storage */ $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); // Verify forum. $nodes = $node_storage->loadByProperties([ $node = $this->getSavedNode([ 'type' => 'page', 'title' => 'Test page', ]); $node = array_shift($nodes); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($this->getMessageText('create', $node)); $this->drupalPostForm('node/' . $node->id() . '/edit', [], t('Save')); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($message_text['nodeify[update]']); $assert_session->pageTextContains($this->getMessageText('update', $node)); $this->drupalPostForm('node/' . $node->id() . '/delete', [], t('Delete')); $assert_session->statusCodeEquals(200); $assert_session->pageTextContains($message_text['nodeify[delete]']); $assert_session->pageTextContains($this->getMessageText('delete', $node)); // Save settings on the other configuration form. $new_create_message = 'Your basic page: [node:title], has been created.'; return [ 'id' => $node->id(), $this->drupalGet('admin/config/system/nodeify'); $this->drupalPostForm('admin/config/system/nodeify', [ 'page[create]' => $new_create_message, ], 'Save configuration'); $edit = [ 'title[0][value]' => 'Test page 2', 'body[0][value]' => 'Test body text 2', ]; $this->drupalPostForm('node/add/page', $edit, t('Save')); $assert_session->statusCodeEquals(200); $node = $this->getSavedNode([ 'type' => 'page', 'title' => 'Test page 2', ]); $assert_session->pageTextContains($this->replaceTitleToken($new_create_message, $node)); } /** * Fetches a particular node that has been saved by drupalPostForm. * * @param array $properties * * @return \Drupal\node\NodeInterface */ protected function getSavedNode(array $properties) { /** @var \Drupal\Node\NodeStorageInterface $node_storage */ $node_storage = $this->container->get('entity_type.manager')->getStorage('node'); // Verify forum. $nodes = $node_storage->loadByProperties($properties); /** @var \Drupal\node\NodeInterface $node */ $node = array_shift($nodes); return $node; } /** * Gets message text from settings. * * @param $op * @param \Drupal\node\NodeInterface|NULL $node * * @return mixed */ protected function getMessageText($op, NodeInterface $node = NULL) { $message_text = self::$messageText; $text = $message_text["nodeify[$op]"]; if ($node) { $text = $this->replaceTitleToken($text, $node); } return $text; } /** * Replaces the title token for testing. * * @param $text * @param \Drupal\node\NodeInterface $node * * @return mixed */ protected function replaceTitleToken($text, NodeInterface $node) { return str_replace('[node:title]', $node->label(), $text); } }