コード例 #1
0
ファイル: ReportSearchTest.php プロジェクト: youprofit/Zurmo
 public function testGetReportsByPartialName()
 {
     $this->assertEquals(2, count(SavedReport::getAll()));
     $this->assertEquals(2, count(ReportSearch::getReportsByPartialName('a', 5)));
     $this->assertEquals(0, count(ReportSearch::getReportsByPartialName('a', 5, 'AccountsModule')));
     $this->assertEquals(1, count(ReportSearch::getReportsByPartialName('a', 5, 'ReportsTestModule')));
     $this->assertEquals(1, count(ReportSearch::getReportsByPartialName('a', 5, 'ReportsTestModule', Report::TYPE_SUMMATION)));
     $this->assertEquals(0, count(ReportSearch::getReportsByPartialName('a', 5, 'ContactsModule', Report::TYPE_SUMMATION)));
 }
コード例 #2
0
 public function testRegularUserControllerActionsWithElevationToEdit()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $nobody = User::getByUsername('nobody');
     $group1 = Group::getByName('Group1');
     $nobody->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $nobody->setRight('AccountsModule', AccountsModule::RIGHT_CREATE_ACCOUNTS);
     $nobody->setRight('ReportsModule', ReportsModule::RIGHT_ACCESS_REPORTS);
     $nobody->setRight('ReportsModule', ReportsModule::RIGHT_CREATE_REPORTS);
     $nobody->setRight('ReportsModule', ReportsModule::RIGHT_DELETE_REPORTS);
     assert($nobody->save());
     // Not Coding Standard
     $savedReports = SavedReport::getAll();
     $this->assertEquals(0, count($savedReports));
     $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/create');
     $this->assertContains('Rows and Columns Report', $content);
     $this->assertContains('Summation Report', $content);
     $this->assertContains('Matrix Report', $content);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->resetPostArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('reports/default/create');
     $this->assertContains('Accounts', $content);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $postData['ajax'] = 'edit-form';
     $this->setPostArray($postData);
     $content = $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $this->assertEquals('[]', $content);
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(1, count($savedReports));
     $nobody = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(1, count($savedReports));
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('reports/default/details');
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('reports/default/edit');
     //Save an existing report
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id));
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $this->assertEquals(1, count($savedReports));
     //Clone existing report
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData = static::makeRowsAndColumnsReportPostData();
     $postData['save'] = 'save';
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('reports/default/save');
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(2, count($savedReports));
 }
コード例 #3
0
 /**
  * @depends testAutoComplete
  */
 public function testDelete()
 {
     $savedReports = SavedReport::getAll();
     $this->assertEquals(3, count($savedReports));
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithRedirectExceptionAndGetContent('reports/default/delete');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(2, count($savedReports));
 }
コード例 #4
0
 /**
  * @depends testMakeReportDataProviderAndResolveAttributeName
  */
 public function testGetContactIdsByReportDataProviderAndAttributeName()
 {
     $contactReports = SavedReport::getAll();
     $contactReport = $contactReports[0];
     $contacts = Contact::getAll();
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 1, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(1, $contactIds);
     $attributeName = null;
     $reportDataProvider = MarketingListMembersUtil::makeReportDataProviderAndResolveAttributeName($contactReport->id, 2, $attributeName);
     $contactIds = MarketingListMembersUtil::getContactIdsByReportDataProviderAndAttributeName($reportDataProvider, $attributeName);
     $this->assertCount(2, $contactIds);
     $this->assertContains($contacts[0]->id, $contactIds);
     $this->assertContains($contacts[1]->id, $contactIds);
 }
