当前位置: 首页>>代码示例>>PHP>>正文


PHP UserInterface::block方法代码示例

本文整理汇总了PHP中Drupal\user\UserInterface::block方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::block方法的具体用法?PHP UserInterface::block怎么用?PHP UserInterface::block使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\user\UserInterface的用法示例。


在下文中一共展示了UserInterface::block方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testPersonalContactAccess

 /**
  * Tests access to the personal contact form.
  */
 function testPersonalContactAccess()
 {
     // Test allowed access to admin user's contact form.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
     $this->assertResponse(200);
     // Check the page title is properly displayed.
     $this->assertRaw(t('Contact @username', array('@username' => $this->adminUser->getDisplayName())));
     // Test denied access to admin user's own contact form.
     $this->drupalLogout();
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
     $this->assertResponse(403);
     // Test allowed access to user with contact form enabled.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(200);
     // Test that there is no access to personal contact forms for users
     // without an email address configured.
     $original_email = $this->contactUser->getEmail();
     $this->contactUser->setEmail(FALSE)->save();
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(404, 'Not found (404) returned when visiting a personal contact form for a user with no email address');
     // Test that the 'contact tab' does not appear on the user profiles
     // for users without an email address configured.
     $this->drupalGet('user/' . $this->contactUser->id());
     $contact_link = '/user/' . $this->contactUser->id() . '/contact';
     $this->assertResponse(200);
     $this->assertNoLinkByHref($contact_link, 'The "contact" tab is hidden on profiles for users with no email address');
     // Restore original email address.
     $this->contactUser->setEmail($original_email)->save();
     // Test denied access to the user's own contact form.
     $this->drupalGet('user/' . $this->webUser->id() . '/contact');
     $this->assertResponse(403);
     // Test always denied access to the anonymous user contact form.
     $this->drupalGet('user/0/contact');
     $this->assertResponse(403);
     // Test that anonymous users can access the contact form.
     $this->drupalLogout();
     user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access user contact forms'));
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(200);
     // Test that anonymous users can access admin user's contact form.
     $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
     $this->assertResponse(200);
     $this->assertCacheContext('user');
     // Revoke the personal contact permission for the anonymous user.
     user_role_revoke_permissions(RoleInterface::ANONYMOUS_ID, array('access user contact forms'));
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(403);
     $this->assertCacheContext('user');
     $this->drupalGet('user/' . $this->adminUser->id() . '/contact');
     $this->assertResponse(403);
     // Disable the personal contact form.
     $this->drupalLogin($this->adminUser);
     $edit = array('contact_default_status' => FALSE);
     $this->drupalPostForm('admin/config/people/accounts', $edit, t('Save configuration'));
     $this->assertText(t('The configuration options have been saved.'), 'Setting successfully saved.');
     $this->drupalLogout();
     // Re-create our contacted user with personal contact forms disabled by
     // default.
     $this->contactUser = $this->drupalCreateUser();
     // Test denied access to a user with contact form disabled.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(403);
     // Test allowed access for admin user to a user with contact form disabled.
     $this->drupalLogin($this->adminUser);
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(200);
     // Re-create our contacted user as a blocked user.
     $this->contactUser = $this->drupalCreateUser();
     $this->contactUser->block();
     $this->contactUser->save();
     // Test that blocked users can still be contacted by admin.
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(200);
     // Test that blocked users cannot be contacted by non-admins.
     $this->drupalLogin($this->webUser);
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(403);
     // Test enabling and disabling the contact page through the user profile
     // form.
     $this->drupalGet('user/' . $this->webUser->id() . '/edit');
     $this->assertNoFieldChecked('edit-contact--2');
     $this->assertFalse(\Drupal::service('user.data')->get('contact', $this->webUser->id(), 'enabled'), 'Personal contact form disabled');
     $this->drupalPostForm(NULL, array('contact' => TRUE), t('Save'));
     $this->assertFieldChecked('edit-contact--2');
     $this->assertTrue(\Drupal::service('user.data')->get('contact', $this->webUser->id(), 'enabled'), 'Personal contact form enabled');
     // Test with disabled global default contact form in combination with a user
     // that has the contact form enabled.
     $this->config('contact.settings')->set('user_default_enabled', FALSE)->save();
     $this->contactUser = $this->drupalCreateUser();
     \Drupal::service('user.data')->set('contact', $this->contactUser->id(), 'enabled', 1);
     $this->drupalGet('user/' . $this->contactUser->id() . '/contact');
     $this->assertResponse(200);
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:100,代码来源:ContactPersonalTest.php

示例2: block

 /**
  * {@inheritdoc}
  */
 public function block()
 {
     return $this->subject->block();
 }
开发者ID:mosswoodcreative,项目名称:d8-api-test,代码行数:7,代码来源:TokenAuthUser.php


注:本文中的Drupal\user\UserInterface::block方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。