/** * @test * @group integration */ public function getByIdShouldReturnExpectedTemplateSnippet() { $existingId = 'TPLS-template-snip-pet0-test-000000000001-TPLS'; $websiteId = 'SITE-template-snip-pet0-test-000000000001-SITE'; $request = sprintf('/templatesnippet/getbyid/params/{"id":"%s","websiteid":"%s"}', $existingId, $websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $actualTemplateSnippet = $response->getData(); $this->assertInstanceOf('stdClass', $actualTemplateSnippet); $this->assertObjectHasAttribute('id', $actualTemplateSnippet); $this->assertSame($existingId, $actualTemplateSnippet->id); $this->assertObjectHasAttribute('websiteId', $actualTemplateSnippet); $this->assertSame($websiteId, $actualTemplateSnippet->websiteId); $this->assertObjectHasAttribute('name', $actualTemplateSnippet); $this->assertSame('TEMPLATE_SNIPPET_NAME_1', $actualTemplateSnippet->name); $this->assertObjectHasAttribute('description', $actualTemplateSnippet); $this->assertSame('TEMPLATE_SNIPPET_DESCRIPTION_1', $actualTemplateSnippet->description); $this->assertObjectHasAttribute('category', $actualTemplateSnippet); $this->assertSame('TEMPLATE_SNIPPET_CATEGORY_1', $actualTemplateSnippet->category); $this->assertObjectHasAttribute('baseLayout', $actualTemplateSnippet); $this->assertFalse($actualTemplateSnippet->baseLayout); $this->assertObjectHasAttribute('pageTypes', $actualTemplateSnippet); $this->assertInternalType('array', $actualTemplateSnippet->pageTypes); $this->assertCount(0, $actualTemplateSnippet->pageTypes); $this->assertObjectHasAttribute('content', $actualTemplateSnippet); $this->assertSame('[]', \Zend_Json::encode($actualTemplateSnippet->content)); $this->assertEquals('local', $actualTemplateSnippet->sourceType); $this->assertFalse($actualTemplateSnippet->readonly); }
/** * @test * @group integration */ public function getAllOnUserWithWebsiteIdShouldReturnExpectedUsers() { $websiteId = 'SITE-0r7g62te-0t4c-42c7-8628-f2cb4236e5gw-SITE'; $getAllRequest = sprintf('/user/getall/params/{"websiteId":"%s"}', $websiteId); $this->dispatch($getAllRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $expectedUsersOfWebsiteCount = 5; $expectedUsersIdsOfWebsite = array('USER-re02eaa7-7fc5-464a-bd47-16b3b8af360p-USER', 'USER-re02eaa7-7fc5-464a-bd47-16b3b8af361p-USER', 'USER-re02eaa7-7fc5-464a-bd47-16b3b8af362p-USER', 'USER-re02eaa7-7fc5-464a-bd47-16b3b8af363p-USER', 'USER-re02eaa7-7fc5-464a-bd47-16b3b8af364p-USER'); $responseData = $response->getData(); $this->assertObjectHasAttribute('users', $responseData); $actualUsersOfWebsite = $responseData->users; $this->assertInternalType('array', $actualUsersOfWebsite); $actualUsersOfWebsiteCount = count($actualUsersOfWebsite); $this->assertSame($expectedUsersOfWebsiteCount, $actualUsersOfWebsiteCount); $actualUsersIdsOfWebsite = array_map(function ($user) { return $user->id; }, $actualUsersOfWebsite); sort($expectedUsersIdsOfWebsite); sort($actualUsersIdsOfWebsite); $this->assertSame($expectedUsersIdsOfWebsite, $actualUsersIdsOfWebsite); }
/** * @test * @group integration */ public function getAllAlbumsShouldReturnExpectedAlbumsSortedByName() { $websiteId = 'SITE-ce6e702f-10ac-4e1e-951f-307e4b8760as-SITE'; $request = sprintf('/album/getall/params/{"websiteId":"%s"}', $websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('albums', $responseData); $allAlbumsForWebsiteId = $responseData->albums; $this->assertInternalType('array', $allAlbumsForWebsiteId); $expectedAlbumNameOrder = array('a_controller_test_album', 'b_controller_test_album', 'z_controller_test_album'); $this->assertSame(3, count($allAlbumsForWebsiteId)); $actualAlbumNameOrder = array(); foreach ($allAlbumsForWebsiteId as $albumsOfWebsiteId) { $this->assertInstanceOf('stdClass', $albumsOfWebsiteId); $this->objectHasAttribute('websiteId', $albumsOfWebsiteId); $this->assertSame($websiteId, $albumsOfWebsiteId->websiteId); $this->objectHasAttribute('id', $albumsOfWebsiteId); $this->assertTrue($this->validateUniqueId(new DataAlbum(), $albumsOfWebsiteId->id)); $this->objectHasAttribute('name', $albumsOfWebsiteId); $this->assertNotEmpty($albumsOfWebsiteId->name); $actualAlbumNameOrder[] = $albumsOfWebsiteId->name; } $assertionMessage = sprintf("Actual album name order [%s] doesn't match expected album name order [%s]", implode(",", $actualAlbumNameOrder), implode(",", $expectedAlbumNameOrder)); $this->assertSame($expectedAlbumNameOrder, $actualAlbumNameOrder, $assertionMessage); }
/** * @param string $websiteId * @param string $expectedId * @param string $expectedUserlogin * @param string $expectedAction * @param array $expectedAdditionalinfo */ protected function assertActionLogEntry($websiteId, $expectedId, $expectedUserlogin, $expectedAction, $expectedAdditionalinfo = array()) { $getLogRequest = sprintf('log/get/params/{"websiteId":"%s","format":"json"}', $websiteId); $this->dispatch($getLogRequest); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertInternalType('array', $responseData); $expectedLogEntriesCount = 1; $this->assertSame($expectedLogEntriesCount, count($responseData)); $expectedLogKeys = array('id', 'name', 'dateTime', 'userlogin', 'action', 'additionalinfo'); $this->assertInstanceOf('stdClass', $responseData[0]); $actualLogKeys = array_keys(get_object_vars($responseData[0])); sort($actualLogKeys); sort($expectedLogKeys); $this->assertSame($expectedLogKeys, $actualLogKeys); $this->assertSame($expectedId, $responseData[0]->id); $this->assertSame($expectedUserlogin, $responseData[0]->userlogin); $this->assertSame($expectedAction, $responseData[0]->action); if (count($expectedAdditionalinfo) > 0) { $this->assertObjectHasAttribute('additionalinfo', $responseData[0]); $actualAdditionalInfo = json_decode($responseData[0]->additionalinfo, false); foreach ($expectedAdditionalinfo as $key => $expectedValue) { $this->assertObjectHasAttribute($key, $actualAdditionalInfo); $this->assertSame($expectedValue, $actualAdditionalInfo->{$key}); } } return $responseData[0]; }
/** * @test * @group integration */ public function getWebsiteBuildsShouldReturnBuilds() { $comment = 'test_website_build_comment'; $websiteId = 'SITE-bw02fg14-3bbe-4301-ae51-f58464f1708e-SITE'; $config = Registry::getConfig(); $expectedWebsiteBuildsCount = (int) $config->builds->threshold; $request = sprintf('/builder/getwebsitebuilds/params/{"websiteid":"%s"}', $websiteId); $this->copyWebsiteBuildsFromStorageToBuildsDirectory($websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('builds', $responseData); $this->assertNotEmpty($responseData->builds); $this->assertInternalType('array', $responseData->builds); $this->assertSame($expectedWebsiteBuildsCount, count($responseData->builds)); foreach ($responseData->builds as $nextBuild) { $this->assertObjectHasAttribute('id', $nextBuild); $this->assertObjectHasAttribute('version', $nextBuild); $this->assertObjectHasAttribute('timestamp', $nextBuild); $this->assertObjectHasAttribute('comment', $nextBuild); $this->assertObjectHasAttribute('creatorName', $nextBuild); $this->assertObjectHasAttribute('lastPublished', $nextBuild); $this->assertInternalType('object', $nextBuild->lastPublished); $this->assertObjectHasAttribute('id', $nextBuild->lastPublished); $this->assertObjectHasAttribute('status', $nextBuild->lastPublished); $this->assertObjectHasAttribute('timestamp', $nextBuild->lastPublished); $this->assertObjectHasAttribute('percent', $nextBuild->lastPublished); $this->assertObjectHasAttribute('remaining', $nextBuild->lastPublished); $this->assertObjectHasAttribute('msg', $nextBuild->lastPublished); } }
/** * @test * @group integration */ public function getByIdOnExistingUserShouldReturnUserAsExpected() { $userId = 'USER-gbi7e2cf-11r5-45e9-bc6d-a25cee8a74c1-USER'; $getByIdRequest = sprintf('/user/getbyid/params/{"id":"%s"}', $userId); $this->dispatch($getByIdRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $actualUserData = $response->getData(); $this->assertNotEmpty($actualUserData); $actualUserFields = array_keys(get_object_vars($actualUserData)); $minimalExpectedFieldCount = 11; $this->assertTrue(count($actualUserFields) === $minimalExpectedFieldCount); $expectedUserValues = array('id' => $userId, 'lastname' => 'lastname_get_by_id', 'firstname' => 'firstname_get_by_id', 'gender' => 'm', 'email' => '*****@*****.**', 'language' => null, 'superuser' => false, 'isdeletable' => true, 'owner' => false, 'readonly' => false, 'groups' => array('SITE-ga37e89c-r2ag-48cd-a6t9-fc45ds78fe5s-SITE' => array('GROUP-gi00fg03-a3c4-4fdh-ard4-72ebb0878rf7-GROUP', 'GROUP-gi00fg03-a3c4-4fdh-3rd5-72ebb0878rf7-GROUP', 'GROUP-gi00fg03-a3c4-4fdh-3r5d-72ebb0878rf7-GROUP'))); arsort($expectedUserValues['groups']); foreach ($expectedUserValues['groups'] as $siteId => $websiteGroups) { sort($websiteGroups); $expectedUserValues['groups'][$siteId] = $websiteGroups; } $this->assertObjectHasAttribute('groups', $actualUserData); $this->assertInstanceOf('stdClass', $actualUserData->groups); $actualUserGroupData = get_object_vars($actualUserData->groups); $actualUserData->groups = array(); foreach ($actualUserGroupData as $siteId => $websiteGroups) { sort($websiteGroups); $actualUserData->groups[$siteId] = $websiteGroups; } foreach ($actualUserData as $key => $value) { $this->assertSame($expectedUserValues[$key], $value); } }
/** * @test * @group integration */ public function getByIdShouldReturnExpectedMedia() { $websiteId = 'SITE-me10e89c-r2af-46cd-a651-fc42dc78fe5l-SITE'; $mediaId = 'MDB-1frc4a9f-6793-471e-96bf-ge9039a0d703-MDB'; $expectedAlbumId = 'ALBUM-ce1e6f03-gbc4-4fdb-add4-72ebb0878006-ALBUM'; $requestUri = sprintf('/media/getbyid/params/{"websiteid":"%s","id":"%s"}', $websiteId, $mediaId); $this->dispatch($requestUri); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $responseData = $response->getData(); $this->assertTrue($response->getSuccess()); $this->assertNotEmpty($responseData); // Response Felder pruefen $expectedResponseProperties = array('id', 'websiteId', 'name', 'url', 'icon', 'type', 'extension', 'filesize', 'dateUploaded', 'albumId'); $actualResponseProperties = array_keys(get_object_vars($responseData)); foreach ($expectedResponseProperties as $expectedResponseProperty) { $this->assertContains($expectedResponseProperty, $actualResponseProperties); } // Response Inhalte pruefen $this->assertObjectHasAttribute('id', $responseData); $this->assertSame($mediaId, $responseData->id); $this->assertObjectHasAttribute('websiteId', $responseData); $this->assertSame($websiteId, $responseData->websiteId); $this->assertObjectHasAttribute('albumId', $responseData); $this->assertSame($expectedAlbumId, $responseData->albumId); $this->assertObjectHasAttribute('url', $responseData); $this->assertNotEmpty($responseData->url); $this->assertObjectHasAttribute('icon', $responseData); $this->assertNotEmpty($responseData->icon); }
/** * @test * @group integration */ public function loginShouldAllowLoginForUserWithPendingOptin() { $username = '******'; $password = '******'; $loginRequest = sprintf('/user/login/params/{"username":"******","password":"******"}', $username, $password); $this->dispatch($loginRequest); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $this->assertNull($response->getData()); }
/** * @test * @integration */ public function templateSnippetImportShouldRespondWithConflictingTemplateSnippet() { $websiteId = 'SITE-ae6e702f-10ac-4e1e-exmo-307e4b8765db-SITE'; $config = Registry::getConfig(); $testImportDirectory = $config->import->directory; $testFilesDirectory = $config->test->files->directory; $testImportFilename = 'test_export_0_templatesnippets_conflict_only_templatesnippet.zip'; $testImportFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'test_exports' . DIRECTORY_SEPARATOR . $testImportFilename; $expectedImportFile = $testImportDirectory . DIRECTORY_SEPARATOR . $testImportFilename; $importUnzipDirectory = str_replace('.zip', '', $expectedImportFile); $assertionMessage = sprintf("Import file '%s' existiert nicht", $testImportFile); $this->assertFileExists($testImportFile, $assertionMessage); $testImportTmpFile = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpe7f3im'; $fileInputname = 'import'; $requestUri = sprintf('/import/file/params/{"websiteid":"%s","fileinputname":"%s"}', $websiteId, $fileInputname); $this->assertFakeUpload($fileInputname, $testImportFile, $testImportTmpFile); $this->dispatch($requestUri); $this->assertHeaderContains('Content-Type', 'text/plain'); $response = new Response($this->getResponseBody()); $this->assertFalse($response->getSuccess()); $reponseError = $response->getError(); $this->assertEquals(11, $reponseError[0]->code); $responseData = $response->getData(); $this->assertObjectHasAttribute('importId', $responseData); $this->assertObjectHasAttribute('conflict', $responseData); $conflictData = $responseData->conflict; $this->assertObjectHasAttribute('templatesnippets', $conflictData); $this->assertObjectHasAttribute('templates', $conflictData); $this->assertObjectHasAttribute('modules', $conflictData); $this->assertObjectHasAttribute('media', $conflictData); $expectedConflictingTemplateSnippets = array(); $conflictingTemplateSnippet = new \StdClass(); $conflictingTemplateSnippet->id = 'TPLS-template-snip-pet0-test-000000000023-TPLS'; $conflictingTemplateSnippet->oldName = 'TEMPLATE_SNIPPET_NAME_23'; $conflictingTemplateSnippet->newName = 'Export_Test_TemplateSnippet_0'; $expectedConflictingTemplateSnippets[] = $conflictingTemplateSnippet; $this->assertTrue(count($conflictData->templatesnippets) === count($expectedConflictingTemplateSnippets)); $this->assertEquals($expectedConflictingTemplateSnippets, $conflictData->templatesnippets); $errorData = $response->getError(); $this->assertEquals(11, $errorData[0]->code); $errorMessage = \Cms\Error::getMessageByCode(11); $this->assertEquals($errorMessage, $errorData[0]->text); if (file_exists($testImportTmpFile)) { unlink($testImportTmpFile); } if (strstr($importUnzipDirectory, $testImportDirectory)) { DirectoryHelper::removeRecursiv($importUnzipDirectory, $testImportDirectory); if (is_dir($importUnzipDirectory)) { rmdir($importUnzipDirectory); } if (file_exists($expectedImportFile)) { unlink($expectedImportFile); } } }
/** * @test * @group integration * @dataProvider invalidSearchFilterProvider */ public function getWithSearchFilterShouldOnlyReturnMatchingMediasAndExpectedTotal() { $websiteId = 'SITE-ra10e89c-22af-46sf-a651-fc42dc78fe50-SITE'; $searchFilter = 'Test_Data_Search_Filter'; $requestUri = sprintf('/media/get/params/{"websiteid":"%s","search":"%s"}', $websiteId, $searchFilter); $this->dispatch($requestUri); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $this->assertNotEmpty($response->getData()); $responseData = $response->getData(); $this->assertObjectHasAttribute('media', $responseData); $this->assertObjectHasAttribute('total', $responseData); $mediaItems = $responseData->media; $this->assertInternalType('array', $mediaItems); $this->assertTrue(count($mediaItems) == 2); $this->assertTrue($responseData->total == 2); }
/** * @test * @group integration */ public function getAllShouldReturnAtLeastOneTemplate() { $websiteId = 'SITE-30490289-dddb-4501-879f-9c6c7965f871-SITE'; $this->dispatch(sprintf('/template/getAll/params/{"websiteid":"%s"}', $websiteId)); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templates', $responseData); $this->assertInternalType('array', $responseData->templates); $this->assertGreaterThan(0, count($responseData->templates)); }
/** * @test * @group integration */ public function getAllShouldReturnAtLeastOneSnippet() { $websiteId = 'SITE-template-snip-pet0-test-000000000002-SITE'; $this->dispatch(sprintf('/templatesnippet/getAll/params/{"websiteid":"%s"}', $websiteId)); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templatesnippets', $responseData); $this->assertInternalType('array', $responseData->templatesnippets); $this->assertGreaterThan(0, count($responseData->templatesnippets)); }
/** * @test * @group integration */ public function createAlbumShouldCreateAlbumAsExpected() { $websiteId = 'SITE-ce6e702f-10ac-4e1e-951f-307e4b8765al-SITE'; $albumName = 'controller_test_album_1'; $request = sprintf('/album/create/params/{"websiteId":"%s","name":"%s"}', $websiteId, $albumName); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('id', $responseData); $albumId = $responseData->id; $this->assertNotNull($albumId, 'Album ID muss im Response geliefert werden'); $this->assertTrue($this->validateUniqueId(new DataAlbum(), $albumId)); }
/** * @test * @group integration */ public function buildWebsiteShouldBeLogged() { $websiteId = 'SITE-bw00fg14-3bbe-4301-ae51-f58464f1708e-SITE'; $params = array('websiteId' => $websiteId, 'comment' => 'test_website_build_1'); $paramsAsJson = json_encode($params); $userlogin = '******'; $userPassword = '******'; $this->assertSuccessfulLogin($userlogin, $userPassword); $this->activateGroupCheck(); $this->dispatch('builder/buildwebsite/params/' . $paramsAsJson); $this->deactivateGroupCheck(); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertActionLogEntry($params['websiteId'], $responseData->id, $userlogin, BuilderBusiness::BUILDER_BUILD_ACTION); $this->removeCreatedWebsite($websiteId); }
/** * @test * @group integration */ public function infoShouldRespondWithExpectedUserJsonWithoutGroupAssociation() { $userName = '******'; $userPassword = '******'; $this->assertSuccessfulLogin($userName, $userPassword); $this->activateGroupCheck(); $infoRequest = '/user/info'; $this->dispatch($infoRequest); $this->deactivateGroupCheck(); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('userInfo', $responseData); $expectedUserInfo = array('id' => 'USER-lo01eaa7-7fc5-464a-bd47-16b3b8af36c0-USER', 'lastname' => 'login_lastname_0', 'firstname' => 'login_firstname_0', 'gender' => 'm', 'email' => '*****@*****.**', 'language' => null, 'superuser' => true, 'owner' => false, 'readonly' => false, 'dashboardUrl' => null, 'upgradeUrl' => null, 'groups' => array(), 'privilege' => array()); $actualUserInfo = get_object_vars($responseData->userInfo); $this->assertSame($expectedUserInfo, $actualUserInfo); }
/** * @test * @group integration * @dataProvider uuidProvider * @param string $action * @param string $resource * @param integer $count */ public function getUuidShouldReturnFiveValidUuidsForUuidProvider($action, $resource, $count) { $dispatchUri = sprintf('/uuid/%s/params/{"count":%d}', $action, $count); $this->dispatch($dispatchUri); $cmsResponse = new CmsResponse($this->getResponseBody()); $data = $cmsResponse->getData(); $this->assertObjectHasAttribute('uuids', $data); $this->assertInternalType('array', $data->uuids); $uuids = $data->uuids; $this->assertTrue(count($uuids) === $count); $dataResource = sprintf('Orm\\Data\\%s', $resource); $uniqueidValidator = new UniqueIdValidator($dataResource::ID_PREFIX, $dataResource::ID_SUFFIX); foreach ($uuids as $uuid) { $this->assertTrue($uniqueidValidator->isValid($uuid)); } $this->resetResponse(); $this->resetRequest(); }
/** * @test * @group integration */ public function deleteShouldDeleteExpectedTemplateSnippet() { $runId = 'CMSRUNID-00000000-0000-0000-0000-000000000001-CMSRUNID'; $websiteId = 'SITE-template-snip-pet0-test-000000000002-SITE'; $request = sprintf('/templatesnippet/getall/params/{"websiteid":"%s"}', $websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templatesnippets', $responseData); $this->assertInternalType('array', $responseData->templatesnippets); $this->assertGreaterThan(0, count($responseData->templatesnippets)); $templateSnippetCountBeforeDelete = count($responseData->templatesnippets); $templateSnippetIdForDelete = 'TPLS-template-snip-pet0-test-deleteaction-TPLS'; $request = sprintf('/templatesnippet/delete/params/%s', \Zend_Json::encode(array('runid' => $runId, 'ids' => array($templateSnippetIdForDelete), 'websiteid' => $websiteId))); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $request = sprintf('/templatesnippet/getall/params/{"websiteid":"%s"}', $websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templatesnippets', $responseData); $this->assertInternalType('array', $responseData->templatesnippets); $this->assertGreaterThan(0, count($responseData->templatesnippets)); $this->assertLessThan($templateSnippetCountBeforeDelete, count($responseData->templatesnippets)); foreach ($responseData->templatesnippets as $templateSnippet) { $this->assertInstanceOf('stdClass', $templateSnippet); $this->assertObjectHasAttribute('id', $templateSnippet); $this->assertNotSame($templateSnippetIdForDelete, $templateSnippet->id); } }
/** * Existiert ein bestimmter Lock */ protected function lockExists($runId, $userId, $websiteId, $id, $type, $returnLock = false) { $params = array('runid' => $runId, 'websiteid' => $websiteId); $request = '/lock/getAll/params/' . json_encode($params); $this->dispatch($request); $response = $this->getResponseBody(); $responseJsonObj = json_decode($response); $this->assertResponseBodySuccess($responseJsonObj); $response = new Response($response); $responseData = $response->getData(); $this->assertObjectHasAttribute('locks', $responseData); $this->assertInternalType('array', $responseData->locks); foreach ($responseData->locks as $nextLock) { if ($websiteId == $nextLock->websiteid && $id == $nextLock->id && $type == $nextLock->type && $userId == $nextLock->userid && $runId == $nextLock->runid) { // Lock existiert return $returnLock === true ? $nextLock : true; } } // Lock existiert nicht return false; }
/** * @test * @group integration */ public function getByIdShouldReturnExpectedTemplate() { $existingId = 'TPL-in6c753f-2rap-474f-a4et-4a97223fbdea-TPL'; $websiteId = 'SITE-30490289-dddb-4501-879f-9c6c7965f871-SITE'; $request = sprintf('/template/getbyid/params/{"id":"%s","websiteid":"%s"}', $existingId, $websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $actualTemplate = $response->getData(); $this->assertInstanceOf('stdClass', $actualTemplate); $this->assertObjectHasAttribute('id', $actualTemplate); $this->assertSame($existingId, $actualTemplate->id); $this->assertObjectHasAttribute('websiteId', $actualTemplate); $this->assertSame($websiteId, $actualTemplate->websiteId); $this->assertObjectHasAttribute('name', $actualTemplate); $this->assertSame('Template_Name_Int_GetById', $actualTemplate->name); $this->assertObjectHasAttribute('content', $actualTemplate); $this->assertSame('[{"some":"value"}]', \Zend_Json::encode($actualTemplate->content)); }
/** * @test * @group integration */ public function uploadShouldStoreFileAsExpectedAndHaveTextPlainContentType() { $expectedUploadCount = 1; $expectedUploadExtension = 'js'; $config = Registry::getConfig(); $testMediaFilesDirectory = $config->media->files->directory; $testFilesDirectory = $config->test->files->directory; $testUploadFile = $testFilesDirectory . DIRECTORY_SEPARATOR . 'backbone.js'; $testTmpFile = DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpIsd9te'; $websiteId = 'SITE-ra10e8ul-11af-46cd-a651-fc42dc78fe50-SITE'; $mediaName = 'integration_test_upload'; $albumId = 'ALBUM-ce2ecf03-acc4-4adb-ed34-72ebb08780up-ALBUM'; $fileInputname = 'upload'; $requestUri = sprintf('/media/upload/params/{"websiteid":"%s","albumid":"%s","name":"%s","fileinputname":"%s"}', $websiteId, $albumId, $mediaName, $fileInputname); $this->assertFakeUpload($fileInputname, $testUploadFile, $testTmpFile); $this->dispatch($requestUri); $response = $this->getResponseBody(); $this->assertHeaderContains('Content-Type', 'text/plain'); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $uniqueidValidator = new UniqueIdValidator(DataMedia::ID_PREFIX, DataMedia::ID_SUFFIX); $responseData = $response->getData(); $this->assertObjectHasAttribute('id', $responseData); $mediaId = $responseData->id; $this->assertTrue($uniqueidValidator->isValid($mediaId)); $expectedMediaWebsiteDirectory = $testMediaFilesDirectory . DIRECTORY_SEPARATOR . $websiteId; $this->assertTrue(is_dir($expectedMediaWebsiteDirectory)); $directory = new \DirectoryIterator($expectedMediaWebsiteDirectory); $uploadedFiles = array(); foreach ($directory as $fileinfo) { if (!$fileinfo->isDot()) { $splitFileName = explode(".", $fileinfo->getFilename()); $this->assertSame($expectedUploadExtension, end($splitFileName)); $uploadedFiles[] = $fileinfo->getFilename(); } } $this->assertSame($expectedUploadCount, count($uploadedFiles)); $testMediaWebsiteUploadDirectory = $testMediaFilesDirectory . DIRECTORY_SEPARATOR . $websiteId; $this->dispatch('/media/getbyid/params/{"websiteid":"' . $websiteId . '","id":"' . $mediaId . '"}'); $response = $this->getResponseBody(); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('dateUploaded', $responseData); $this->assertNotNull($responseData->dateUploaded, 'Upload-Datum muss automatisch gesetzt werden'); $this->assertInternalType('int', $responseData->dateUploaded, 'Upload-Datum muss Timestamp sein'); DirectoryHelper::removeRecursiv($testMediaWebsiteUploadDirectory, $testMediaFilesDirectory); }
/** * @test * @group integration */ public function editAlbumShouldAlterAlbumAsExpected() { $websiteId = 'SITE-ce6e702f-10ac-4e1e-951f-307e4b8765al-SITE'; $albumId = 'ALBUM-ce1ecf03-acc4-4fdb-add4-72ebb0878007-ALBUM'; $alteredAlbumName = 'controller_test_album_4_altered'; $getAllRequest = sprintf('/album/getall/params/{"websiteId":"%s"}', $websiteId); $this->dispatch($getAllRequest); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('albums', $responseData); $this->assertInternalType('array', $responseData->albums); $this->assertSame(1, count($responseData->albums)); $request = sprintf('/album/edit/params/{"websiteId":"%s","id":"%s","name":"%s"}', $websiteId, $albumId, $alteredAlbumName); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $this->dispatch($getAllRequest); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('albums', $responseData); $this->assertInternalType('array', $responseData->albums); $this->assertSame(1, count($responseData->albums)); $allAlbumsForWebsiteId = $responseData->albums; $this->assertInternalType('array', $allAlbumsForWebsiteId); foreach ($allAlbumsForWebsiteId as $albumsOfWebsiteId) { $this->assertInstanceOf('stdClass', $albumsOfWebsiteId); $this->assertObjectHasAttribute('websiteId', $albumsOfWebsiteId); $this->assertSame($websiteId, $albumsOfWebsiteId->websiteId); $this->assertTrue($this->validateUniqueId(new DataAlbum(), $albumsOfWebsiteId->id)); $this->assertObjectHasAttribute('name', $albumsOfWebsiteId); $this->assertSame($alteredAlbumName, $albumsOfWebsiteId->name); } }
/** * @test * @group integration */ public function removeGroupsOnUserShouldRemoveGroupsAsExpected() { $websiteId = 'SITE-0db7eaa7-7fc5-464a-bd47-06b3b8af00rg-SITE'; $userId = 'USER-0db7eaa7-7fc5-464a-bd47-06b3b8af03rg-USER'; $removeGroupIds = array('"GROUP-1fb7eaa7-7fc5-464a-bd47-16b3b8ag00rg-GROUP"', '"GROUP-1fb7eaa7-7fc5-464a-bd47-16b3b8af07rg-GROUP"'); $removeGroupsRequest = sprintf('/user/removegroups/params/{"id":"%s","websiteid":"%s","groupIds":[%s]}', $userId, $websiteId, implode(',', $removeGroupIds)); $this->dispatch($removeGroupsRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $getByIdRequest = sprintf('/user/getbyid/params/{"id":"%s"}', $userId); $this->dispatch($getByIdRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $actualUserData = $response->getData(); $this->assertObjectHasAttribute('groups', $actualUserData); $actualUserGroups = $actualUserData->groups; $this->assertNull($actualUserGroups); }
/** * @test * @group integration */ public function createUserShouldCreateNonSuperuserAsExpected() { $userAttr = array('lastname' => 'create_test_lastname', 'firstname' => 'create_test_firstname', 'gender' => 'f', 'superuser' => false, 'email' => '*****@*****.**', 'language' => 'en-US'); $this->dispatchWithParams('/user/create', $userAttr); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('id', $responseData); $userId = $responseData->id; $this->assertTrue($this->validateUniqueId(new DataUser(), $userId)); $getByIdRequest = sprintf('/user/getbyid/params/{"id":"%s"}', $userId); $this->dispatch($getByIdRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $actualUserData = $response->getData(); $this->assertNotEmpty($actualUserData); $actualUserFields = array_keys(get_object_vars($actualUserData)); $expectedUserValues = array('id' => $userId, 'lastname' => 'create_test_lastname', 'firstname' => 'create_test_firstname', 'gender' => 'f', 'language' => 'en-US', 'email' => '*****@*****.**', 'superuser' => false, 'isdeletable' => true, 'groups' => null, 'owner' => false, 'readonly' => false); foreach ($actualUserData as $key => $value) { $this->assertSame($expectedUserValues[$key], $value); } }
/** * @test * @group integration */ public function overwriteShouldOverwriteStatedModules() { $config = Registry::getConfig(); DirectoryHelper::clearLatchDirectory(); $websiteId = 'SITE-im12maec-ovwr-4ea8-a477-t4e79e8e62m3-SITE'; $this->dispatch(sprintf('/modul/getAll/params/{"websiteid":"%s"}', $websiteId)); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertTrue(count($responseData->modules) === 4); $modules = array('MODUL-0rap5eb8-0df3-47e9-exti-71ae9d96d3m0-MODUL', 'MODUL-0rap5eb8-0df3-47e9-exti-71ae9d96d3m1-MODUL'); $templates = $media = array(); $importLatchFilesDirectory = $config->import->latch->files->directory; $importFileToLatch = $importLatchFilesDirectory . DIRECTORY_SEPARATOR . 'import_modules_conflict_modules.zip'; $this->assertFileExists($importFileToLatch); $latchBusiness = new LatchBusiness('Latch'); $importId = $latchBusiness->latchImportFile($websiteId, $importFileToLatch); $data = array('templates' => $templates, 'modules' => $modules, 'media' => $media, 'importId' => $importId); $request = sprintf('/import/overwrite/params/%s', json_encode($data)); $this->dispatch($request); $response = $this->getValidatedSuccessResponse(); $responseData = $response->getData(); $this->assertObjectHasAttribute('modules', $responseData); $this->assertObjectHasAttribute('templates', $responseData); $this->assertObjectHasAttribute('media', $responseData); $this->assertObjectHasAttribute('pages', $responseData); $this->assertObjectHasAttribute('website', $responseData); $this->assertEmpty($responseData->website); $this->assertEmpty($responseData->pages); $this->assertEmpty($responseData->templates); $this->assertEmpty($responseData->media); $this->assertNotEmpty($responseData->modules); $importedModules = $responseData->modules; $this->assertTrue(count($importedModules) === 3); $this->dispatch(sprintf('/modul/getAll/params/{"websiteid":"%s"}', $websiteId)); $response = new Response($this->getResponseBody()); $responseData = $response->getData(); $this->assertTrue(count($responseData->modules) === 5); $this->removeImportMediaDirectoryAndFiles($websiteId); }
/** * @test * @group integration */ public function addUsersOnGroupShouldAddUsersAsExpectedOnExistingUsers() { $groupId = 'GROUP-au00e5a7-7fc5-464a-bd47-16b3b8af00de-GROUP'; $websiteId = 'SITE-au00eaa7-7fc5-464a-bd47-16b3b8af00fr-SITE'; $userIdsToAdd = array('"USER-au00ega7-7fc5-464a-bd47-16b3b8af00kl-USER"', '"USER-au01eaa7-7fc5-464a-bd47-16b3b8af01zk-USER"', '"USER-au02eaa7-7fc5-464a-bd47-16b3b8af01zk-USER"'); $alreadyExistingGroupUserIds = array('USER-au00ega0-7fc5-464a-bd47-16b3b8af00kl-USER', 'USER-au00ega1-7fc5-464a-bd47-16b3b8af00kl-USER'); $expectedUserCount = count($userIdsToAdd) + count($alreadyExistingGroupUserIds); $addUsersRequest = sprintf('/group/addusers/params/{"id":"%s","websiteid":"%s","userIds":[%s]}', $groupId, $websiteId, implode(',', $userIdsToAdd)); $this->dispatch($addUsersRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $getByIdRequest = sprintf('/group/getbyid/params/{"id":"%s","websiteId":"%s"}', $groupId, $websiteId); $this->dispatch($getByIdRequest); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $actualGroup = $response->getData(); $actualGroupUsers = $actualGroup->users; $this->assertSame($expectedUserCount, count($actualGroupUsers)); $expectedGroupUsersIds = array_merge($userIdsToAdd, $alreadyExistingGroupUserIds); $expectedGroupUsersIds = array_map(function ($id) { return str_replace('"', '', $id); }, $expectedGroupUsersIds); $actualGroupUsersIds = array_map(function ($user) { return $user->id; }, $actualGroupUsers); sort($actualGroupUsersIds); sort($expectedGroupUsersIds); $this->assertSame($expectedGroupUsersIds, $actualGroupUsersIds); }
/** * @test * @group integration */ public function editMediaShouldAlterAlbumIdAsExpected() { $mediaId = 'MDB-co91d0ec-cb0f-4961-92bd-765d4aa581a4-MDB'; $websiteId = 'SITE-ra10e89c-22ed-46cd-a651-fc42dc78fe51-SITE'; $alteredAlbumId = 'ALBUM-ce1ecf03-acc4-4adb-ed34-72ebb0878alt-ALBUM'; $requestUri = sprintf('/media/edit/params/{"websiteId":"%s","id":"%s","albumId":"%s"}', $websiteId, $mediaId, $alteredAlbumId); $this->dispatch($requestUri); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertEmpty($response->getError()); $this->assertTrue($response->getSuccess()); $getAllRequestUri = sprintf('/media/get/params/{"websiteId":"%s"}', $websiteId); $this->dispatch($getAllRequestUri); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($this->getResponseBody()); $this->dispatch($getAllRequestUri); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($this->getResponseBody()); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('media', $responseData); $this->assertInternalType('array', $responseData->media); $this->assertTrue(count($responseData->media) === 1); $allMediaForWebsiteAndAlbumId = $responseData->media; foreach ($allMediaForWebsiteAndAlbumId as $media) { $this->assertInstanceOf('stdClass', $media); $this->assertObjectHasAttribute('websiteId', $media); $this->assertSame($websiteId, $media->websiteId); $this->assertObjectHasAttribute('id', $media); $this->assertSame($mediaId, $media->id); $this->assertObjectHasAttribute('albumId', $media); $this->assertSame($alteredAlbumId, $media->albumId); } }
/** * @param string $websiteId * @param string $assertionMessage */ protected function assertHasNoTemplates($websiteId, $assertionMessage = null) { $mediaRequestUri = sprintf('/template/getAll/params/{"websiteid":"%s"}', $websiteId); $this->dispatch($mediaRequestUri); $response = $this->getResponseBody(); $this->assertInternalType('string', $response); $this->assertNotNull($response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templates', $responseData); $responseMedias = $responseData->templates; if ($assertionMessage === null) { $assertionMessage = 'There are already templates attached to this website'; } $this->assertTrue(empty($responseMedias), $assertionMessage); }
/** * @test * @group integration * @group bugs * @ticket SBCMS-457 */ public function getAllShouldReturnLimitedAlbumMediaAndTotalMediaCount() { $websiteId = 'SITE-ga10e89c-r2af-46cd-a651-fc42dc78fe5c-SITE'; $albumId = 'ALBUM-ga2ecf03-moe9-4adb-ed3f-72ebb087800c-ALBUM'; $limit = $expectedMediaCount = 5; $expectedTotalCount = 8; $requestUri = sprintf('/media/getall/params/{"websiteid":"%s","albumId":"%s","limit":%d}', $websiteId, $albumId, $limit); $this->dispatch($requestUri); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('media', $responseData); $this->assertObjectHasAttribute('total', $responseData); $this->assertTrue(count(array_keys(get_object_vars($responseData))) === 2); $medias = $responseData->media; $this->assertInternalType('array', $medias); $assertionMessage = sprintf("Didn't get the expected media count of %d", $expectedMediaCount); $this->assertTrue(count($medias) === $expectedMediaCount, $assertionMessage); $assertionMessage = sprintf("Didn't get the expected total media count of %d", $expectedTotalCount); $this->assertSame($expectedTotalCount, $responseData->total, $assertionMessage); }
/** * @test * @group integration */ public function createShouldCreateExpectedTemplateSnippet() { $websiteId = 'SITE-template-snip-pet0-test-000000000001-SITE'; $this->dispatch(sprintf('/templatesnippet/getall/params/{"websiteid":"%s"}', $websiteId)); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templatesnippets', $responseData); $this->assertInternalType('array', $responseData->templatesnippets); $this->assertGreaterThan(0, count($responseData->templatesnippets)); $templateSnippetCountBeforeCreate = count($responseData->templatesnippets); $name = 'TemplateSnippet_Create_Via_Integration_Test'; $request = sprintf('/templatesnippet/create/params/{"name":"%s","websiteid":"%s", "content":[]}', $name, $websiteId); $this->dispatch($request); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $newTemplateSnippet = $response->getData(); $this->assertNotNull($newTemplateSnippet); $this->assertObjectHasAttribute('id', $newTemplateSnippet); $this->assertNotNull($newTemplateSnippet->id); $this->dispatch(sprintf('/templatesnippet/getall/params/{"websiteid":"%s"}', $websiteId)); $response = $this->getResponseBody(); $this->assertNotNull($response); $this->assertInternalType('string', $response); $response = new Response($response); $this->assertTrue($response->getSuccess()); $responseData = $response->getData(); $this->assertObjectHasAttribute('templatesnippets', $responseData); $this->assertInternalType('array', $responseData->templatesnippets); $this->assertGreaterThan(0, count($responseData->templatesnippets)); $this->assertGreaterThan($templateSnippetCountBeforeCreate, count($responseData->templatesnippets)); $newTemplateSnippetData = null; foreach ($responseData->templatesnippets as $templateSnippet) { $this->assertInstanceOf('stdClass', $templateSnippet); $this->assertObjectHasAttribute('id', $templateSnippet); $this->assertObjectHasAttribute('name', $templateSnippet); $this->assertObjectHasAttribute('content', $templateSnippet); if ($templateSnippet->id == $newTemplateSnippet->id) { $newTemplateSnippetData = $templateSnippet; } } $this->assertNotNull($newTemplateSnippetData); $this->assertSame($name, $newTemplateSnippetData->name); $this->assertSame(array(), $newTemplateSnippetData->content); $this->assertEquals('local', $newTemplateSnippetData->sourceType); $this->assertFalse($newTemplateSnippetData->readonly); }
/** * @test * @group integration */ public function copyPageShouldBeRejectedWhenAuthenticatedUserHasNoPagesPrivileges() { $params = array('id' => 'PAGE-co0rsfb8-0363-47e9-0nor-90ae9d96d3c2-PAGE', 'websiteId' => 'SITE-co64e89c-02af-46cd-a651-fc42dc78fe50-SITE', 'name' => 'copy page test'); $paramsAsJson = json_encode($params); $userName = '******'; $userPassword = '******'; $this->assertSuccessfulLogin($userName, $userPassword); $this->activateGroupCheck(); $this->dispatch('page/copy/params/' . $paramsAsJson); $this->deactivateGroupCheck(); $response = $this->getResponseBody(); $response = new Response($response); $this->assertFalse($response->getSuccess()); $responseError = $response->getError(); $this->assertSame(7, $responseError[0]->code); $this->assertNull($response->getData()); }