コード例 #5
0
 /**
  * @depends testResolveReportToSavedReport
  */
 public function testMakeReportBySavedReport()
 {
     $billy = User::getByUsername('billy');
     $savedReports = SavedReport::getAll();
     $this->assertEquals(1, count($savedReports));
     $savedReport = $savedReports[0];
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     $filters = $report->getFilters();
     $groupBys = $report->getGroupBys();
     $orderBys = $report->getOrderBys();
     $displayAttributes = $report->getDisplayAttributes();
     $drillDownDisplayAttributes = $report->getDrillDownDisplayAttributes();
     $this->assertEquals('ReportsTestModule', $report->getModuleClassName());
     $this->assertEquals('myFirstReport', $report->getName());
     $this->assertEquals('aDescription', $report->getDescription());
     $this->assertEquals(Report::TYPE_ROWS_AND_COLUMNS, $report->getType());
     $this->assertEquals('1 and 2 or 3', $report->getFiltersStructure());
     $this->assertTrue($report->getOwner()->isSame($billy));
     $this->assertCount(4, $filters);
     $this->assertCount(1, $groupBys);
     $this->assertCount(1, $orderBys);
     $this->assertCount(1, $displayAttributes);
     $this->assertCount(1, $drillDownDisplayAttributes);
     $this->assertEquals(true, $filters[0]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[0]->value);
     $this->assertEquals('string', $filters[0]->attributeIndexOrDerivedType);
     $this->assertNull($filters[0]->currencyIdForValue);
     $this->assertNull($filters[0]->secondValue);
     $this->assertNull($filters[0]->stringifiedModelForValue);
     $this->assertNull($filters[0]->valueType);
     $this->assertEquals('equals', $filters[0]->operator);
     $this->assertEquals(true, $filters[1]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[1]->value);
     $this->assertEquals('currencyValue', $filters[1]->attributeIndexOrDerivedType);
     $this->assertEquals(4, $filters[1]->currencyIdForValue);
     $this->assertEquals('bValue', $filters[1]->secondValue);
     $this->assertNull($filters[1]->stringifiedModelForValue);
     $this->assertNull($filters[1]->valueType);
     $this->assertEquals('between', $filters[1]->operator);
     $this->assertEquals(false, $filters[2]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[2]->value);
     $this->assertEquals('owner__User', $filters[2]->attributeIndexOrDerivedType);
     $this->assertNull($filters[2]->currencyIdForValue);
     $this->assertNull($filters[2]->secondValue);
     $this->assertEquals('someName', $filters[2]->stringifiedModelForValue);
     $this->assertNull($filters[2]->valueType);
     $this->assertNull($filters[2]->operator);
     $this->assertEquals(true, $filters[3]->availableAtRunTime);
     $this->assertEquals('aValue', $filters[3]->value);
     $this->assertEquals('createdDateTime', $filters[3]->attributeIndexOrDerivedType);
     $this->assertNull($filters[3]->currencyIdForValue);
     $this->assertEquals('bValue', $filters[3]->secondValue);
     $this->assertNull($filters[3]->stringifiedModelForValue);
     $this->assertNull($filters[3]->operator);
     $this->assertEquals('Between', $filters[3]->valueType);
     $this->assertEquals('url', $orderBys[0]->attributeIndexOrDerivedType);
     $this->assertEquals('desc', $orderBys[0]->order);
     $this->assertEquals('lastName', $groupBys[0]->attributeIndexOrDerivedType);
     $this->assertEquals('y', $groupBys[0]->axis);
     $this->assertEquals('phone', $displayAttributes[0]->attributeIndexOrDerivedType);
     $this->assertEquals('someNewLabel', $displayAttributes[0]->label);
     $this->assertEquals('firstName', $drillDownDisplayAttributes[0]->attributeIndexOrDerivedType);
     $this->assertEquals('someNewLabel', $drillDownDisplayAttributes[0]->label);
 }
