示例#1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->drupalPlaceBlock('local_tasks_block');
     $this->drupalPlaceBlock('local_actions_block');
     $this->drupalPlaceBlock('page_title_block');
     $this->type = $this->createProfileType('test', 'Test profile', TRUE);
     $id = $this->type->id();
     $field_storage = FieldStorageConfig::create(['field_name' => 'profile_fullname', 'entity_type' => 'profile', 'type' => 'text']);
     $field_storage->save();
     $this->field = FieldConfig::create(['field_storage' => $field_storage, 'bundle' => $this->type->id(), 'label' => 'Full name']);
     $this->field->save();
     // Configure the default display.
     $this->display = EntityViewDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->display) {
         $this->display = EntityViewDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->display->save();
     }
     $this->display->setComponent($this->field->getName(), ['type' => 'string'])->save();
     // Configure rhe default form.
     $this->form = EntityFormDisplay::load("profile.{$this->type->id()}.default");
     if (!$this->form) {
         $this->form = EntityFormDisplay::create(['targetEntityType' => 'profile', 'bundle' => $this->type->id(), 'mode' => 'default', 'status' => TRUE]);
         $this->form->save();
     }
     $this->form->setComponent($this->field->getName(), ['type' => 'string_textfield'])->save();
     $this->checkPermissions(['administer profile types', "view own {$id} profile", "view any {$id} profile", "add own {$id} profile", "add any {$id} profile", "edit own {$id} profile", "edit any {$id} profile", "delete own {$id} profile", "delete any {$id} profile"]);
     user_role_grant_permissions(AccountInterface::AUTHENTICATED_ROLE, ['access user profiles']);
     $this->adminUser = $this->drupalCreateUser(['administer profile types', "view any {$id} profile", "add any {$id} profile", "edit any {$id} profile", "delete any {$id} profile"]);
 }
 /**
  * Sets up all of our services with mock methods so buildForm() is possible.
  *
  * @param string $catalog_id
  *   Catalog id.
  * @param string $application_id
  *   Application id.
  * @param [] $filters
  *   An optional list of filters for the client to receive.
  */
 protected function baseMockBuild($catalog_id, $application_id, $filters = [])
 {
     // Field manager mocking.
     $field_settings = ['max_filesize' => '2 MB', 'file_extensions' => self::MOCK_FIELD_SETTINGS_FILE_EXTENSIONS, 'catalog_id' => $catalog_id];
     $this->fieldConfig->expects($this->once())->method('getName')->willReturn('field_test');
     $this->fieldConfig->expects($this->once())->method('getSettings')->willReturn($field_settings);
     // Search filter always starts with the extensions OR filter.
     $extension_filter_value = str_replace(',', '|', self::MOCK_FIELD_SETTINGS_FILE_EXTENSIONS);
     $extension_filter = ['field' => 'fileformat', 'operator' => 'matches', 'value' => $extension_filter_value];
     array_unshift($filters, $extension_filter);
     // Client mocking.
     $search_response = $this->json->decode(file_get_contents('expected/search-expected-small-response.json', TRUE));
     $per_page = 8;
     $page = 1;
     $this->client->expects($this->once())->method('search')->with($page, $per_page, $filters)->willReturn($search_response);
     // Entity type storage mocking.
     $mock_catalog = $this->getMockBuilder('\\Drupal\\embridge\\EmbridgeCatalogInterface')->disableOriginalConstructor()->getMock();
     $mock_catalog->expects($this->once())->method('getApplicationId')->willReturn($application_id);
     $mock_catalog_storage = $this->getMock(EntityStorageInterface::class);
     $mock_catalog_storage->expects($this->once())->method('load')->with($catalog_id)->willReturn($mock_catalog);
     $this->entityTypeManager->expects($this->once())->method('getStorage')->with('embridge_catalog')->willReturn($mock_catalog_storage);
     // Create mock assets.
     foreach ($search_response['results'] as $i => $result) {
         $mock_asset = $this->getMockBuilder('\\Drupal\\embridge\\EmbridgeAssetEntityInterface')->disableOriginalConstructor()->getMock();
         $mock_asset->expects($this->once())->method('id')->willReturn($i);
         $this->mockAssets[$i]['asset'] = $mock_asset;
         $this->mockAssets[$i]['result'] = $result;
     }
     // Mock up the asset helper.
     $return_map = [];
     foreach ($this->mockAssets as $id => $asset_result) {
         $return_map[] = [$asset_result['result'], $catalog_id, $asset_result['asset']];
     }
     $this->assetHelper->expects($this->exactly(count($this->mockAssets)))->method('searchResultToAsset')->will($this->returnValueMap($return_map));
 }