forked from CollaboraOnline/collabora-drupal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue CollaboraOnline#52: Add test to check changes.
- Loading branch information
1 parent
5844935
commit e88e648
Showing
2 changed files
with
191 additions
and
35 deletions.
There are no files selected for viewing
35 changes: 0 additions & 35 deletions
35
modules/collabora_online_group/tests/src/Functional/InstallationTest.php
This file was deleted.
Oops, something went wrong.
191 changes: 191 additions & 0 deletions
191
modules/collabora_online_group/tests/src/Functional/ViewTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Drupal\Tests\collabora_online_group\Functional; | ||
|
||
use Drupal\Component\Utility\DiffArray; | ||
use Drupal\Core\Config\FileStorage; | ||
use Drupal\Core\Config\InstallStorage; | ||
use Drupal\Core\Url; | ||
use Drupal\group\PermissionScopeInterface; | ||
use Drupal\media\Entity\Media; | ||
use Drupal\Tests\BrowserTestBase; | ||
use Drupal\Tests\collabora_online\Traits\MediaCreationTrait; | ||
use Drupal\Tests\collabora_online_group\Traits\GroupRelationTrait; | ||
use Drupal\Tests\group\Traits\GroupTestTrait; | ||
use Drupal\Tests\media\Traits\MediaTypeCreationTrait; | ||
use Drupal\user\RoleInterface; | ||
|
||
/** | ||
* Test the provided by the module. | ||
*/ | ||
class ViewTest extends BrowserTestBase { | ||
|
||
use MediaCreationTrait; | ||
use GroupRelationTrait; | ||
use GroupTestTrait; | ||
use MediaTypeCreationTrait; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected static $modules = [ | ||
'collabora_online_group', | ||
'views', | ||
]; | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected $defaultTheme = 'stark'; | ||
|
||
/** | ||
* Test the links for the overriden view. | ||
*/ | ||
public function testViewLinks(): void { | ||
// Add configuration needed for testing. | ||
$group_type = $this->createGroupType(['id' => 'group_type_1']); | ||
$media_type = $this->createMediaType('file', ['id' => 'document']); | ||
$this->createGroupRole([ | ||
'group_type' => 'group_type_1', | ||
'scope' => PermissionScopeInterface::INSIDER_ID, | ||
'global_role' => RoleInterface::AUTHENTICATED_ID, | ||
'permissions' => [ | ||
'view group', | ||
'access group_media overview', | ||
'view group_media:document entity', | ||
'edit any group_media:document in collabora', | ||
'preview group_media:document in collabora', | ||
], | ||
]); | ||
$this->createPluginRelation($group_type, 'group_media:document', [ | ||
'group_cardinality' => 0, | ||
'entity_cardinality' => 1, | ||
'use_creation_wizard' => FALSE, | ||
]); | ||
|
||
// Create content. | ||
$group = $this->createGroup(['type' => 'group_type_1']); | ||
for ($i = 1;$i < 4;$i++) { | ||
$media = $this->createMediaEntity('document', [ | ||
'id' => 'media_' . $i, | ||
'name' => 'Media ' . $i, | ||
]); | ||
$group->addRelationship($media, 'group_media:document'); | ||
} | ||
$user = $this->createUser([ | ||
'view the administration theme', | ||
'access administration pages', | ||
'access group overview', | ||
]); | ||
$group->addMember($user); | ||
|
||
// Go to the page and check the links added to the view. | ||
$this->drupalLogin($user); | ||
$this->drupalGet("group/{$group->id()}/media"); | ||
$assert_session = $this->assertSession(); | ||
|
||
// Check table header. | ||
$table = $assert_session->elementExists('css', 'table'); | ||
$table_header = $assert_session->elementExists('css', 'thead', $table); | ||
$rows = $table_header->findAll('css', 'tr'); | ||
$cols = $rows[0]->findAll('css', 'th'); | ||
$this->assertEquals('Media name', $cols[0]->getText()); | ||
$this->assertEquals('Bundle', $cols[1]->getText()); | ||
$this->assertEquals('Status', $cols[2]->getText()); | ||
$this->assertEquals('Publisher', $cols[3]->getText()); | ||
$this->assertEquals('Dropbutton', $cols[4]->getText()); | ||
|
||
// Check that rows contain new links for operations in Collabora. | ||
$table_body = $assert_session->elementExists('css', 'tbody', $table); | ||
$rows = $table_body->findAll('css', 'tr'); | ||
$i = 0; | ||
foreach(Media::loadMultiple() as $media) { | ||
$cols = $rows[$i]->findAll('css', 'td'); | ||
$this->assertEquals($media->getName(), $cols[0]->getText()); | ||
$this->assertEquals($media_type->label(), $cols[1]->getText()); | ||
$this->assertEquals('Yes', $cols[2]->getText()); | ||
$this->assertEquals('Anonymous', $cols[3]->getText()); | ||
$operation_links = $cols[4]->findAll('css', 'a'); | ||
$this->assertEquals('Preview in Collabora', $operation_links[0]->getText()); | ||
$this->assertEquals( | ||
Url::fromRoute( | ||
'collabora-online.preview', | ||
[ | ||
'media' => $media->id() | ||
], | ||
[ | ||
'destination' => \Drupal::destination(), | ||
] | ||
)->toString(), | ||
$operation_links[0]->getAttribute('href') | ||
); | ||
$this->assertEquals('Edit in Collabora', $operation_links[1]->getText()); | ||
$this->assertEquals( | ||
Url::fromRoute( | ||
'collabora-online.edit', | ||
[ | ||
'media' => $media->id() | ||
], | ||
[ | ||
'destination' => \Drupal::destination(), | ||
] | ||
)->toString(), | ||
$operation_links[1]->getAttribute('href') | ||
); | ||
} | ||
} | ||
|
||
/** | ||
* Tests that the module configuration only adds links. | ||
*/ | ||
public function testConfigDiff(): void { | ||
// Check that view adds only fields for links. | ||
$name = 'views.view.group_media'; | ||
// Get modules path. | ||
$collabora_path = \Drupal::moduleHandler()->getModule('collabora_online_group')->getPath(); | ||
$groupmedia_path = \Drupal::moduleHandler()->getModule('groupmedia')->getPath(); | ||
// Load views configurations to compare. | ||
$collabora_source = new FileStorage($collabora_path . '/config/override'); | ||
$collabora_view = $collabora_source->read($name); | ||
$groupmedia_source = new FileStorage($groupmedia_path . '/' . InstallStorage::CONFIG_OPTIONAL_DIRECTORY); | ||
$groupmedia_view = $groupmedia_source->read($name); | ||
|
||
// Link fields in configuration array are too big, we just check that are | ||
// present. Links are checked in other test. | ||
$this->assertTrue(!empty($collabora_view['display']['default']['display_options']['fields']['collabora_preview'])); | ||
$this->assertTrue(!empty($collabora_view['display']['default']['display_options']['fields']['collabora_edit'])); | ||
$collabora_view['display']['default']['display_options']['fields']['collabora_preview'] = []; | ||
$collabora_view['display']['default']['display_options']['fields']['collabora_edit'] = []; | ||
|
||
// Difference should be module dependencies, fields, and dropdown. | ||
$diff = DiffArray::diffAssocRecursive($collabora_view, $groupmedia_view); | ||
$this->assertEquals([ | ||
'dependencies' => [ | ||
'module' => [ | ||
'collabora_online', | ||
'group', | ||
'media' | ||
] | ||
], | ||
'display' => [ | ||
'default' => [ | ||
'display_options' => [ | ||
'fields' => [ | ||
'collabora_preview' => [], | ||
'collabora_edit' => [], | ||
'dropbutton' => [ | ||
'fields' => [ | ||
'collabora_preview' => 'collabora_preview', | ||
'collabora_edit' => 'collabora_edit', | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
], $diff); | ||
} | ||
|
||
} |