コード例 #6
0
 public function testCloneSetsRightPermissions()
 {
     // create users and groups.
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $everyoneGroup->setRight('ReportsModule', ReportsModule::getAccessRight());
     $everyoneGroup->setRight('AccountsModule', AccountsModule::RIGHT_ACCESS_ACCOUNTS);
     $this->assertTrue($everyoneGroup->save());
     $everyoneGroup->forgetAll();
     $jim = UserTestHelper::createBasicUser('jim');
     $john = UserTestHelper::createBasicUser('john');
     $johnGroup = new Group();
     $johnGroup->name = 'John Group';
     $johnGroup->users->add($john);
     $this->assertTrue($johnGroup->save());
     $john->forgetAll();
     $johnGroup->forgetAll();
     $john = User::getByUsername('john');
     $johnGroup = Group::getByName('John Group');
     $basePostData = static::makeRowsAndColumnsReportPostDataForAccounts();
     $basePostData['save'] = 'save';
     $description = StringUtil::generateRandomString(40);
     // create a report with everyone group permission, ensure everyone can access it.
     // clone it, ensure everyone group can still access it.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     SavedReport::deleteAll();
     $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array('name' => 'Everyone Report 01', 'description' => $description, 'ownerId' => $super->id, 'ownerName' => strval($super), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP, 'nonEveryoneGroup' => null)));
     $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(1, $savedReports);
     $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($jim));
     // ensure jim can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // clone the report.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(2, $savedReports);
     $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
     $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
     $this->assertEquals($sourcePermissions, $clonePermissions);
     $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($jim));
     // ensure jim can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[1]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // create a report with specific group permissions, ensure only members of that group can access it.
     // clone it, ensure only that specific group members can access it.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     SavedReport::deleteAll();
     $modelSpecificPostData = array('RowsAndColumnsReportWizardForm' => array('name' => 'Group Specific Report 01', 'description' => $description, 'ownerId' => $super->id, 'ownerName' => strval($super), 'explicitReadWriteModelPermissions' => array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_NONEVERYONE_GROUP, 'nonEveryoneGroup' => $johnGroup->id)));
     $postData = CMap::mergeArray($basePostData, $modelSpecificPostData);
     $this->setGetArray(array('type' => 'RowsAndColumns'));
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(1, $savedReports);
     $this->assertEquals(Permission::ALL, $savedReports[0]->getEffectivePermissions($super));
     $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::NONE, $savedReports[0]->getEffectivePermissions($jim));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($johnGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[0]->getEffectivePermissions($john));
     // ensure john can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('john');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // ensure jim can not access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
     // clone the report.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('type' => 'RowsAndColumns', 'id' => $savedReports[0]->id, 'isBeingCopied' => '1'));
     $postData['RowsAndColumnsReportWizardForm']['name'] = 'Cloned ' . $postData['RowsAndColumnsReportWizardForm']['name'];
     $this->setPostArray($postData);
     $this->runControllerWithExitExceptionAndGetContent('/reports/default/save');
     ForgetAllCacheUtil::forgetAllCaches();
     $savedReports = SavedReport::getAll();
     $this->assertCount(2, $savedReports);
     $sourcePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[0]);
     $clonePermissions = ExplicitReadWriteModelPermissionsUtil::makeBySecurableItem($savedReports[1]);
     $this->assertEquals($sourcePermissions, $clonePermissions);
     $this->assertEquals(Permission::ALL, $savedReports[1]->getEffectivePermissions($super));
     $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($everyoneGroup));
     $this->assertEquals(Permission::NONE, $savedReports[1]->getEffectivePermissions($jim));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($johnGroup));
     $this->assertEquals(Permission::READ_WRITE_CHANGE_PERMISSIONS_CHANGE_OWNER, $savedReports[1]->getEffectivePermissions($john));
     // ensure john can access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('john');
     $this->resetPostArray();
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 1);
     $this->setGetArray(array('id' => $savedReports[1]->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/details');
     $this->assertContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->assertEquals(substr_count($content, $postData['RowsAndColumnsReportWizardForm']['name']), 3);
     // ensure jim can not access it.
     $this->logoutCurrentUserLoginNewUserAndGetByUsername('jim');
     $this->resetGetArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('/reports/default/list');
     $this->assertNotContains($postData['RowsAndColumnsReportWizardForm']['name'], $content);
     $this->setGetArray(array('id' => $savedReports[0]->id));
     $this->runControllerWithAccessDeniedSecurityExceptionAndGetContent('/reports/default/details');
 }