diff --git a/.ci/Jenkinsfile b/.ci/Jenkinsfile deleted file mode 100644 index b8eabb54..00000000 --- a/.ci/Jenkinsfile +++ /dev/null @@ -1,688 +0,0 @@ -#!groovy - -import org.csanchez.jenkins.plugins.kubernetes.pipeline.PodTemplateAction -import groovy.transform.Field - -String launchUnitTests = "yes" -String launchIntegrationTests = "yes" -String[] pimVersions = ["1.7", "2.0"] -String[] supportedPhpVersions = ["5.6", "7.0", "7.1"] -@Field def String verboseOutputs = "yes" -@Field def String dotsPerLine = "50" - -def clientConfig = [ - "php-http/guzzle6-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7"]], - "php-http/guzzle5-adapter": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7", "zendframework/zend-diactoros", "slim/slim"]], - "php-http/curl-client": ["phpVersion": supportedPhpVersions, "psrImplem": ["guzzlehttp/psr7", "zendframework/zend-diactoros", "slim/slim"]] -] - -imageRepo = "eu.gcr.io/akeneo-ci/php-api-client" -imageTag = "pull-request-${env.CHANGE_ID}-build-${env.BUILD_NUMBER}" -gcrImages = [] - -def clients = clientConfig.keySet() as String[] -def buildResult= 'SUCCESS' - -try { - stage("Build") { - milestone 1 - if (env.BRANCH_NAME =~ /^PR-/) { - userInput = input(message: 'Launch tests?', parameters: [ - string(defaultValue: pimVersions.join(','), description: 'PIM edition the tests should run on', name: 'requiredPimVersions'), - choice(choices: 'yes\nno', description: 'Run unit tests and code style checks', name: 'launchUnitTests'), - choice(choices: 'yes\nno', description: 'Run integration tests', name: 'launchIntegrationTests'), - choice(choices: 'no\nyes', description: 'Enable Verbose mode', name: 'verboseOutputs'), - string(defaultValue: '50', description: 'Number of dots per line', name: 'dotsperline'), - string(defaultValue: clients.join(','), description: 'Clients used to run integration tests (comma separated values)', name: 'clients'), - choice(choices: 'no\nyes', description: 'Enable Verbose mode', name: 'verboseOutputs'), - string(defaultValue: '50', description: 'Number of dots per line', name: 'dotsperline'), - ]) - - pimVersions = userInput['requiredPimVersions'].tokenize(',') - launchUnitTests = userInput['launchUnitTests'] - launchIntegrationTests = userInput['launchIntegrationTests'] - clients = userInput['clients'].tokenize(',') - verboseOutputs = userInput['verboseOutputs'] - dotsPerLine = userInput['dotsperline'] - } - milestone 2 - - checkouts = [:] - - if (launchUnitTests.equals("yes")) { - String currentClient = "php-http/guzzle6-adapter" - String currentPsrImplem = "guzzlehttp/psr7" - - for (phpVersion in clientConfig.get(currentClient).get("phpVersion")) { - String currentPhpVersion = phpVersion - - checkouts["${currentClient}-${currentPsrImplem}-${currentPhpVersion}"] = {buildClient(currentPhpVersion, currentClient, currentPsrImplem)} - } - } - - if (launchIntegrationTests.equals("yes")) { - for (pimVersion in pimVersions) { - String currentPimVersion = pimVersion - - switch (currentPimVersion) { - case "1.7": - checkouts["pim_community_dev_${currentPimVersion}"] = {buildPim(currentPimVersion, "5.6")} - break - case "2.0": - checkouts["pim_community_dev_${currentPimVersion}"] = {buildPim(currentPimVersion, "7.1")} - break - default: - error("pimVersion \"${pimVersion}\" is not a valid version managed by this script..") - break - } - } - - for (client in clients) { - for (phpVersion in clientConfig.get(client).get("phpVersion")) { - for (psrImplem in clientConfig.get(client).get("psrImplem")) { - String currentClient = client - String currentPhpVersion = phpVersion - String currentPsrImplem = psrImplem - - checkouts["${currentClient}-${currentPsrImplem}-${currentPhpVersion}"] = {buildClient(currentPhpVersion, currentClient, currentPsrImplem)} - } - } - } - } - - parallel checkouts - } - - if (launchUnitTests.equals("yes")) { - stage("Unit tests and Code style") { - def tasks = [:] - - String currentClient = "php-http/guzzle6-adapter" - String currentPsrImplem = "guzzlehttp/psr7" - - tasks["php-cs-fixer"] = {runPhpCsFixerTest("7.1", currentClient, currentPsrImplem)} - - for (phpVersion in clientConfig.get(currentClient).get("phpVersion")) { - String currentPhpVersion = phpVersion - - tasks["phpspec-${phpVersion}"] = {runPhpSpecTest(currentPhpVersion, currentClient, currentPsrImplem)} - } - - try { - parallel tasks - } catch (e) { - println e - buildResult = 'FAILURE' - } - } - } - - if (launchIntegrationTests.equals("yes")) { - for (pimVersion in pimVersions) { - String currentPimVersion = pimVersion - stage("Integration tests ${currentPimVersion}") { - def tasks = [:] - - for (client in clients) { - for (phpVersion in clientConfig.get(client).get("phpVersion")) { - for (psrImplem in clientConfig.get(client).get("psrImplem")) { - String currentClient = client - String currentPsrImplem = psrImplem - String currentPhpVersion = phpVersion - - tasks["phpunit-${currentClient}-${currentPsrImplem}-${currentPhpVersion}"] = {runIntegrationTest(currentPhpVersion, currentClient, currentPsrImplem, currentPimVersion)} - } - } - } - - try { - parallel tasks - } catch (e) { - println e - buildResult = 'FAILURE' - } - } - } - } -} catch (e) { - println e - buildResult = 'FAILURE' -} finally { - stage("Cleanup") { - if (gcrImages.size() > 0) { - withDockerGcloud({ - sh "gcloud -q container images delete " + gcrImages.join(" ") - }) - } else { - echo "Nothing to cleanup" - } - } - - currentBuild.result = buildResult -} - -/** - * Run checkout of the PIM for a given PHP version and a PIM version. - * Run composer, prepare configuration files and push data to a docker registry image. - * - * @param pimVersion PIM version to checkout - */ -void buildPim(String pimVersion, String phpVersion) { - - withBuildNode(phpVersion,{ - dir("git") { - checkout([$class: 'GitSCM', - branches: [[name: pimVersion]], - userRemoteConfigs: [[credentialsId: 'github-credentials', url: 'https://github.com/akeneo/pim-community-dev.git']] - ]) - - container("php") { - sh "php -d memory_limit=-1 /usr/local/bin/composer --ansi require \"akeneo/catalogs\":\"dev-master\" --optimize-autoloader --no-interaction --no-progress --prefer-dist" - sh "cp app/config/parameters.yml.dist app/config/parameters.yml" - sh "sed -i \"s#database_host: .*#database_host: 127.0.0.1#g\" app/config/parameters.yml" - if ("2.0" == pimVersion) { - sh "sed -i \"s#index_hosts: .*#index_hosts: 'elastic:changeme@127.0.0.1:9200'#g\" app/config/parameters.yml" - } - sh "sed -i \"s#installer_data: .*#installer_data: '%kernel.root_dir%/../vendor/akeneo/catalogs/${pimVersion}/community/api/fixtures'#\" app/config/pim_parameters.yml" - } - - String gcrImageName = getPimGCRImageName(pimVersion) - saveDockerData(gcrImageName) - - // Add image to array for cleanup - gcrImages += "${gcrImageName}" - } - }) -} - -/** - * Run checkout of the PHP client, for a given PHP version, HTTP client and PSR7 implementation. - * Run composer, prepare configuration files and push data to a docker registry image. - * - * @param phpVersion PHP version to use to run the composer - * @param client Name of the HTTP client package to use to checkout - * @param psrImplem Name of the PSR 7 implementation package to checkout - */ -void buildClient(String phpVersion, String client, String psrImplem) { - withBuildNode(phpVersion,{ - dir("git") { - checkout scm - - container("php") { - sh "composer --ansi require ${client} ${psrImplem}" - sh "composer --ansi update --optimize-autoloader --no-interaction --no-progress --prefer-dist --no-suggest" - sh "cp tests/etc/parameters.yml.dist tests/etc/parameters.yml" - sh "sed -i \"s#base_uri: .*#base_uri: 'http://akeneo-pim'#g\" tests/etc/parameters.yml" - sh "sed -i \"s#install_path: .*#install_path: '/home/jenkins/pim'#g\" tests/etc/parameters.yml" - } - - String gcrImageName = getApiClientGCRImageName(phpVersion, client, psrImplem) - saveDockerData(gcrImageName) - - // Add image to array for cleanup - gcrImages += "${gcrImageName}" - } - }) -} - -/** - * Run php cs fixer, for a given PHP version, HTTP client and PSR7 implementation. - * - * @param phpVersion PHP version to run the test with - * @param client Name of the HTTP client package to run the test with - * @param psrImplem Name of the PSR 7 implementation package to run the test with - */ -void runPhpCsFixerTest(String phpVersion, String client, String psrImplem) { - String phpApiImage = getApiClientGCRImageName(phpVersion, client, psrImplem) - - withPhpApi(phpApiImage, phpVersion, { - dir("/home/jenkins/php-api-client") { - try { - sh "./bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php --format=junit > junit_output.xml" - } finally { - sh """sed -i 's/testcase name="/testcase name="[php-cs-fixer] /' junit_output.xml""" - junit "junit_output.xml" - } - } - }) -} - -/** - * Run PHPspec tests, for a given PHP version, HTTP client and PSR7 implementation. - * - * @param phpVersion PHP version to run the test with - * @param client Name of the HTTP client package to use to run the test with - * @param psrImplem Name of the PSR 7 implementation package to run the test with - */ -void runPhpSpecTest(String phpVersion, String client, String psrImplem) { - String phpApiImage = getApiClientGCRImageName(phpVersion, client, psrImplem) - - withPhpApi(phpApiImage, phpVersion, { - dir("/home/jenkins/php-api-client") { - try { - sh "./bin/phpspec run --no-interaction --format=junit > junit_output.xml" - } finally { - sh """sed -i 's/testcase name="/testcase name="[php-${phpVersion}] /' junit_output.xml""" - junit "junit_output.xml" - } - } - }) -} - -/** - * Run integration tests of the PHP client, for a given PHP version, HTTP client, PSR7 implementation and a PIM version. - * First, it starts the PIM. The configuration of the PIM (composer, parameters) is already done in the checkout step. - * Then, it launches the PHPUnit tests. - * - * Do note that PHPUnit resets the PIM database between each test and generates the API client id/secret, - * thanks to "docker exec" commands inside the PHPUnit process. - * In order to do that, the docker socket and docker bin are exposed as volumes to the PHPUnit container. - * - * @param phpVersion PHP version to run the test with - * @param client Name of the HTTP client package to use to run the test with - * @param psrImplem Name of the PSR 7 implementation package to run the test with - * @param pimVersion PIM version to run the test with - */ -void runIntegrationTest(String phpVersion, String client, String psrImplem, String pimVersion) { - switch (pimVersion) { - case "1.7": - runPim17IntegrationTest(phpVersion, client, psrImplem) - break - case "2.0": - runPim2IntegrationTest(phpVersion, client, psrImplem, pimVersion) - break - default: - error("pimVersion \"${pimVersion}\" is not a valid version managed by this script..") - break - } -} - -/** - * Run integration tests of the PHP client, for a given PHP version, HTTP client and PSR7 implementation on PIM version 1.7. - * - * 1) Ask to use Kubernetes PIM 1.7 pod template with specific data images (Depending on phpVersion, client, psrImplem) - * 2) Scan all PHP test files in folder "tests/v1_7/Api" and "tests/Common/Api" - * 3) For each php file, K8s create a PIM 1.7 pod and run commands inside defined container (Install PIM and launch tests) - * - * Do note that PHPUnit resets the PIM database between each test and generates the API client id/secret, - * thanks to "docker exec" commands inside the PHPUnit process. - * In order to do that, K8s pod template (pim_20_ce.yaml) need to mount docker socket and docker bin from host to "php-api-container". - * Because K8s will create numbers of PIMs in parallel, there won't be one "pim" containers name as in Docker. - * So we have to call Kubernetes API to get our current "php" container ID and put it in the the "docker_name" of parameters.yml - * - * @param phpVersion PHP version to run the test with - * @param client Name of the HTTP client package to use to run the test with - * @param psrImplem Name of the PSR 7 implementation package to run the test with - */ -def runPim17IntegrationTest(String phpVersion, String client, String psrImplem) { - String pimVersion = "1.7" - String phpApiImageName = getApiClientGCRImageName(phpVersion, client, psrImplem) - String pimImageName = getPimGCRImageName(pimVersion) - - queue(phpApiImageName, pimImageName, pimVersion, phpVersion, { - def messages = new net.sf.json.JSONArray() - def files = [] - - // Find and store PHP test integration files to launch them in parallels - files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/v1_7/Api -name "*Integration.php"').tokenize('\n') - files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n') - - for (file in files) { - def commands = [ - // Export "php" container id into shared file (We use ''' has we don't want groovy interpolation for $) - // And clean kubernetes' docker prefix "docker://" (Take care, pubsub uses Busybox's sed != GNU sed) - [container: "pubsub", script: '''sh -c "kubectl get pod \\${POD_NAME} -o jsonpath='{$.status.containerStatuses[?(@.name==\\"php\\")].containerID}' | sed 's#docker://##g' > /home/jenkins/php-container-id" '''], - // Set "php" container id to parameters.yml - [container: "php-api", script: '''sh -c 'sed -i "s#docker_name: .*#docker_name: $(cat /home/jenkins/php-container-id)#g" tests/etc/parameters.yml' '''], - // Copy apache configuration for Kubernetes - [container: "php", script: "sudo cp /home/jenkins/php-api-client/.ci/akeneo.conf /etc/apache2/sites-available/000-default.conf"], - // Own pim folder to docker user/group (which is also the apache user) - [container: "php", script: "chown -R docker:docker /home/jenkins/pim"], - // Reload apache (No restart otherwise pod will crash) - [container: "php", script: "sudo /usr/sbin/apache2ctl graceful"], - // Install pim as docker user - [container: "php", script: "su docker -c './app/console pim:install -e prod'"], - [ - container: "php-api", - junit: [in: "/home/jenkins/php-api-client/", name: "junit_output.xml"], - script: 'sudo php -d error_reporting="E_ALL" ./bin/phpunit -c phpunit.xml.dist '+file+' --log-junit junit_output.xml' - ] - ] - def message = new net.sf.json.JSONObject() - message.put("name",file) - message.put("commands",commands) - messages.add(message) - } - return messages - }, verboseOutputs, dotsPerLine) -} - -/** - * Run integration tests of the PHP client, for a given PHP version, HTTP client and PSR7 implementation on PIM version 2.0. - * - * 1) Ask to use Kubernetes PIM 2.0 pod template with specific data images (Depending on phpVersion, client, psrImplem) - * 2) Scan all PHP test files in folder "tests/v2_0/Api" and "tests/Common/Api" - * 3) For each php file, K8s create a PIM 2.0 pod and run commands inside defined container (Install PIM and launch tests) - * - * Do note that PHPUnit resets the PIM database between each test and generates the API client id/secret, - * thanks to "docker exec" commands inside the PHPUnit process. - * In order to do that, K8s pod template (pim_20_ce.yaml) need to mount docker socket and docker bin from host to "php-api-container". - * Because K8s will create numbers of PIMs in parallel, there won't be one "pim" containers name as in Docker. - * So we have to call Kubernetes API to get our current "php" container ID and put it in the the "docker_name" of parameters.yml - * - * @param phpVersion PHP version to run the test with - * @param client Name of the HTTP client package to use to run the test with - * @param psrImplem Name of the PSR 7 implementation package to run the test with - */ -def runPim2IntegrationTest(String phpVersion, String client, String psrImplem, String pimVersion) { - String phpApiImageName = getApiClientGCRImageName(phpVersion, client, psrImplem) - String pimImageName = getPimGCRImageName(pimVersion) - - queue(phpApiImageName, pimImageName, pimVersion, phpVersion, { - def messages = new net.sf.json.JSONArray() - def files = [] - - // Find and store PHP test integration files to launch them in parallels - files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/v2_0/Api -name "*Integration.php"').tokenize('\n') - files += sh (returnStdout: true, script: 'find /home/jenkins/php-api-client/tests/Common/Api -name "*Integration.php"').tokenize('\n') - for (file in files) { - def commands = [ - // Export "php" container id into shared file (We use ''' has we don't want groovy interpolation for $) - // And clean kubernetes' docker prefix "docker://" (Take care, pubsub uses Busybox's sed != GNU sed) - [container: "pubsub", script: '''sh -c "kubectl get pod \\${POD_NAME} -o jsonpath='{$.status.containerStatuses[?(@.name==\\"php\\")].containerID}' | sed 's#docker://##g' > /home/jenkins/php-container-id" '''], - // Set "php" container id to parameters.yml - [container: "php-api", script: '''sh -c 'sed -i "s#docker_name: .*#docker_name: $(cat /home/jenkins/php-container-id)#g" tests/etc/parameters.yml' '''], - // Change php-api-client conf for Pim 2.x - [container: "php-api", script: '''sed -i 's#bin_path: .*#bin_path: bin#g' tests/etc/parameters.yml'''], - [container: "php-api", script: '''sed -i 's#version: .*#version: #g' tests/etc/parameters.yml'''], - // Copy apache configuration for Kubernetes - [container: "httpd", script: "cp /home/jenkins/php-api-client/.ci/akeneo.conf /usr/local/apache2/conf/vhost.conf"], - // Reload apache (No restart otherwise pod will crash) - [container: "httpd", script: "pkill -HUP httpd"], - // Install pim as docker user - [container: "php", script: "bin/console pim:install -e prod"], - // Own pim folder to docker user/group (which is also the apache user) - [container: "php", script: "chown -R www-data:www-data /home/jenkins/pim/"], - [ - container: "php-api", - junit: [in: "/home/jenkins/php-api-client/", name: "junit_output.xml"], - script: 'php -d error_reporting="E_ALL" ./bin/phpunit -c phpunit.xml.dist '+file+' --log-junit junit_output.xml' - ] - ] - def message = new net.sf.json.JSONObject() - message.put("name",file) - message.put("commands",commands) - messages.add(message) - } - return messages - }, verboseOutputs, dotsPerLine) -} - -/** - * This function allow you to run Google Cloud commands - * - * @param body Groovy script to execute inside Jenkins node - * - * Kubernetes Template : - * (Default location is set to "/home/jenkins") - * - (Run) docker : Run Google Cloud commands inside - * - (Run) php : Run PHP commands inside - */ -def withBuildNode(String phpVersion, body) { - clearTemplateNames() - def uuid = UUID.randomUUID().toString() - - withCredentials([string(credentialsId: 'composer-token', variable: 'token')]) { - podTemplate(name: "php-api-client-node", label: "build-" + uuid, containers: [ - containerTemplate( - name: "docker", - image: "paulwoelfel/docker-gcloud", - ttyEnabled: true, - command: 'cat', - envVars: [envVar(key: "DOCKER_API_VERSION", value: "1.23")], - resourceRequestCpu: '100m', resourceRequestMemory: '200Mi'), - containerTemplate( - name: "php", - image: "akeneo/php:${phpVersion}", - ttyEnabled: true, - command: 'cat', - alwaysPullImage: true, - envVars: [ - envVar(key: "COMPOSER_AUTH", value: "{\"github-oauth\":{\"github.com\": \"$token\"}}")], - resourceRequestCpu: '500m', - resourceRequestMemory: '1000Mi') - ], volumes: [ - hostPathVolume(hostPath: "/var/run/docker.sock", mountPath: "/var/run/docker.sock") - ]) { - node("build-" + uuid) { - dir('/home/jenkins') { - body() - } - } - } - } -} - -/** - * This function allow you to run Google Cloud commands - * - * @param body Groovy script to execute inside "docker" container - * - * Kubernetes Template : - * - (Run) docker : Run Google Cloud commands inside - */ -def withDockerGcloud(body) { - clearTemplateNames() - def uuid = UUID.randomUUID().toString() - - podTemplate(name: "php-api-client-gcloud", label: "dockergcloud-" + uuid, containers: [ - containerTemplate( - name: "docker", - image: "paulwoelfel/docker-gcloud", - ttyEnabled: true, - command: 'cat', - resourceRequestCpu: '100m', - resourceRequestMemory: '200Mi', - envVars: [envVar(key: "DOCKER_API_VERSION", value: "1.23")]) - ], volumes: [ - hostPathVolume(hostPath: "/var/run/docker.sock", mountPath: "/var/run/docker.sock") - ]) { - node("dockergcloud-" + uuid) { - container("docker") { - body() - } - } - } -} - -/** - * This function allow you to run php commands with php-api-client sources - * - * @param phpApiImageName Full GCR image name to pull, containing php-api-client data - * @param phpVersion PHP version to run the test with - * @param body Groovy script to execute inside "php" container - * - * Kubernetes Template : - * - (Init) php-api-client : Copy php-api-client sources to /home/jenkins/php-api-client - * - (Run) php : Run PHP commands inside - */ -def withPhpApi(String phpApiImageName, String phpVersion, body) { - clearTemplateNames() - def uuid = UUID.randomUUID().toString() - - podTemplate(name: "php-api-client-php", label: "php-" + uuid, containers: [ - containerTemplate( - name: "php", - image: "akeneo/php:${phpVersion}", - ttyEnabled: true, - command: 'cat', - alwaysPullImage: true, - resourceRequestCpu: '500m', - resourceRequestMemory: '1000Mi') - ], annotations: [ - podAnnotation(key: "pod.beta.kubernetes.io/init-containers", value: - """ - [{ - "name": "php-api-client-data", - "image": "${phpApiImageName}", - "imagePullPolicy": "Always", - "command": ["sh", "-c", "mkdir -p /home/jenkins/php-api-client && cp -Rp /data/. /home/jenkins/php-api-client"], - "volumeMounts":[{ - "name": "workspace-volume", - "mountPath": "/home/jenkins" - }] - }] - """) - ]) { - node("php-" + uuid) { - container("php") { - body() - } - } - } -} - -/** - * This function allow you to run a list of messages on parallel pods. - * Each message will create a kubernetes pod (based on template) and run its commands sequentially. - * - * @param phpApiImageName Full GCR image name to pull, containing php-api-client data - * @param pimImageName Full GCR image name to pull, containing pim data - * @param pimVersion PIM version to run the test with - * @param phpVersion PHP version to run the test with - * @param body JSON Array containing the list of messages to execute in parallel - * - * Kubernetes Template : - * - (Init) php-api-client : Copy php-api-client sources to /home/jenkins/php-api-client (Used for K8s PIM's template) - * - (Run) gcloud : Used to manage pubsub queues and to create PIM's Kubernetes pods (Based on template) - */ - -def queue(String phpApiImageName, String pimImageName, String pimVersion, String phpVersion, body, verboseOutputs, dotsPerLine) { - def verbosity = (verboseOutputs == "yes") ? "-v" : "" - def linesize = (dotsPerLine.isNumber())? dotsPerLine :"50" - clearTemplateNames() - def uuid = UUID.randomUUID().toString() - // Maximum pods in parallel. Default set to number of messages - def maxScale = 100 - def k8s_template - - // Define Kubernetes pod template based on PIM version - switch (pimVersion) { - case "1.7": - k8s_template = "pim_17_ce.yaml" - break - case "2.0": - k8s_template = "pim_20_ce.yaml" - break - default: - error("pimVersion \"${pimVersion}\" is not a valid version managed by this script..") - break - } - - podTemplate(name: "php-api-client-pubsub", label: "pubsub-" + uuid, containers: [ - containerTemplate(name: "gcloud", ttyEnabled: true, command: 'cat', image: "eu.gcr.io/akeneo-ci/gcloud:1.0", alwaysPullImage: true, resourceRequestCpu: '100m', resourceRequestMemory: '200Mi', envVars: [envVar(key: "PUBSUB_PROJECT_ID", value: "akeneo-ci")]) - ], annotations: [ - podAnnotation(key: "pod.beta.kubernetes.io/init-containers", value: - """ - [{ - "name": "php-api-client-data", - "image": "${phpApiImageName}", - "imagePullPolicy": "Always", - "command": ["sh", "-c", "mkdir -p /home/jenkins/php-api-client && cp -Rp /data/. /home/jenkins/php-api-client"], - "volumeMounts":[{ - "name": "workspace-volume", - "mountPath": "/home/jenkins" - }] - }] - """) - ], volumes: [ - hostPathVolume(hostPath: "/var/run/docker.sock", mountPath: "/var/run/docker.sock"), - hostPathVolume(hostPath: "/usr/bin/docker", mountPath: "/usr/bin/docker") - - ]) { - node("pubsub-" + uuid) { - def messages = body() - - container("gcloud") { - sh "gcloud.phar pubsub:topic:create ${env.NODE_NAME}" - sh "gcloud.phar pubsub:topic:create ${env.NODE_NAME}-results" - sh "gcloud.phar pubsub:subscription:create ${env.NODE_NAME} ${env.NODE_NAME}-subscription" - sh "gcloud.phar pubsub:subscription:create ${env.NODE_NAME}-results ${env.NODE_NAME}-results-subscription" - - def size = messages.size() - def scale = size > maxScale ? maxScale : size - - writeJSON file: 'output.json', json: messages - sh "gcloud.phar pubsub:message:publish ${env.NODE_NAME} output.json" - - sh """sed -i \ - -e 's#JOB_SCALE#${scale}#g' \ - -e 's#JOB_NAME#${env.NODE_NAME}#g' \ - -e 's#JOB_COMPLETIONS#${size}#g' \ - -e 's#SUBSCRIPTION_NAME#${env.NODE_NAME}-subscription#g' \ - -e 's#RESULT_TOPIC#${env.NODE_NAME}-results#g' \ - -e 's#API_CLIENT_IMAGE#${phpApiImageName}#g' \ - -e 's#PIM_IMAGE#${pimImageName}#g' \ - -e 's#PHP_API_VERSION#${phpVersion}#g' \ - /home/jenkins/php-api-client/.ci/k8s/${k8s_template} - """ - - try { - sh "cat /home/jenkins/php-api-client/.ci/k8s/${k8s_template}" - sh "kubectl apply -f /home/jenkins/php-api-client/.ci/k8s/${k8s_template}" - sh "gcloud.phar ${verbosity} job:wait --dotsperline ${linesize} ${env.NODE_NAME}-results-subscription ${size} ${env.WORKSPACE} --ansi" - } finally { - sh "kubectl delete job ${env.NODE_NAME}" - sh "gcloud.phar pubsub:topic:delete ${env.NODE_NAME}" - sh "gcloud.phar pubsub:topic:delete ${env.NODE_NAME}-results" - sh "gcloud.phar pubsub:subscription:delete ${env.NODE_NAME}-subscription" - sh "gcloud.phar pubsub:subscription:delete ${env.NODE_NAME}-results-subscription" - - junit allowEmptyResults: true, testResults: 'junit/**/*.xml' - } - } - } - } -} - -@NonCPS -def clearTemplateNames() { - // see https://issues.jenkins-ci.org/browse/JENKINS-42184 - currentBuild.rawBuild.getAction( PodTemplateAction.class )?.stack?.clear() -} - -/** - * Save current folder content inside a Docker image and push it to Google Cloud Registry - * - * @param gcrName PHP version to run the test with - * @param gCloudcontainerName Container name allowed to build and push images to Google Cloud Registry - */ -def saveDockerData(String gcrName, String gCloudcontainerName = "docker") { - container(gCloudcontainerName) { - sh "echo 'FROM alpine:3.6\nADD . /data\n' > Dockerfile" - sh "docker build -t ${gcrName} ." - sh "gcloud docker -- push ${gcrName}" - } -} - -/** - * Give a structured name to tag current php-api-client data into Google Cloud Registry - * - * @param phpVersion PHP version to run the test with - * @param client name of the HTTP client package to use to run the test with - * @param psrImplem name of the PSR 7 implementation package to run the test with - */ -def getApiClientGCRImageName(String phpVersion, String client, String psrImplem) { - String imageName = "${client}_${psrImplem}_php-${phpVersion}".replaceAll("/", "_") - return "${imageRepo}/${imageName}:${imageTag}" -} - -/** - * Give a structured name to tag current pim data into Google Cloud Registry - * - * @param pimVersion PIM version to run the test with - */ -def getPimGCRImageName(String pimVersion) { - String imageName = "pim_community_dev_${pimVersion}".replaceAll("/", "_") - return "${imageRepo}/${imageName}:${imageTag}" -} diff --git a/.ci/akeneo.conf b/.ci/akeneo.conf deleted file mode 100644 index 7ac3f355..00000000 --- a/.ci/akeneo.conf +++ /dev/null @@ -1,22 +0,0 @@ - - ServerName 127.0.0.1 - - DocumentRoot /home/jenkins/pim/web - - AllowOverride None - Require all granted - - Options -MultiViews - RewriteEngine On - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ app.php [QSA,L] - - - - Options FollowSymlinks - - - - RewriteEngine Off - - diff --git a/.ci/k8s/pim_17_ce.yaml b/.ci/k8s/pim_17_ce.yaml deleted file mode 100644 index e341f98f..00000000 --- a/.ci/k8s/pim_17_ce.yaml +++ /dev/null @@ -1,111 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: JOB_NAME -spec: - completions: JOB_COMPLETIONS - parallelism: JOB_SCALE - template: - spec: - initContainers: - - name: php-api-client-data - image: API_CLIENT_IMAGE - imagePullPolicy: Always - command: ['sh', '-c', 'mkdir -p /home/jenkins/php-api-client && cp -Rp /data/. /home/jenkins/php-api-client'] - volumeMounts: - - { mountPath: /home/jenkins, name: pim } - - name: pim-community-dev-data - image: PIM_IMAGE - imagePullPolicy: Always - command: ['sh', '-c', 'mkdir -p /home/jenkins/pim && cp -Rp /data/. /home/jenkins/pim'] - volumeMounts: - - { mountPath: /home/jenkins, name: pim } - hostAliases: - - ip: "127.0.0.1" - hostnames: - - "akeneo" - - "akeneo.dev" - - "akeneo-pim" - - "mysql" - containers: - - name: mysql - image: eu.gcr.io/akeneo-ci/mysql:5.5 - imagePullPolicy: Always - env: - - { name: MYSQL_ROOT_PASSWORD, value: root } - - { name: MYSQL_USER, value: akeneo_pim } - - { name: MYSQL_PASSWORD, value: akeneo_pim } - - { name: MYSQL_DATABASE, value: akeneo_pim } - readinessProbe: - timeoutSeconds: 5 - initialDelaySeconds: 5 - failureThreshold: 30 - exec: - command: ["mysql", "-proot", "-h", "127.0.0.1", "-e", "SELECT 1"] - volumeMounts: - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - resources: - requests: {cpu: "100m", memory: "700Mi"} - - name: php-api - image: akeneo/apache-php:php-PHP_API_VERSION - command: ["/bin/bash", "-c"] - args: - - | - tail -f /dev/null & - CHILD_PID=$! - (while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then kill $CHILD_PID; fi; sleep 1; done) & - wait $CHILD_PID - if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi - workingDir: /home/jenkins/php-api-client - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - - { name: docker-socket, mountPath: /var/run/docker.sock } - - { name: docker-exec, mountPath: /usr/bin/docker } - resources: - requests: {cpu: "300m", memory: "300Mi"} - - name: php - image: akeneo/apache-php:php-5.6 - command: ["/bin/bash", "-c"] - args: - - | - sudo /usr/local/bin/apache-foreground & - CHILD_PID=$! - (while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then sudo kill -9 $CHILD_PID; fi; sleep 1; done) & - wait $CHILD_PID - if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi - workingDir: /home/jenkins/pim - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - lifecycle: - preStop: - exec: - command: ["/usr/sbin/apache2ctl", "stop"] - resources: - requests: {cpu: "500m", memory: "750Mi"} - - name: pubsub - image: eu.gcr.io/akeneo-ci/gcloud:1.0 - imagePullPolicy: Always - - command: ["/bin/sh", "-c"] - args: - - | - trap "touch /tmp/pod/main-terminated" EXIT - gcloud.phar pubsub:message:consume SUBSCRIPTION_NAME RESULT_TOPIC - env: - - { name: REDIS_URI, value: "tcp://redis.jenkins:6379" } - - { name: POD_NAME, valueFrom: { fieldRef: { fieldPath: metadata.name } } } - - { name: NAMESPACE, valueFrom: { fieldRef: { fieldPath: metadata.namespace } } } - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod } - resources: - requests: {cpu: "100m", memory: "100Mi"} - volumes: - - { name: pim, emptyDir: {medium: Memory}} - - { name: tmp-pod, emptyDir: {medium: Memory}} - - { name: mysql, emptyDir: {medium: Memory}} - - { name: docker-socket, hostPath: { path: /var/run/docker.sock }} - - { name: docker-exec, hostPath: { path: /usr/bin/docker }} - restartPolicy: Never diff --git a/.ci/k8s/pim_20_ce.yaml b/.ci/k8s/pim_20_ce.yaml deleted file mode 100644 index 6746c990..00000000 --- a/.ci/k8s/pim_20_ce.yaml +++ /dev/null @@ -1,147 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: JOB_NAME -spec: - completions: JOB_COMPLETIONS - parallelism: JOB_SCALE - template: - spec: - initContainers: - - name: php-api-client-data - image: API_CLIENT_IMAGE - imagePullPolicy: Always - command: ['sh', '-c', 'mkdir -p /home/jenkins/php-api-client && cp -Rp /data/. /home/jenkins/php-api-client'] - volumeMounts: - - { mountPath: /home/jenkins, name: pim } - - name: pim-community-dev-data - image: PIM_IMAGE - imagePullPolicy: Always - command: ['sh', '-c', 'mkdir -p /home/jenkins/pim && cp -Rp /data/. /home/jenkins/pim'] - volumeMounts: - - { mountPath: /home/jenkins, name: pim } - hostAliases: - - ip: "127.0.0.1" - hostnames: - - "akeneo" - - "akeneo.dev" - - "akeneo-pim" - - "mysql" - containers: - - name: mysql - image: eu.gcr.io/akeneo-ci/mysql:5.7 - imagePullPolicy: Always - env: - - { name: MYSQL_ROOT_PASSWORD, value: root } - - { name: MYSQL_USER, value: akeneo_pim } - - { name: MYSQL_PASSWORD, value: akeneo_pim } - - { name: MYSQL_DATABASE, value: akeneo_pim } - readinessProbe: - timeoutSeconds: 5 - initialDelaySeconds: 5 - failureThreshold: 30 - exec: - command: ["mysql", "-proot", "-h", "127.0.0.1", "-e", "SELECT 1"] - volumeMounts: - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - resources: - requests: {cpu: "100m", memory: "700Mi"} - - name: php-api - image: akeneo/apache-php:php-PHP_API_VERSION - command: ["/bin/bash", "-c"] - args: - - | - tail -f /dev/null & - CHILD_PID=$! - (while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then kill $CHILD_PID; fi; sleep 1; done) & - wait $CHILD_PID - if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi - workingDir: /home/jenkins/php-api-client - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - - { name: docker-socket, mountPath: /var/run/docker.sock } - - { name: docker-exec, mountPath: /usr/bin/docker } - resources: - requests: {cpu: "300m", memory: "300Mi"} - - name: php - image: eu.gcr.io/akeneo-ci/php:7.1-fpm - imagePullPolicy: Always - command: ["/bin/bash", "-c"] - args: - - | - php-fpm & - CHILD_PID=$! - (while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then kill $CHILD_PID; fi; sleep 1; done) & - wait $CHILD_PID - if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi - workingDir: /home/jenkins/pim - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - resources: - requests: {cpu: "300m", memory: "300Mi"} - - name: httpd - image: eu.gcr.io/akeneo-ci/httpd:2.4 - command: ["/bin/bash", "-c"] - args: - - | - httpd-foreground & - CHILD_PID=$! - (while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then kill $CHILD_PID; fi; sleep 1; done) & - wait $CHILD_PID - if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - resources: - requests: {cpu: "100m", memory: "200Mi"} - - name: elasticsearch - image: docker.elastic.co/elasticsearch/elasticsearch:5.5.2 - command: ["/bin/bash", "-c"] - args: - - | - /usr/share/elasticsearch/bin/es-docker & - CHILD_PID=$! - (while true; do if [[ -f "/tmp/pod/main-terminated" ]]; then kill $CHILD_PID; fi; sleep 1; done) & - wait $CHILD_PID - if [[ -f "/tmp/pod/main-terminated" ]]; then exit 0; fi - env: - - { name: ES_JAVA_OPTS, value: "-Xms1g -Xmx1g" } - volumeMounts: - - { name: tmp-pod, mountPath: /tmp/pod, readOnly: true } - resources: - requests: {cpu: "100m", memory: "1500Mi"} - readinessProbe: - httpGet: - path: / - port: 9200 - httpHeaders: - - name: Authorization - value: Basic ZWxhc3RpYzpjaGFuZ2VtZQ== - timeoutSeconds: 1 - initialDelaySeconds: 5 - - name: pubsub - image: eu.gcr.io/akeneo-ci/gcloud:1.0 - imagePullPolicy: Always - command: ["/bin/sh", "-c"] - args: - - | - trap "touch /tmp/pod/main-terminated" EXIT - gcloud.phar pubsub:message:consume SUBSCRIPTION_NAME RESULT_TOPIC - env: - - { name: REDIS_URI, value: "tcp://redis.jenkins:6379" } - - { name: POD_NAME, valueFrom: { fieldRef: { fieldPath: metadata.name } } } - - { name: NAMESPACE, valueFrom: { fieldRef: { fieldPath: metadata.namespace } } } - volumeMounts: - - { name: pim, mountPath: /home/jenkins } - - { name: tmp-pod, mountPath: /tmp/pod } - resources: - requests: {cpu: "100m", memory: "100Mi"} - volumes: - - { name: pim, emptyDir: {medium: Memory}} - - { name: tmp-pod, emptyDir: {medium: Memory}} - - { name: mysql, emptyDir: {medium: Memory}} - - { name: docker-socket, hostPath: { path: /var/run/docker.sock }} - - { name: docker-exec, hostPath: { path: /usr/bin/docker }} - restartPolicy: Never diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..d5b48b3f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +language: php + +php: + - 5.6 + - 7.0 + - 7.1 + +sudo: false + +cache: + directories: + - $HOME/.composer/cache/files + +before_install: + - phpenv config-rm xdebug.ini + - phpenv config-add travis.php.ini + - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config + - composer self-update --no-interaction + +install: + - composer require php-http/guzzle6-adapter + - composer install --prefer-dist --no-interaction + +script: + - bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php -vvv + - bin/phpspec run --no-interaction + - php -d error_reporting="E_ALL" bin/phpunit -c phpunit.xml.dist + +notifications: + email: false diff --git a/CHANGELOG-1.0.md b/CHANGELOG-1.0.md index 4ae13ff5..71579919 100644 --- a/CHANGELOG-1.0.md +++ b/CHANGELOG-1.0.md @@ -1,4 +1,10 @@ -# 2.0.1 (2018-04-05) +# 1.0.x + +## Bug Fixes + +- API-599: fix const not supported by PHP 5.6 + +# 1.0.1 (2018-04-05) ## Improvements diff --git a/README.md b/README.md index 02e6ac93..10639d6b 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,20 @@ $client->getProductApi()->upsertList([ ]); ``` +## Testing + +Do note that you have to delete the `composer.lock` because Doctrine dependencies are loaded. +These dependencies are different in function of the PHP version running `composer install`. + +``` +cp docker-compose.yml.dist docker-compose.yml +rm -rf composer.lock vendor/ +docker-compose run client_56 composer install +docker-compose run client_56 bin/phpunit -c phpunit.xml.dist +docker-compose run client_56 bin/phpspec run +docker-compose run client_56 bin/php-cs-fixer fix --diff --dry-run --config=.php_cs.php -vvv +``` + ## Support If you find a bug or want to submit an improvement, don't hesitate to raise an issue on Github. diff --git a/composer.json b/composer.json index 9519f9fe..4de97879 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,8 @@ "friendsofphp/php-cs-fixer": "^v2.3", "phpunit/phpunit": "5.7.*", "phpspec/phpspec": "3.2.*", - "symfony/yaml": "^3.3" + "symfony/yaml": "^3.3", + "donatj/mock-webserver": "^2.0" }, "config": { "bin-dir": "bin" diff --git a/docker-compose.yml.dist b/docker-compose.yml.dist index 59ffdcf8..2a80ee61 100644 --- a/docker-compose.yml.dist +++ b/docker-compose.yml.dist @@ -1,7 +1,37 @@ version: '2' services: - client: + client_56: + image: akeneo/php:5.6 + environment: + COMPOSER_HOME: /home/docker/.composer + PHP_IDE_CONFIG: 'serverName=akeneo-client' + PHP_XDEBUG_ENABLED: 0 + PHP_XDEBUG_IDE_KEY: XDEBUG_IDE_KEY + PHP_XDEBUG_REMOTE_HOST: xxx.xxx.xxx.xxx + XDEBUG_CONFIG: 'remote_host=xxx.xxx.xxx.xxx' + user: docker + volumes: + - ./:/home/docker/client + - ~/.composer:/home/docker/.composer + working_dir: /home/docker/client + + client_70: + image: akeneo/php:7.0 + environment: + COMPOSER_HOME: /home/docker/.composer + PHP_IDE_CONFIG: 'serverName=akeneo-client' + PHP_XDEBUG_ENABLED: 0 + PHP_XDEBUG_IDE_KEY: XDEBUG_IDE_KEY + PHP_XDEBUG_REMOTE_HOST: xxx.xxx.xxx.xxx + XDEBUG_CONFIG: 'remote_host=xxx.xxx.xxx.xxx' + user: docker + volumes: + - ./:/home/docker/client + - ~/.composer:/home/docker/.composer + working_dir: /home/docker/client + + client_71: image: akeneo/php:7.1 environment: COMPOSER_HOME: /home/docker/.composer @@ -14,13 +44,5 @@ services: volumes: - ./:/home/docker/client - ~/.composer:/home/docker/.composer - - /var/run/docker.sock:/var/run/docker.sock - - /usr/bin/docker:/usr/bin/docker working_dir: /home/docker/client - networks: - - client -networks: - default: - external: - name: your-pim-network # Replace with the Docker network your PIM is on diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 774edcf0..adb60ede 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,17 +12,6 @@ syntaxCheck="false"> - tests/ + tests/ - - - tests/Common/Api/* - tests/v1_7/Api/* - - - - tests/Common/Api/* - tests/v2_0/Api/* - - diff --git a/spec/Search/SearchBuilderSpec.php b/spec/Search/SearchBuilderSpec.php index ec32731b..d7de00db 100644 --- a/spec/Search/SearchBuilderSpec.php +++ b/spec/Search/SearchBuilderSpec.php @@ -31,13 +31,13 @@ function it_builds_a_search_with_a_single_filter_without_options() function it_builds_a_search_with_a_single_filter_without_value_nor_option() { - $this->addFilter('family' , Operator::EMPTY)->shouldReturn($this); + $this->addFilter('family' , Operator::IS_EMPTY)->shouldReturn($this); $this->getFilters()->shouldReturn( [ 'family'=> [ [ - 'operator' => Operator::EMPTY, + 'operator' => Operator::IS_EMPTY, ] ] ] diff --git a/src/Search/Operator.php b/src/Search/Operator.php index 1e63eb26..db982e71 100644 --- a/src/Search/Operator.php +++ b/src/Search/Operator.php @@ -27,7 +27,7 @@ final class Operator const GREATER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'GREATER OR EQUALS THAN ON ALL LOCALES'; const LOWER_THAN_ON_ALL_LOCALES = 'LOWER THAN ON ALL LOCALES'; const LOWER_OR_EQUALS_THAN_ON_ALL_LOCALES = 'LOWER OR EQUALS THAN ON ALL LOCALES'; - const EMPTY = 'EMPTY'; + const IS_EMPTY = 'EMPTY'; const NOT_EMPTY = 'NOT EMPTY'; const BETWEEN = 'BETWEEN'; const NOT_BETWEEN = 'NOT BETWEEN'; diff --git a/tests/Api/ApiTestCase.php b/tests/Api/ApiTestCase.php new file mode 100644 index 00000000..f38f7967 --- /dev/null +++ b/tests/Api/ApiTestCase.php @@ -0,0 +1,70 @@ + + * @copyright 2017 Akeneo SAS (http://www.akeneo.com) + * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) + */ +abstract class ApiTestCase extends \PHPUnit_Framework_TestCase +{ + /** @var MockWebServer */ + protected $server; + + /** + * {@inheritdoc} + */ + protected function setUp() + { + $this->server = new MockWebServer(8081, '127.0.0.1'); + $this->server->start(); + + $this->server->setResponseOfPath( + '/'. AuthenticationApi::TOKEN_URI, + new ResponseStack( + new Response($this->getAuthenticatedJson()) + ) + ); + } + + /** + * {@inheritdoc} + */ + protected function tearDown() + { + $this->server->stop(); + } + + /** + * @return AkeneoPimClientInterface + */ + protected function createClient() + { + $clientBuilder = new AkeneoPimClientBuilder($this->server->getServerRoot()); + + return $clientBuilder->buildAuthenticatedByPassword( + 'client_id', + 'secret', + 'username', + 'password' + ); + } + + private function getAuthenticatedJson() + { + return <<server->getServerRoot(). '/' . ProductMediaFileApi::MEDIA_FILES_URI.'/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'; + $this->server->setResponseOfPath( + '/'. ProductMediaFileApi::MEDIA_FILES_URI, + new ResponseStack( + new Response('', ['Location' => $mediaFileURI], 201) + ) + ); + + $api = $this->createClient()->getProductMediaFileApi(); + $mediaFile = realpath(__DIR__ . '/../fixtures/akeneo.png'); + + $productInfos = [ + 'identifier' => 'medium_boot', + 'attribute' => 'side_view', + 'scope' => null, + 'locale' => null, + ]; + + $response = $api->create($mediaFile, $productInfos); + + $lastRequest = $this->server->getLastRequest()->jsonSerialize(); + Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_POST]['product'], json_encode($productInfos)); + Assert::assertNotEmpty($lastRequest[RequestInfo::JSON_KEY_FILES]['file']); + Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_FILES]['file']['name'], 'akeneo.png'); + Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_FILES]['file']['type'], 'image/png'); + Assert::assertSame($lastRequest[RequestInfo::JSON_KEY_FILES]['file']['size'], 8073); + + Assert::assertSame('f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png', $response); + } +} diff --git a/tests/Api/CreateProductTest.php b/tests/Api/CreateProductTest.php new file mode 100644 index 00000000..9546035a --- /dev/null +++ b/tests/Api/CreateProductTest.php @@ -0,0 +1,93 @@ +server->setResponseOfPath( + '/'. ProductApi::PRODUCTS_URI, + new ResponseStack( + new Response('', [], 201) + ) + ); + + $api = $this->createClient()->getProductApi(); + $response = $api->create('new_shoes', $this->newProduct()); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($this->expectedProduct())); + + Assert::assertSame(201, $response); + } + + /** + * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException + * @expectedExceptionMessage The value black_sneakers is already set on another product for the unique attribute sku + */ + public function test_create_invalid_product() + { + $this->server->setResponseOfPath( + '/'. ProductApi::PRODUCTS_URI, + new ResponseStack( + new Response('{"code": 422, "message":"The value black_sneakers is already set on another product for the unique attribute sku"}', [], 422) + ) + ); + + $api = $this->createClient()->getProductApi(); + $api->create('black_sneakers', $this->newProduct()); + } + + private function newProduct() + { + return [ + 'enabled' => false, + 'family' => 'sandals', + 'categories' => ['summer_collection'], + 'values' => [ + 'name' => [ + [ + 'data' => 'The pumps', + 'locale' => 'en_US', + 'scope' => null, + ], + [ + 'data' => 'Les pumps', + 'locale' => 'fr_FR', + 'scope' => null, + ] + ] + ] + ]; + } + + private function expectedProduct() + { + return [ + 'enabled' => false, + 'family' => 'sandals', + 'categories' => ['summer_collection'], + 'values' => [ + 'name' => [ + [ + 'data' => 'The pumps', + 'locale' => 'en_US', + 'scope' => null, + ], + [ + 'data' => 'Les pumps', + 'locale' => 'fr_FR', + 'scope' => null, + ] + ] + ], + 'identifier' => 'new_shoes' + ]; + } +} diff --git a/tests/Api/DeleteProductTest.php b/tests/Api/DeleteProductTest.php new file mode 100644 index 00000000..c828651b --- /dev/null +++ b/tests/Api/DeleteProductTest.php @@ -0,0 +1,29 @@ +server->setResponseOfPath( + '/'. sprintf(ProductApi::PRODUCT_URI, 'docks_white'), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $api = $this->createClient()->getProductApi(); + + $response = $api->delete('docks_white'); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'DELETE'); + Assert::assertSame(204, $response); + } +} diff --git a/tests/Api/DownloadProductMediaFileTest.php b/tests/Api/DownloadProductMediaFileTest.php new file mode 100644 index 00000000..2b13d1b7 --- /dev/null +++ b/tests/Api/DownloadProductMediaFileTest.php @@ -0,0 +1,32 @@ +server->setResponseOfPath( + '/'. sprintf(ProductMediaFileApi::MEDIA_FILE_DOWNLOAD_URI, '/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'), + new ResponseStack( + new Response(file_get_contents($expectedMediaFilePath), [], 201) + ) + ); + + $api = $this->createClient()->getProductMediaFileApi(); + $mediaFile = $api->download('/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png'); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET'); + Assert::assertInstanceOf(StreamInterface::class, $mediaFile); + Assert::assertSame(file_get_contents($expectedMediaFilePath), $mediaFile->getContents()); + } +} diff --git a/tests/Api/GetProductTest.php b/tests/Api/GetProductTest.php new file mode 100644 index 00000000..005ac651 --- /dev/null +++ b/tests/Api/GetProductTest.php @@ -0,0 +1,63 @@ +server->setResponseOfPath( + '/'. sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), + new ResponseStack( + new Response($this->getProduct(), [], 200) + ) + ); + + $api = $this->createClient()->getProductApi(); + + $product = $api->get('black_sneakers'); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_METHOD], 'GET'); + Assert::assertEquals($product, json_decode($this->getProduct(), true)); + } + + /** + * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException + * @expectedExceptionMessage Resource `black_sneakers` does not exist. + */ + public function test_get_unknow_product() + { + $this->server->setResponseOfPath( + '/'. sprintf(ProductApi::PRODUCT_URI, 'black_sneakers'), + new ResponseStack( + new Response('{"code": 404, "message":"Resource `black_sneakers` does not exist."}', [], 404) + ) + ); + + $api = $this->createClient()->getProductApi(); + $api->get('black_sneakers'); + } + + private function getProduct() + { + return <<server->setResponseOfPath( + '/'. ProductApi::PRODUCTS_URI, + new ResponseStack( + new Response($this->getFirstPage(), [], 200), + new Response($this->getSecondPage(), [], 200) + ) + ); + + $api = $this->createClient()->getProductApi(); + $firstPage = $api->listPerPage(10, true, []); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_GET], ['limit' => '10', 'with_count' => 'true']); + + Assert::assertInstanceOf(PageInterface::class, $firstPage); + Assert::assertEquals($firstPage->getCount(), 11); + Assert::assertNull($firstPage->getPreviousLink()); + Assert::assertNull($firstPage->getPreviousPage()); + Assert::assertFalse($firstPage->hasPreviousPage()); + Assert::assertTrue($firstPage->hasNextPage()); + Assert::assertSame($this->server->getServerRoot() . '/api/rest/v1/products?page=2&with_count=true&pagination_type=page&limit=10', $firstPage->getNextLink()); + Assert::assertEquals(count($firstPage->getItems()), 10); + + $secondPage = $firstPage->getNextPage(); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_GET], [ + 'page' => '2', + 'with_count' => 'true', + 'pagination_type' => 'page', + 'limit' => '10' + ]); + + Assert::assertInstanceOf(PageInterface::class, $secondPage); + Assert::assertEquals($secondPage->getCount(), 11); + Assert::assertNull($secondPage->getNextLink()); + Assert::assertNull($secondPage->getNextPage()); + Assert::assertFalse($secondPage->hasNextPage()); + Assert::assertTrue($secondPage->hasPreviousPage()); + Assert::assertSame($this->server->getServerRoot() . '/api/rest/v1/products?page=1&with_count=true&pagination_type=page&limit=10', $secondPage->getPreviousLink()); + Assert::assertEquals(count($secondPage->getItems()), 1); + } + + private function getFirstPage() + { + $baseUri = $this->server->getServerRoot(); + + return <<server->getServerRoot(); + + return <<server->setResponseOfPath( + '/'. ProductApi::PRODUCTS_URI, + new ResponseStack( + new Response($this->getResults(), [], 200) + ) + ); + } + + public function test_upsert_list() { $api = $this->createClient()->getProductApi(); + $response = $api->upsertList($this->getProductToUpsert()); - $response = $api->upsertList([ - [ - 'identifier' => 'docks_black', - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', - ], - ], - ] - ], - [ - 'identifier' => 'pumps', - 'enabled' => false, - 'family' => 'sandals', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'data' => 'The pumps', - 'locale' => 'en_US', - 'scope' => null, - ], - [ - 'data' => 'Les pumps', - 'locale' => 'fr_FR', - 'scope' => null, - ] - ], - ] - ] - ]); + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], $this->getProductToUpsertJson()); - $this->assertInstanceOf('\Iterator', $response); + Assert::assertInstanceOf('\Iterator', $response); $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); + Assert::assertCount(2, $responseLines); - $this->assertSame([ + Assert::assertSame([ 'line' => 1, 'identifier' => 'docks_black', 'status_code' => 204, ], $responseLines[1]); - $this->assertSame([ + Assert::assertSame([ 'line' => 2, 'identifier' => 'pumps', 'status_code' => 201, ], $responseLines[2]); } - public function testUpsertListFromStreamSuccessful() + public function test_upsert_list_from_stream() { - $resourcesContent = -<<getProductToUpsertJson()); rewind($resources); - $streamedResources = $this->getStreamFactory()->createStream($resources); + $streamedResources = StreamFactoryDiscovery::find()->createStream($resources); $api = $this->createClient()->getProductAPi(); $response = $api->upsertList($streamedResources); - $this->assertInstanceOf('\Iterator', $response); + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], $this->getProductToUpsertJson()); + + Assert::assertInstanceOf('\Iterator', $response); $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); + Assert::assertCount(2, $responseLines); - $this->assertSame([ + Assert::assertSame([ 'line' => 1, 'identifier' => 'docks_black', 'status_code' => 204, ], $responseLines[1]); - $this->assertSame([ + Assert::assertSame([ 'line' => 2, 'identifier' => 'pumps', 'status_code' => 201, ], $responseLines[2]); } - public function testUpsertListFailed() - { - $api = $this->createClient()->getProductApi(); + private function getProductToUpsertJson(){ + return <<upsertList([ + private function getProductToUpsert(){ + return [ [ + 'identifier' => 'docks_black', 'enabled' => false, 'values' => [ 'name' => [ @@ -120,30 +107,27 @@ public function testUpsertListFailed() 'values' => [ 'name' => [ [ - 'data' => 'line too long' . str_repeat('a', 1000000), + 'data' => 'The pumps', 'locale' => 'en_US', 'scope' => null, + ], + [ + 'data' => 'Les pumps', + 'locale' => 'fr_FR', + 'scope' => null, ] ], ] ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Identifier is missing.', - ], $responseLines[1]); + ]; + } - $this->assertSame([ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ], $responseLines[2]); + private function getResults() + { + return <<server->setResponseOfPath( + '/'. sprintf(ProductApi::PRODUCT_URI, 'docks_black'), + new ResponseStack( + new Response('', [], 204) + ) + ); + + $api = $this->createClient()->getProductApi(); + + $parameters = [ + 'enabled' => false, + 'values' => [ + 'name' => [ + [ + 'locale' => 'en_US', + 'scope' => null, + 'data' => 'Black Docks', + ], + ], + ] + ]; + $response = $api->upsert('docks_black', $parameters); + + Assert::assertSame($this->server->getLastRequest()->jsonSerialize()[RequestInfo::JSON_KEY_INPUT], json_encode($parameters)); + + Assert::assertSame(204, $response); + } + +} diff --git a/tests/Common/Api/ApiTestCase.php b/tests/Common/Api/ApiTestCase.php deleted file mode 100644 index 7c61e16d..00000000 --- a/tests/Common/Api/ApiTestCase.php +++ /dev/null @@ -1,193 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -abstract class ApiTestCase extends \PHPUnit_Framework_TestCase -{ - /** @var array */ - private $configuration; - - /** @var ConsoleCommandLauncher */ - private $consoleCommandLauncher; - - /** - * {@inheritdoc} - */ - protected function setUp() - { - $this->configuration = $this->parseConfigurationFile(); - $this->consoleCommandLauncher = new ConsoleCommandLauncher($this->getConfiguration()); - - $installer = new DatabaseInstaller($this->getCommandLauncher()); - $installer->install(); - } - - /** - * @return StreamFactory - */ - protected function getStreamFactory() - { - return StreamFactoryDiscovery::find(); - } - - /** - * @param string $username - * @param string $password - * - * @return AkeneoPimClientInterface - */ - protected function createClient($username = 'admin', $password = 'admin') - { - $config = $this->getConfiguration(); - $generator = new CredentialGenerator($this->getCommandLauncher()); - - $credentials = $generator->generate($config['pim']['version']); - $clientBuilder = new AkeneoPimClientBuilder($config['pim']['base_uri']); - - return $clientBuilder->buildAuthenticatedByPassword( - $credentials['client_id'], - $credentials['secret'], - $username, - $password - ); - } - - /** - * @return ConsoleCommandLauncher - */ - protected function getCommandLauncher() - { - return $this->consoleCommandLauncher; - } - - /** - * @return array - */ - protected function getConfiguration() - { - return $this->configuration; - } - - /** - * Assert that all the expected data of a content of a resource are the same - * in an actual one. - * An associative array can contain more elements than expected, but an - * numeric key array must be strictly identical. - * - * @param array $expectedContent - * @param array $actualContent - */ - protected function assertSameContent(array $expectedContent, array $actualContent) - { - $expectedContent = $this->sortResourceContent($expectedContent); - $actualContent = $this->sortResourceContent($actualContent); - - $expectedContent = $this->mergeResourceContents($actualContent, $expectedContent); - - $this->assertSame($expectedContent, $actualContent); - } - - /** - * @return string - */ - protected function getConfigurationFile() - { - return realpath(dirname(__FILE__)).'/../../../tests/etc/parameters.yml'; - } - - /** - * @throws \RuntimeException - * - * @return array - */ - private function parseConfigurationFile() - { - $configFile = $this->getConfigurationFile(); - if (!is_file($configFile)) { - throw new \RuntimeException('The configuration file parameters.yml is missing'); - } - - $config = Yaml::parse(file_get_contents($configFile)); - - return $config; - } - - /** - * Recursively merge an expected content in a actual one to be able to compare them. - * Numeric key arrays are kept identical. - * - * @param array $actualContent - * @param array $expectedContent - * - * @return array - */ - private function mergeResourceContents(array $actualContent, array $expectedContent) - { - foreach ($expectedContent as $key => $value) { - if (is_array($value) && isset($actualContent[$key]) && is_array($actualContent[$key])) { - $expectedContent[$key] = $this->mergeResourceContents($actualContent[$key], $expectedContent[$key]); - } - } - - if ($this->isAssociativeArray($expectedContent)) { - $mergedContent = array_merge($actualContent, $expectedContent); - } else { - $mergedContent = $expectedContent; - } - - return $mergedContent; - } - - /** - * @param array $array - * - * @return bool True if the array is associative (i.e. at least one key is a string) - */ - private function isAssociativeArray(array $array) - { - foreach (array_keys($array) as $key) { - if (is_string($key)) { - return true; - } - } - - return false; - } - - /** - * Sort a resource content to be able to compare it with another one. - * The order of elements in an associative array is important in PHPUnit but not for us. - * So we force the order of the associative arrays to be identical to be able to use them in a PHPUnit assertion. - * This sort has no consequences for sequential arrays with numeric keys. - * - * @param array $resourceContent - * - * @return array Sorted resource content - */ - private function sortResourceContent(array $resourceContent) - { - ksort($resourceContent); - - foreach ($resourceContent as $key => $value) { - if (is_array($value)) { - $resourceContent[$key] = $this->sortResourceContent($value); - } - } - - return $resourceContent; - } -} diff --git a/tests/Common/Api/Attribute/CreateAttributeIntegration.php b/tests/Common/Api/Attribute/CreateAttributeIntegration.php deleted file mode 100644 index ecbe20cf..00000000 --- a/tests/Common/Api/Attribute/CreateAttributeIntegration.php +++ /dev/null @@ -1,117 +0,0 @@ -createClient()->getAttributeApi(); - $response = $api->create('comment', [ - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ]); - - $this->assertSame(201, $response); - - $attribute = $api->get('comment'); - $this->assertSameContent([ - 'code' => 'comment', - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 0, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ], $attribute); - } - - public function testCreateAnExistingAttribute() - { - $api = $this->createClient()->getAttributeApi(); - - try { - $api->create('name', [ - 'type' => 'pim_catalog_text', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'sort_order' => 2, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Name', - ], - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame([ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], $exception->getResponseErrors()); - } - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidAttribute() - { - $api = $this->createClient()->getAttributeApi(); - $api->create('fail', [ - 'type' => 'unknown_type', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ]); - } -} diff --git a/tests/Common/Api/Attribute/GetAttributeIntegration.php b/tests/Common/Api/Attribute/GetAttributeIntegration.php deleted file mode 100644 index 06e4a907..00000000 --- a/tests/Common/Api/Attribute/GetAttributeIntegration.php +++ /dev/null @@ -1,57 +0,0 @@ -createClient()->getAttributeApi(); - - $attribute = $api->get('length'); - - $this->assertSameContent([ - 'code' => 'length', - 'type' => 'pim_catalog_metric', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'allowed_extensions' => [], - 'metric_family' => 'Length', - 'default_metric_unit' => 'CENTIMETER', - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => false, - 'negative_allowed' => false, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 10, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Length', - 'fr_FR' => 'Longueur', - ], - ], $attribute); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getAttributeApi(); - - $api->get('unknown'); - } -} diff --git a/tests/Common/Api/Attribute/ListAttributeIntegration.php b/tests/Common/Api/Attribute/ListAttributeIntegration.php deleted file mode 100644 index 24eeec96..00000000 --- a/tests/Common/Api/Attribute/ListAttributeIntegration.php +++ /dev/null @@ -1,659 +0,0 @@ -createClient()->getAttributeApi(); - $expectedAttributes = $this->getExpectedAttributes(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(7); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attributes?page=2&limit=7&with_count=false', $firstPage->getNextLink()); - - $attributes = $firstPage->getItems(); - $this->assertCount(7 ,$attributes); - for ($i = 0; $i < 7; $i++) { - $this->assertSameContent($expectedAttributes[$i], $attributes[$i]); - } - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attributes?page=1&limit=7&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/attributes?page=3&limit=7&with_count=false', $secondPage->getNextLink()); - - $attributes = $secondPage->getItems(); - $this->assertCount(7 ,$attributes); - for ($i = 0; $i < 7; $i++) { - $this->assertSameContent($expectedAttributes[7 + $i], $attributes[$i]); - } - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/attributes?page=2&limit=7&with_count=false', $lastPage->getPreviousLink()); - - $attributes = $lastPage->getItems(); - $this->assertCount(1 ,$attributes); - $this->assertSameContent($expectedAttributes[14], $attributes[0]); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSameContent($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getAttributeApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(5, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(15, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/attributes?page=2&limit=5&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getAttributeApi(); - $expectedAttributes = $this->getExpectedAttributes(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/attributes?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $attributes = $firstPage->getItems(); - $this->assertCount(2 ,$attributes); - $this->assertSameContent($expectedAttributes[0], $attributes[0]); - $this->assertSameContent($expectedAttributes[1], $attributes[1]); - } - - public function testAll() - { - $api = $this->createClient()->getAttributeApi(); - $attributes = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $attributes); - - $attributes = iterator_to_array($attributes); - - $this->assertCount(15, $attributes); - $this->assertSameContent($this->getExpectedAttributes(), $attributes); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getAttributeApi(); - $attributes = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $attributes); - - $attributes = iterator_to_array($attributes); - - $this->assertCount(15, $attributes); - $this->assertSameContent($this->getExpectedAttributes(), $attributes); - } - - /** - * @return array - */ - protected function getExpectedAttributes() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/color', - ], - ], - 'code' => 'color', - 'type' => 'pim_catalog_simpleselect', - 'group' => 'colors', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 9, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Color', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/description', - ], - ], - 'code' => 'description', - 'type' => 'pim_catalog_textarea', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => 1000, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 5, - 'localizable' => true, - 'scopable' => true, - 'labels' => [ - 'en_US' => 'Description', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/destocking_date', - ], - ], - 'code' => 'destocking_date', - 'type' => 'pim_catalog_date', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 12, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Destocking date', - 'fr_FR' => 'Date de déstockage', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/handmade', - ], - ], - 'code' => 'handmade', - 'type' => 'pim_catalog_boolean', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 13, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Handmade', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/heel_color', - ], - ], - 'code' => 'heel_color', - 'type' => 'pim_reference_data_simpleselect', - 'group' => 'colors', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => 'color', - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 14, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Heel color', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/length', - ], - ], - 'code' => 'length', - 'type' => 'pim_catalog_metric', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'allowed_extensions' => [], - 'metric_family' => 'Length', - 'default_metric_unit' => 'CENTIMETER', - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => false, - 'negative_allowed' => false, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 10, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Length', - 'fr_FR' => 'Longueur', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/manufacturer', - ], - ], - 'code' => 'manufacturer', - 'type' => 'pim_catalog_simpleselect', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 3, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Manufacturer', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/name', - ], - ], - 'code' => 'name', - 'type' => 'pim_catalog_text', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 2, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Name', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/number_in_stock', - ], - ], - 'code' => 'number_in_stock', - 'type' => 'pim_catalog_number', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => false, - 'negative_allowed' => false, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 11, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Number in stock', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/price', - ], - ], - 'code' => 'price', - 'type' => 'pim_catalog_price_collection', - 'group' => 'marketing', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => '1.0000', - 'number_max' => '200.0000', - 'decimals_allowed' => true, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 6, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Price', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/side_view', - ], - ], - 'code' => 'side_view', - 'type' => 'pim_catalog_image', - 'group' => 'media', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'allowed_extensions' => [ - 'gif', - 'png', - 'jpeg', - 'jpg', - ], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => '1.00', - 'minimum_input_length' => null, - 'sort_order' => 7, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Side view', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/size', - ], - ], - 'code' => 'size', - 'type' => 'pim_catalog_simpleselect', - 'group' => 'sizes', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 8, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Size', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/sku', - ], - ], - 'code' => 'sku', - 'type' => 'pim_catalog_identifier', - 'group' => 'info', - 'unique' => true, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 1, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'SKU', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/sole_color', - ], - ], - 'code' => 'sole_color', - 'type' => 'pim_reference_data_simpleselect', - 'group' => 'colors', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => 'color', - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 15, - 'localizable' => false, - 'scopable' => true, - 'labels' => [ - 'en_US' => 'Sole color', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/weather_conditions', - ], - ], - 'code' => 'weather_conditions', - 'type' => 'pim_catalog_multiselect', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 4, - 'localizable' => false, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Weather conditions', - ], - ], - - ]; - } -} diff --git a/tests/Common/Api/Attribute/UpsertAttributeIntegration.php b/tests/Common/Api/Attribute/UpsertAttributeIntegration.php deleted file mode 100644 index 41909339..00000000 --- a/tests/Common/Api/Attribute/UpsertAttributeIntegration.php +++ /dev/null @@ -1,144 +0,0 @@ -createClient()->getAttributeApi(); - - $response = $api->upsert('name', [ - 'max_characters' => 42, - 'labels' => [ - 'fr_FR' => 'Nom', - ], - ]); - - $this->assertSame(204, $response); - - $attribute = $api->get('name'); - $this->assertSameContent([ - 'code' => 'name', - 'type' => 'pim_catalog_text', - 'group' => 'info', - 'unique' => false, - 'useable_as_grid_filter' => true, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => 42, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 2, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Name', - 'fr_FR' => 'Nom', - ], - ], $attribute); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getAttributeApi(); - $response = $api->upsert('comment', [ - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ]); - - $this->assertSame(201, $response); - - $attribute = $api->get('comment'); - $this->assertSameContent([ - 'code' => 'comment', - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'allowed_extensions' => [], - 'metric_family' => null, - 'default_metric_unit' => null, - 'reference_data_name' => null, - 'available_locales' => [], - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'wysiwyg_enabled' => null, - 'number_min' => null, - 'number_max' => null, - 'decimals_allowed' => null, - 'negative_allowed' => null, - 'date_min' => null, - 'date_max' => null, - 'max_file_size' => null, - 'minimum_input_length' => null, - 'sort_order' => 0, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ], $attribute); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getAttributeApi(); - $api->upsert('name', [ - 'max_characters' => false, - 'labels' => [ - 'fr_FR' => [], - ], - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getAttributeApi(); - $api->upsert('invalid code !', [ - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'useable_as_grid_filter' => false, - 'max_characters' => null, - 'validation_rule' => null, - 'validation_regexp' => null, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ]); - } -} diff --git a/tests/Common/Api/Attribute/UpsertListAttributeIntegration.php b/tests/Common/Api/Attribute/UpsertListAttributeIntegration.php deleted file mode 100644 index 04d96184..00000000 --- a/tests/Common/Api/Attribute/UpsertListAttributeIntegration.php +++ /dev/null @@ -1,89 +0,0 @@ -createClient()->getAttributeApi(); - - $response = $api->upsertList([ - [ - 'code' => 'name', - 'max_characters' => 42, - 'useable_as_grid_filter' => true, - ], - [ - 'code' => 'comment', - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'Comment', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'code' => 'name', - 'status_code' => 204, - ], $responseLines[1]); - - $this->assertSame([ - 'line' => 2, - 'code' => 'comment', - 'status_code' => 201, - ], $responseLines[2]); - } - - public function testUpsertListFailed() - { - $api = $this->createClient()->getAttributeApi(); - - $response = $api->upsertList([ - [ - 'max_characters' => 42, - 'useable_as_grid_filter' => true, - ], - [ - 'code' => 'comment', - 'type' => 'pim_catalog_text', - 'group' => 'other', - 'unique' => false, - 'localizable' => true, - 'scopable' => false, - 'labels' => [ - 'en_US' => 'line too long' . str_repeat('a', 1000000), - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Code is missing.', - ], $responseLines[1]); - - $this->assertSame([ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ], $responseLines[2]); - } -} diff --git a/tests/Common/Api/AttributeOption/CreateAttributeOptionIntegration.php b/tests/Common/Api/AttributeOption/CreateAttributeOptionIntegration.php deleted file mode 100644 index 94143ebe..00000000 --- a/tests/Common/Api/AttributeOption/CreateAttributeOptionIntegration.php +++ /dev/null @@ -1,81 +0,0 @@ -createClient()->getAttributeOptionApi(); - $response = $api->create('color', 'yellow', [ - 'sort_order' => 9, - 'labels' => [ - 'en_US' => 'Yellow', - ], - ]); - - $this->assertSame(201, $response); - - $attributeOption = $api->get('color', 'yellow'); - $this->assertSameContent([ - 'code' => 'yellow', - 'attribute' => 'color', - 'sort_order' => 9, - 'labels' => [ - 'en_US' => 'Yellow', - ], - ], $attributeOption); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testCreateOnAnUnknownAttribute() - { - $api = $this->createClient()->getAttributeOptionApi(); - $api->create('foo', 'bar', [ - 'sort_order' => 42, - 'labels' => [ - 'en_US' => 'FooBar', - ], - ]); - } - - public function testCreateAnExistingAttributeOption() - { - $api = $this->createClient()->getAttributeOptionApi(); - - try { - $api->create('color', 'black', [ - 'sort_order' => 2, - 'labels' => [ - 'en_US' => 'Black', - ], - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame([ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], $exception->getResponseErrors()); - } - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidAttributeOption() - { - $api = $this->createClient()->getAttributeOptionApi(); - $api->create('color', 'yellow', [ - 'sort_order' => 9, - 'labels' => [ - 'en_US' => ['invalid type'], - ], - ]); - } -} diff --git a/tests/Common/Api/AttributeOption/GetAttributeOptionIntegration.php b/tests/Common/Api/AttributeOption/GetAttributeOptionIntegration.php deleted file mode 100644 index 2a51e1c5..00000000 --- a/tests/Common/Api/AttributeOption/GetAttributeOptionIntegration.php +++ /dev/null @@ -1,34 +0,0 @@ -createClient()->getAttributeOptionApi(); - - $attributeOption = $api->get('weather_conditions', 'hot'); - - $this->assertSameContent([ - 'code' => 'hot', - 'attribute' => 'weather_conditions', - 'sort_order' => 3, - 'labels' => [ - 'en_US' => 'Hot', - ] - ], $attributeOption); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getAttributeOptionApi(); - - $api->get('weather_conditions', 'unknown'); - } -} diff --git a/tests/Common/Api/AttributeOption/ListAttributeOptionIntegration.php b/tests/Common/Api/AttributeOption/ListAttributeOptionIntegration.php deleted file mode 100644 index b9b4ba81..00000000 --- a/tests/Common/Api/AttributeOption/ListAttributeOptionIntegration.php +++ /dev/null @@ -1,199 +0,0 @@ -createClient()->getAttributeOptionApi(); - $expectedAttributeOptions = $this->getExpectedAttributeOptions(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage('weather_conditions', 2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attributes/weather_conditions/options?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $attributeOptions = $firstPage->getItems(); - $this->assertCount(2 ,$attributeOptions); - $this->assertSameContent($expectedAttributeOptions[0], $attributeOptions[0]); - $this->assertSameContent($expectedAttributeOptions[1], $attributeOptions[1]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attributes/weather_conditions/options?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/attributes/weather_conditions/options?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $attributeOptions = $secondPage->getItems(); - $this->assertCount(2 ,$attributeOptions); - $this->assertSameContent($expectedAttributeOptions[2], $attributeOptions[0]); - $this->assertSameContent($expectedAttributeOptions[3], $attributeOptions[1]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/attributes/weather_conditions/options?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - - $attributeOptions = $lastPage->getItems(); - $this->assertCount(1 ,$attributeOptions); - $this->assertSameContent($expectedAttributeOptions[4], $attributeOptions[0]); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getAttributeOptionApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage('weather_conditions',2, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(5, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/attributes/weather_conditions/options?page=2&limit=2&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getAttributeOptionApi(); - $expectedAttributeOptions = $this->getExpectedAttributeOptions(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage('weather_conditions',2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/attributes/weather_conditions/options?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $attributeOptions = $firstPage->getItems(); - $this->assertCount(2 ,$attributeOptions); - $this->assertSameContent($expectedAttributeOptions[0], $attributeOptions[0]); - $this->assertSameContent($expectedAttributeOptions[1], $attributeOptions[1]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testListPerPageOnAnUnknownAttribute() - { - $api = $this->createClient()->getAttributeOptionApi(); - - $api->listPerPage('unknown_attribute'); - } - - public function testAll() - { - $api = $this->createClient()->getAttributeOptionApi(); - $attributeOptions = $api->all('weather_conditions'); - - $this->assertInstanceOf(ResourceCursorInterface::class, $attributeOptions); - - $attributeOptions = iterator_to_array($attributeOptions); - - $this->assertCount(5, $attributeOptions); - $this->assertSameContent($this->getExpectedAttributeOptions(), $attributeOptions); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getAttributeOptionApi(); - $attributeOptions = $api->all('weather_conditions', 10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $attributeOptions); - - $attributeOptions = iterator_to_array($attributeOptions); - - $this->assertCount(5, $attributeOptions); - $this->assertSameContent($this->getExpectedAttributeOptions(), $attributeOptions); - } - - /** - * @return array - */ - protected function getExpectedAttributeOptions() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/weather_conditions/options/cold', - ], - ], - 'code' => 'cold', - 'attribute' => 'weather_conditions', - 'sort_order' => 4, - 'labels' => [ - 'en_US' => 'Cold', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/weather_conditions/options/dry', - ], - ], - 'code' => 'dry', - 'attribute' => 'weather_conditions', - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Dry', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/weather_conditions/options/hot', - ], - ], - 'code' => 'hot', - 'attribute' => 'weather_conditions', - 'sort_order' => 3, - 'labels' => [ - 'en_US' => 'Hot', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/weather_conditions/options/snowy', - ], - ], - 'code' => 'snowy', - 'attribute' => 'weather_conditions', - 'sort_order' => 5, - 'labels' => [ - 'en_US' => 'Snowy', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attributes/weather_conditions/options/wet', - ], - ], - 'code' => 'wet', - 'attribute' => 'weather_conditions', - 'sort_order' => 2, - 'labels' => [ - 'en_US' => 'Wet', - ], - ], - ]; - } -} diff --git a/tests/Common/Api/AttributeOption/UpsertAttributeOptionIntegration.php b/tests/Common/Api/AttributeOption/UpsertAttributeOptionIntegration.php deleted file mode 100644 index 111b85ae..00000000 --- a/tests/Common/Api/AttributeOption/UpsertAttributeOptionIntegration.php +++ /dev/null @@ -1,97 +0,0 @@ -createClient()->getAttributeOptionApi(); - - $response = $api->upsert('weather_conditions', 'hot', [ - 'sort_order' => 34, - 'labels' => [ - 'en_US' => 'Hot !', - ], - ]); - - $this->assertSame(204, $response); - - $attributeOption = $api->get('weather_conditions', 'hot'); - $this->assertSameContent([ - 'code' => 'hot', - 'attribute' => 'weather_conditions', - 'sort_order' => 34, - 'labels' => [ - 'en_US' => 'Hot !', - ], - ], $attributeOption); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getAttributeOptionApi(); - $response = $api->upsert('size', '45', [ - 'sort_order' => 9, - 'labels' => [ - 'en_US' => '45', - ], - ]); - - $this->assertSame(201, $response); - - $attributeOption = $api->get('size', '45'); - $this->assertSameContent([ - 'code' => '45', - 'attribute' => 'size', - 'sort_order' => 9, - 'labels' => [ - 'en_US' => '45', - ], - ], $attributeOption); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getAttributeOptionApi(); - $api->upsert('weather_conditions', 'hot', [ - 'sort_order' => 34, - 'labels' => [ - 'en_US' => ['invalid type'], - ], - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getAttributeOptionApi(); - $api->upsert('size', 'invalid code !', [ - 'sort_order' => 9, - 'labels' => [ - 'en_US' => '45', - ], - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testUpsertOnAnUnknownAttribute() - { - $api = $this->createClient()->getAttributeOptionApi(); - $api->upsert('unknown', 'hot', [ - 'sort_order' => 34, - 'labels' => [ - 'en_US' => 'Hot !', - ], - ]); - } -} diff --git a/tests/Common/Api/Category/CreateCategoryIntegration.php b/tests/Common/Api/Category/CreateCategoryIntegration.php deleted file mode 100644 index 776666bb..00000000 --- a/tests/Common/Api/Category/CreateCategoryIntegration.php +++ /dev/null @@ -1,69 +0,0 @@ -createClient()->getCategoryApi(); - $response = $api->create('pumps', [ - 'parent' => '2014_collection', - 'labels' => [ - 'en_US' => 'The Pumps', - 'fr_FR' => 'Les Pumps', - ], - ]); - - $this->assertSame(201, $response); - - $category = $api->get('pumps'); - $this->assertSameContent([ - 'code' => 'pumps', - 'parent' => '2014_collection', - 'labels' => [ - 'en_US' => 'The Pumps', - 'fr_FR' => 'Les Pumps', - ], - ], $category); - } - - public function testCreateAnExistingCategory() - { - $api = $this->createClient()->getCategoryApi(); - - try { - $api->create('summer_collection', [ - 'parent' => '2014_collection', - 'labels' => [ - 'en_US' => 'Summer collection', - 'fr_FR' => 'Collection été', - ], - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame([ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], $exception->getResponseErrors()); - } - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidCategory() - { - $api = $this->createClient()->getCategoryApi(); - $api->create('fail', [ - 'parent' => 'unknown parent', - 'labels' => [ - 'en_US' => 'fail', - ], - ]); - } -} diff --git a/tests/Common/Api/Category/GetCategoryIntegration.php b/tests/Common/Api/Category/GetCategoryIntegration.php deleted file mode 100644 index b96ffa5c..00000000 --- a/tests/Common/Api/Category/GetCategoryIntegration.php +++ /dev/null @@ -1,34 +0,0 @@ -createClient()->getCategoryApi(); - - $category = $api->get('sandals'); - - $this->assertSameContent([ - 'code' => 'sandals', - 'parent' => 'summer_collection', - 'labels' => [ - 'en_US' => 'Sandals', - 'fr_FR' => 'Sandales', - ], - ], $category); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getCategoryApi(); - - $api->get('pumps'); - } -} diff --git a/tests/Common/Api/Category/ListCategoryIntegration.php b/tests/Common/Api/Category/ListCategoryIntegration.php deleted file mode 100644 index ee281325..00000000 --- a/tests/Common/Api/Category/ListCategoryIntegration.php +++ /dev/null @@ -1,189 +0,0 @@ -createClient()->getCategoryApi(); - $expectedCategories = $this->getExpectedCategories(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/categories?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $categories = $firstPage->getItems(); - $this->assertCount(2 ,$categories); - $this->assertSameContent($expectedCategories[0], $categories[0]); - $this->assertSameContent($expectedCategories[1], $categories[1]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/categories?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/categories?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $categories = $secondPage->getItems(); - $this->assertCount(2 ,$categories); - $this->assertSameContent($expectedCategories[2], $categories[0]); - $this->assertSameContent($expectedCategories[3], $categories[1]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/categories?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - $this->assertNull($lastPage->getNextLink()); - $this->assertNull($lastPage->getNextPage()); - - $categories = $lastPage->getItems(); - $this->assertCount(1 ,$categories); - $this->assertSameContent($expectedCategories[4], $categories[0]); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getCategoryApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(5, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/categories?page=2&limit=2&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getCategoryApi(); - $expectedCategories = $this->getExpectedCategories(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/categories?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $categories = $firstPage->getItems(); - $this->assertCount(2 ,$categories); - $this->assertSameContent($expectedCategories[0], $categories[0]); - $this->assertSameContent($expectedCategories[1], $categories[1]); - } - - public function testAll() - { - $api = $this->createClient()->getCategoryApi(); - $categories = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $categories); - - $categories = iterator_to_array($categories); - - $this->assertCount(5, $categories); - $this->assertSameContent($this->getExpectedCategories(), $categories); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getCategoryApi(); - $categories = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $categories); - - $categories = iterator_to_array($categories); - - $this->assertCount(5, $categories); - $this->assertSameContent($this->getExpectedCategories(), $categories); - } - - /** - * @return array - */ - protected function getExpectedCategories() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/categories/2014_collection', - ], - ], - 'code' => '2014_collection', - 'parent' => null, - 'labels' => [ - 'en_US' => '2014 collection', - 'fr_FR' => 'collection 2014', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/categories/summer_collection', - ], - ], - 'code' => 'summer_collection', - 'parent' => '2014_collection', - 'labels' => [ - 'en_US' => 'Summer collection', - 'fr_FR' => 'Collection été', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/categories/sandals', - ], - ], - 'code' => 'sandals', - 'parent' => 'summer_collection', - 'labels' => [ - 'en_US' => 'Sandals', - 'fr_FR' => 'Sandales', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/categories/winter_collection', - ], - ], - 'code' => 'winter_collection', - 'parent' => '2014_collection', - 'labels' => [ - 'en_US' => 'Winter collection', - 'fr_FR' => 'Collection hiver', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/categories/winter_boots', - ], - ], - 'code' => 'winter_boots', - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => 'Winter boots', - 'fr_FR' => 'Bottes d\'hiver', - ], - ] - ]; - } -} diff --git a/tests/Common/Api/Category/UpsertCategoryIntegration.php b/tests/Common/Api/Category/UpsertCategoryIntegration.php deleted file mode 100644 index dd67cd64..00000000 --- a/tests/Common/Api/Category/UpsertCategoryIntegration.php +++ /dev/null @@ -1,87 +0,0 @@ -createClient()->getCategoryApi(); - - $response = $api->upsert('sandals', [ - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => 'Sandals !', - 'fr_FR' => 'Sandales', - ], - ]); - - $this->assertSame(204, $response); - - $category = $api->get('sandals'); - $this->assertSameContent([ - 'code' => 'sandals', - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => 'Sandals !', - 'fr_FR' => 'Sandales', - ], - ], $category); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getCategoryApi(); - $response = $api->upsert('booties', [ - 'parent' => 'summer_collection', - 'labels' => [ - 'en_US' => 'Booties', - 'fr_FR' => 'Bottines', - ], - ]); - - $this->assertSame(201, $response); - - $category = $api->get('booties'); - $this->assertSameContent([ - 'code' => 'booties', - 'parent' => 'summer_collection', - 'labels' => [ - 'en_US' => 'Booties', - 'fr_FR' => 'Bottines', - ], - ], $category); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getCategoryApi(); - $api->upsert('sandals', [ - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => ['wrong data type'], - 'fr_FR' => 'Sandales', - ], - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getCategoryApi(); - $api->upsert('invalid code !', [ - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => 'Invalid code', - 'fr_FR' => 'Code invalide', - ], - ]); - } -} diff --git a/tests/Common/Api/Category/UpsertListCategoryIntegration.php b/tests/Common/Api/Category/UpsertListCategoryIntegration.php deleted file mode 100644 index 557783b2..00000000 --- a/tests/Common/Api/Category/UpsertListCategoryIntegration.php +++ /dev/null @@ -1,122 +0,0 @@ -createClient()->getCategoryApi(); - - $response = $api->upsertList([ - [ - 'code' => 'sandals', - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => 'Sandals', - 'fr_FR' => 'Sandales', - ], - ], - [ - 'code' => 'booties', - 'parent' => 'summer_collection', - 'labels' => [ - 'en_US' => 'Booties', - 'fr_FR' => 'Bottines', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'sandals', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'booties', - 'status_code' => 201, - ] - ], $responseLines); - } - - public function testUpsertListFromStreamSuccessful() - { - $resourcesContent = -<<getStreamFactory()->createStream($resources); - $api = $this->createClient()->getCategoryApi(); - $response = $api->upsertList($streamedResources); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'sandals', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'booties', - 'status_code' => 201, - ] - ], $responseLines); - } - - public function testUpsertListFailed() - { - $api = $this->createClient()->getCategoryApi(); - - $response = $api->upsertList([ - [ - 'parent' => 'winter_collection', - 'labels' => [ - 'en_US' => 'Sandals', - 'fr_FR' => 'Sandales', - ], - ], - [ - 'code' => 'booties', - 'parent' => 'summer_collection', - 'labels' => [ - 'en_US' => 'line too long' . str_repeat('a', 1000000), - 'fr_FR' => 'Bottines', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Code is missing.', - ], - 2 => [ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ] - ], $responseLines); - } -} diff --git a/tests/Common/Api/Channel/GetChannelApiIntegration.php b/tests/Common/Api/Channel/GetChannelApiIntegration.php deleted file mode 100644 index 297a7525..00000000 --- a/tests/Common/Api/Channel/GetChannelApiIntegration.php +++ /dev/null @@ -1,45 +0,0 @@ -createClient()->getChannelApi(); - - $channel = $api->get('ecommerce'); - - $this->assertSameContent([ - 'code' => 'ecommerce', - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - 'conversion_units' => [ - ], - 'labels' => [ - 'en_US' => 'Ecommerce', - 'de_DE' => 'Ecommerce', - 'fr_FR' => 'Ecommerce', - ], - ], $channel); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getChannelApi(); - - $api->get('unknown'); - } -} diff --git a/tests/Common/Api/Channel/ListChannelApiIntegration.php b/tests/Common/Api/Channel/ListChannelApiIntegration.php deleted file mode 100644 index d40d3a57..00000000 --- a/tests/Common/Api/Channel/ListChannelApiIntegration.php +++ /dev/null @@ -1,164 +0,0 @@ -createClient()->getChannelAPi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedChannels = $this->getExpectedChannels(); - - $firstPage = $api->listPerPage(1); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/channels?page=2&limit=1&with_count=false', $firstPage->getNextLink()); - - $channels = $firstPage->getItems(); - $this->assertCount(1 ,$channels); - $this->assertSameContent($expectedChannels[0], $channels[0]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/channels?page=1&limit=1&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/channels?page=3&limit=1&with_count=false', $secondPage->getNextLink()); - - $channels = $secondPage->getItems(); - $this->assertCount(1 ,$channels); - $this->assertSameContent($expectedChannels[1], $channels[0]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/channels?page=2&limit=1&with_count=false', $lastPage->getPreviousLink()); - $this->assertCount(0, $lastPage->getItems()); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getChannelApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(1, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(2, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/channels?page=2&limit=1&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getChannelApi(); - $expectedChannels = $this->getExpectedChannels(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(1, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/channels?page=2&limit=1&with_count=false&foo=bar', $firstPage->getNextLink()); - - $channels = $firstPage->getItems(); - $this->assertCount(1 ,$channels); - $this->assertSameContent($expectedChannels[0], $channels[0]); - } - - public function testAll() - { - $api = $this->createClient()->getChannelApi(); - $channels = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $channels); - - $channels = iterator_to_array($channels); - - $this->assertCount(2, $channels); - $this->assertSameContent($this->getExpectedChannels(), $channels); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getChannelApi(); - $channels = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $channels); - - $channels = iterator_to_array($channels); - - $this->assertCount(2, $channels); - $this->assertSameContent($this->getExpectedChannels(), $channels); - } - - /** - * @return array - */ - public function getExpectedChannels() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/channels/ecommerce', - ], - ], - 'code' => 'ecommerce', - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - 'conversion_units' => [ - ], - 'labels' => [ - 'en_US' => 'Ecommerce', - 'de_DE' => 'Ecommerce', - 'fr_FR' => 'Ecommerce', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/channels/mobile', - ], - ], - 'code' => 'mobile', - 'currencies' => [ - 'EUR', - ], - 'locales' => [ - 'en_US', - ], - 'category_tree' => '2014_collection', - 'conversion_units' => [ - ], - 'labels' => [ - 'en_US' => 'Mobile', - 'de_DE' => 'Mobil', - 'fr_FR' => 'Mobile', - ], - ], - ]; - } -} diff --git a/tests/Common/Api/Family/CreateFamilyApiIntegration.php b/tests/Common/Api/Family/CreateFamilyApiIntegration.php deleted file mode 100644 index 06dc7544..00000000 --- a/tests/Common/Api/Family/CreateFamilyApiIntegration.php +++ /dev/null @@ -1,137 +0,0 @@ -createClient()->getFamilyApi(); - $response = $api->create('running', [ - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Running', - 'fr_FR' => 'Course', - ], - ]); - - $this->assertSame(201, $response); - - $family = $api->get('running'); - $this->assertSameContent([ - 'code' => 'running', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Running', - 'fr_FR' => 'Course', - ], - ], $family); - } - - public function testCreateAnExistingFamily() - { - $api = $this->createClient()->getFamilyApi(); - - try { - $api->create('boots', [ - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots', - 'fr_FR' => 'Bottes', - ], - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame([ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], $exception->getResponseErrors()); - } - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidFamily() - { - $api = $this->createClient()->getFamilyApi(); - $api->create('fail', [ - 'attributes' => [ - 'sku', - 'unknown_attribute', - ], - 'attribute_as_label' => 'unknown_attribute', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'sku', - ], - 'mobile' => [ - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Fail', - 'fr_FR' => 'Fail', - ], - ]); - } -} diff --git a/tests/Common/Api/Family/GetFamilyApiIntegration.php b/tests/Common/Api/Family/GetFamilyApiIntegration.php deleted file mode 100644 index 2504663c..00000000 --- a/tests/Common/Api/Family/GetFamilyApiIntegration.php +++ /dev/null @@ -1,17 +0,0 @@ -createClient()->getFamilyApi(); - $api->get('Addams'); - } -} diff --git a/tests/Common/Api/Family/UpsertFamilyApiIntegration.php b/tests/Common/Api/Family/UpsertFamilyApiIntegration.php deleted file mode 100644 index 086ecff6..00000000 --- a/tests/Common/Api/Family/UpsertFamilyApiIntegration.php +++ /dev/null @@ -1,210 +0,0 @@ -createClient()->getFamilyApi(); - - $response = $api->upsert('boots', [ - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - 'heel_color', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots!', - 'fr_FR' => 'Bottes', - ], - ]); - - $this->assertSame(204, $response); - - $family = $api->get('boots'); - $this->assertSameContent([ - 'attributes' => [ - 'color', - 'description', - 'heel_color', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots!', - 'fr_FR' => 'Bottes', - ], - ], $family); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getFamilyApi(); - $response = $api->upsert('running', [ - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Running', - 'fr_FR' => 'Course', - ], - ]); - - $this->assertSame(201, $response); - - $family = $api->get('running'); - $this->assertSameContent([ - 'code' => 'running', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Running', - 'fr_FR' => 'Course', - ], - ], $family); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getFamilyApi(); - $api->upsert('boots', [ - 'attributes' => 'colors', - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots', - 'fr_FR' => 'Bottes', - ], - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getFamilyApi(); - $api->upsert('invalid code !', [ - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - 'heel_color', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots!', - 'fr_FR' => 'Bottes', - ], - ]); - } -} diff --git a/tests/Common/Api/Family/UpsertListFamilyApiIntegration.php b/tests/Common/Api/Family/UpsertListFamilyApiIntegration.php deleted file mode 100644 index 6b2156e7..00000000 --- a/tests/Common/Api/Family/UpsertListFamilyApiIntegration.php +++ /dev/null @@ -1,157 +0,0 @@ -createClient()->getFamilyApi(); - - $response = $api->upsertList([ - [ - 'code' => 'heels', - 'attributes' => [ - 'manufacturer', - 'name', - 'price', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'name', - 'price', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Heels!', - 'fr_FR' => 'Talons!', - ], - ], - [ - 'code' => 'running', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Running', - 'fr_FR' => 'Course', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'code' => 'heels', - 'status_code' => 204, - ], $responseLines[1]); - - $this->assertSame([ - 'line' => 2, - 'code' => 'running', - 'status_code' => 201, - ], $responseLines[2]); - } - - public function testUpsertListFailed() - { - $api = $this->createClient()->getFamilyApi(); - - $response = $api->upsertList([ - [ - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Running', - 'fr_FR' => 'Course', - ], - ], - [ - 'code' => 'running', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'line too long' . str_repeat('a', 1000000), - 'fr_FR' => 'Course', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Code is missing.', - ], $responseLines[1]); - - $this->assertSame([ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ], $responseLines[2]); - } -} diff --git a/tests/Common/Api/Locale/GetLocaleApiIntegration.php b/tests/Common/Api/Locale/GetLocaleApiIntegration.php deleted file mode 100644 index 719ddd3b..00000000 --- a/tests/Common/Api/Locale/GetLocaleApiIntegration.php +++ /dev/null @@ -1,30 +0,0 @@ -createClient()->getLocaleApi(); - - $locale = $api->get('en_US'); - - $this->assertSameContent([ - 'code' => 'en_US', - 'enabled' => true, - ], $locale); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getLocaleApi(); - - $api->get('en_FR'); - } -} diff --git a/tests/Common/Api/Locale/ListLocaleApiIntegration.php b/tests/Common/Api/Locale/ListLocaleApiIntegration.php deleted file mode 100644 index ab774f17..00000000 --- a/tests/Common/Api/Locale/ListLocaleApiIntegration.php +++ /dev/null @@ -1,224 +0,0 @@ -createClient()->getLocaleApi(); - $expectedLocales = $this->getExpectedLocales(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(3); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/locales?page=2&limit=3&with_count=false', $firstPage->getNextLink()); - - $locales = $firstPage->getItems(); - $this->assertCount(3 ,$locales); - $this->assertSameContent($expectedLocales[0], $locales[0]); - $this->assertSameContent($expectedLocales[1], $locales[1]); - $this->assertSameContent($expectedLocales[2], $locales[2]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/locales?page=1&limit=3&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/locales?page=3&limit=3&with_count=false', $secondPage->getNextLink()); - - $locales = $secondPage->getItems(); - $this->assertCount(3 ,$locales); - $this->assertSameContent($expectedLocales[3], $locales[0]); - $this->assertSameContent($expectedLocales[4], $locales[1]); - $this->assertSameContent($expectedLocales[5], $locales[2]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertSame($baseUri . '/api/rest/v1/locales?page=2&limit=3&with_count=false', $lastPage->getPreviousLink()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertNull($lastPage->getNextPage()); - $this->assertCount(0 ,$lastPage->getItems()); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getLocaleApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(3, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(6, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/locales?page=2&limit=3&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getLocaleApi(); - $expectedLocales = $this->getExpectedLocales(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/locales?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $locales = $firstPage->getItems(); - $this->assertCount(2 ,$locales); - $this->assertSameContent($expectedLocales[0], $locales[0]); - $this->assertSameContent($expectedLocales[1], $locales[1]); - } - - public function testAll() - { - $api = $this->createClient()->getLocaleApi(); - $locales = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $locales); - - $locales = iterator_to_array($locales); - - $this->assertCount(6, $locales); - $this->assertSameContent($locales, $this->getExpectedLocales()); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getLocaleApi(); - $locales = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $locales); - - $locales = iterator_to_array($locales); - - $this->assertCount(6, $locales); - $this->assertSameContent($locales, $this->getExpectedLocales()); - } - - public function testSearchEnabledLocales() - { - $api = $this->createClient()->getLocaleApi(); - $locales = $api->listPerPage(10, true, [ - 'search' => [ - 'enabled' => [ - [ - 'operator' => '=', - 'value' => true, - ] - ] - ] - ]); - - $this->assertSame(2, $locales->getCount()); - - $locales = $locales->getItems(); - - $this->assertSameContent([ - 'code' => 'en_US', - 'enabled' => true, - ], $locales[0]); - - $this->assertSameContent([ - 'code' => 'fr_FR', - 'enabled' => true, - ], $locales[1]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testInvalidSearch() - { - $api = $this->createClient()->getLocaleApi(); - $api->listPerPage(10, true, [ - 'search' => [ - 'family' => [ - [ - 'operator' => 'IN', - 'value' => ['boots'], - ] - ] - ] - ]); - } - - /** - * @return array - */ - public function getExpectedLocales() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/locales/de_DE', - ], - ], - 'code' => 'de_DE', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/locales/en_GB', - ], - ], - 'code' => 'en_GB', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/locales/en_US', - ], - ], - 'code' => 'en_US', - 'enabled' => true, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/locales/fr_BE', - ], - ], - 'code' => 'fr_BE', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/locales/fr_FR', - ], - ], - 'code' => 'fr_FR', - 'enabled' => true, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/locales/it_IT', - ], - ], - 'code' => 'it_IT', - 'enabled' => false, - ], - ]; - } -} diff --git a/tests/Common/Api/Product/AbstractProductApiTestCase.php b/tests/Common/Api/Product/AbstractProductApiTestCase.php deleted file mode 100644 index 79dfdcb9..00000000 --- a/tests/Common/Api/Product/AbstractProductApiTestCase.php +++ /dev/null @@ -1,26 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -abstract class AbstractProductApiTestCase extends ApiTestCase -{ - /** - * Replaces changing data by specified values. - * - * @param array $productData - * - * @return array - */ - protected function sanitizeProductData(array $productData) - { - return ValuesSanitizer::sanitize($productData); - } -} diff --git a/tests/Common/Api/Product/CreateProductApiIntegration.php b/tests/Common/Api/Product/CreateProductApiIntegration.php deleted file mode 100644 index 2e35cf1c..00000000 --- a/tests/Common/Api/Product/CreateProductApiIntegration.php +++ /dev/null @@ -1,33 +0,0 @@ -createClient()->getProductApi(); - $api->create('pumps', [ - 'enabled' => false, - 'family' => 'unknown_family', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'data' => 'The pumps', - 'locale' => 'en_US', - 'scope' => null, - ], - [ - 'data' => 'Les pumps', - 'locale' => 'fr_FR', - 'scope' => null, - ] - ], - ] - ]); - } -} diff --git a/tests/Common/Api/Product/DeleteProductApiIntegration.php b/tests/Common/Api/Product/DeleteProductApiIntegration.php deleted file mode 100644 index c136844d..00000000 --- a/tests/Common/Api/Product/DeleteProductApiIntegration.php +++ /dev/null @@ -1,23 +0,0 @@ -createClient()->getProductApi(); - $response = $api->delete('docks_white'); - - $this->assertSame(204, $response); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testDeleteOnAnUnknownProduct() - { - $api = $this->createClient()->getProductApi(); - $api->delete('unknown'); - } -} diff --git a/tests/Common/Api/Product/GetProductApiIntegration.php b/tests/Common/Api/Product/GetProductApiIntegration.php deleted file mode 100644 index e3cebb2d..00000000 --- a/tests/Common/Api/Product/GetProductApiIntegration.php +++ /dev/null @@ -1,16 +0,0 @@ -createClient()->getProductApi(); - - $api->get('pumps'); - } -} diff --git a/tests/Common/Api/Product/ListProductApiIntegration.php b/tests/Common/Api/Product/ListProductApiIntegration.php deleted file mode 100644 index d72937b6..00000000 --- a/tests/Common/Api/Product/ListProductApiIntegration.php +++ /dev/null @@ -1,46 +0,0 @@ -createClient()->getProductApi(); - $products = $api->listPerPage(10, true, [ - 'search' => [ - 'name' => [ - [ - 'operator' => '=', - 'value' => 'No name', - 'locale' => 'en_US', - ] - ] - ] - ]); - - $this->assertInstanceOf(PageInterface::class, $products); - $this->assertSame(0, $products->getCount()); - $this->assertEmpty($products->getItems()); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testSearchFailedWithInvalidOperator() - { - $api = $this->createClient()->getProductApi(); - $api->listPerPage(10, true, [ - 'search' => [ - 'family' => [ - [ - 'operator' => '=', - 'value' => 'Invalid operator for Family', - ] - ] - ] - ]); - } -} diff --git a/tests/Common/Api/Product/UpsertProductApiIntegration.php b/tests/Common/Api/Product/UpsertProductApiIntegration.php deleted file mode 100644 index ce5ae164..00000000 --- a/tests/Common/Api/Product/UpsertProductApiIntegration.php +++ /dev/null @@ -1,26 +0,0 @@ -createClient()->getProductApi(); - $api->upsert('docks_black', [ - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => ['Black Docks'], - ], - ], - ] - ]); - } -} diff --git a/tests/Common/Api/ProductMediaFile/CreateProductMediaFileApiIntegration.php b/tests/Common/Api/ProductMediaFile/CreateProductMediaFileApiIntegration.php deleted file mode 100644 index 2d4a5afa..00000000 --- a/tests/Common/Api/ProductMediaFile/CreateProductMediaFileApiIntegration.php +++ /dev/null @@ -1,105 +0,0 @@ -createClient()->getProductMediaFileApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $mediaFile = realpath(__DIR__ . '/../../../fixtures/akeneo.png'); - - $response = $api->create($mediaFile, [ - 'identifier' => 'medium_boot', - 'attribute' => 'side_view', - 'scope' => null, - 'locale' => null, - ]); - - $this->assertSame(MediaSanitizer::MEDIA_ATTRIBUTE_DATA_COMPARISON, MediaSanitizer::sanitize($response)); - - $mediaFiles = $api->listPerPage(10)->getItems(); - - $this->assertCount(5, $mediaFiles); - - $expectedMediaFile = [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png', - ], - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png/download', - ], - ], - 'code' => 'f/b/0/6/fb068ccc9e3c5609d73c28d852812ba5faeeab28_akeneo.png', - 'original_filename' => 'akeneo.png', - 'mime_type' => 'image/png', - 'size' => 8073, - 'extension' => 'png', - ]; - - $expectedMediaFile = $this->sanitizeMediaFile($expectedMediaFile); - $mediaFiles[4] = $this->sanitizeMediaFile($mediaFiles[4]); - - $this->assertSameContent($expectedMediaFile, $mediaFiles[4]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnExistingMediaFile() - { - $api = $this->createClient()->getProductMediaFileApi(); - $mediaFile = realpath(__DIR__ . '/../fixtures/akeneo.png'); - - $api->create($mediaFile, [ - 'identifier' => 'medium_boot', - 'attribute' => 'side_view', - 'scope' => null, - 'locale' => null, - ]); - - $api->create($mediaFile, [ - 'identifier' => 'medium_boot', - 'attribute' => 'side_view', - 'scope' => null, - 'locale' => null, - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateWithAnInvalidRequest() - { - $api = $this->createClient()->getProductMediaFileApi(); - $mediaFile = realpath(__DIR__ . '/../fixtures/akeneo.png'); - - $api->create($mediaFile, [ - 'identifier' => 'unknown_product', - 'attribute' => 'side_view', - 'scope' => null, - 'locale' => null, - ]); - } - - /** - * Sanitize the code and links of a media file, because the code is generated randomly. - * - * @param array $mediaFile - * - * @return array - */ - protected function sanitizeMediaFile(array $mediaFile) - { - $mediaFile['code'] = MediaSanitizer::sanitize($mediaFile['code']); - $mediaFile['_links']['self']['href'] = MediaSanitizer::sanitize($mediaFile['_links']['self']['href']); - $mediaFile['_links']['download']['href'] = MediaSanitizer::sanitize($mediaFile['_links']['download']['href']); - - return $mediaFile; - } -} diff --git a/tests/Common/Api/ProductMediaFile/DownloadProductMediaFileApiIntegration.php b/tests/Common/Api/ProductMediaFile/DownloadProductMediaFileApiIntegration.php deleted file mode 100644 index 2dbaa5c1..00000000 --- a/tests/Common/Api/ProductMediaFile/DownloadProductMediaFileApiIntegration.php +++ /dev/null @@ -1,27 +0,0 @@ -createClient()->getProductMediaFileApi(); - $expectedMediaFile = realpath(__DIR__ . '/../../../fixtures/akeneo.png'); - - $mediaFileCode = $api->create($expectedMediaFile, [ - 'identifier' => 'medium_boot', - 'attribute' => 'side_view', - 'scope' => null, - 'locale' => null, - ]); - - $mediaFile = $api->download($mediaFileCode); - - $this->assertInstanceOf(StreamInterface::class, $mediaFile); - $this->assertSame(file_get_contents($expectedMediaFile), $mediaFile->getContents()); - } -} diff --git a/tests/Common/Api/ProductMediaFile/GetProductMediaFileApiIntegration.php b/tests/Common/Api/ProductMediaFile/GetProductMediaFileApiIntegration.php deleted file mode 100644 index 6d27cc0f..00000000 --- a/tests/Common/Api/ProductMediaFile/GetProductMediaFileApiIntegration.php +++ /dev/null @@ -1,43 +0,0 @@ -createClient()->getProductMediaFileApi(); - $code = $api->listPerPage(1)->getItems()[0]['code']; - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $mediaFile = $api->get($code); - $this->assertInternalType('array', $mediaFile); - - $expectedMediaFile = [ - 'code' => $code, - 'original_filename' => 'Ziggy-certification.jpg', - 'mime_type' => 'image/jpeg', - 'size' => 10513, - 'extension' => 'jpg', - '_links' => [ - 'download' => [ - 'href' => sprintf('%s/api/rest/v1/media-files/%s/download', $baseUri, $code), - ], - ], - ]; - - $this->assertSameContent($expectedMediaFile, $mediaFile); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getProductMediaFileApi(); - - $api->get('b/b/6/c/bb6ce0ef18bfa15d9e9fb4e3b26ce7064ac80b63_unknown_media_file.jpg'); - } -} diff --git a/tests/Common/Api/ProductMediaFile/ListProductMediaFileApiIntegration.php b/tests/Common/Api/ProductMediaFile/ListProductMediaFileApiIntegration.php deleted file mode 100644 index 15afdb9d..00000000 --- a/tests/Common/Api/ProductMediaFile/ListProductMediaFileApiIntegration.php +++ /dev/null @@ -1,210 +0,0 @@ -createClient()->getProductMediaFileApi(); - $expectedMediaFiles = $this->getExpectedMediaFiles(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/media-files?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $mediaFiles = $firstPage->getItems(); - - $this->assertCount(2 ,$mediaFiles); - $this->assertSameContent($expectedMediaFiles[0], $this->sanitizeMediaFile($mediaFiles[0])); - $this->assertSameContent($expectedMediaFiles[1], $this->sanitizeMediaFile($mediaFiles[1])); - - $secondPage = $firstPage->getNextPage(); - - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/media-files?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/media-files?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $mediaFiles = $secondPage->getItems(); - - $this->assertCount(2 ,$mediaFiles); - $this->assertSameContent($expectedMediaFiles[2], $this->sanitizeMediaFile($mediaFiles[0])); - $this->assertSameContent($expectedMediaFiles[3], $this->sanitizeMediaFile($mediaFiles[1])); - - $lastPage = $secondPage->getNextPage(); - - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertNull($lastPage->getNextPage()); - $this->assertCount(0, $lastPage->getItems()); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getProductMediaFileApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(4, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/media-files?page=2&limit=2&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getProductMediaFileApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedMediaFiles = $this->getExpectedMediaFiles(); - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/media-files?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $mediaFiles = $firstPage->getItems(); - - $this->assertCount(2 ,$mediaFiles); - $this->assertSameContent($expectedMediaFiles[0], $this->sanitizeMediaFile($mediaFiles[0])); - $this->assertSameContent($expectedMediaFiles[1], $this->sanitizeMediaFile($mediaFiles[1])); - } - - public function testAll() - { - $api = $this->createClient()->getProductMediaFileApi(); - $mediaFiles = $api->all(); - $expectedMediaFiles = $this->getExpectedMediaFiles(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $mediaFiles); - - $mediaFilesCount = 0; - foreach ($mediaFiles as $key => $mediaFile) { - $this->assertSameContent($expectedMediaFiles[$key], $this->sanitizeMediaFile($mediaFile)); - $mediaFilesCount++; - } - - $this->assertSame(4, $mediaFilesCount); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getProductMediaFileApi(); - $mediaFiles = $api->all(10, ['foo' => 'bar']); - $expectedMediaFiles = $this->getExpectedMediaFiles(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $mediaFiles); - - $mediaFilesCount = 0; - foreach ($mediaFiles as $key => $mediaFile) { - $this->assertSameContent($expectedMediaFiles[$key], $this->sanitizeMediaFile($mediaFile)); - $mediaFilesCount++; - } - - $this->assertSame(4, $mediaFilesCount); - } - - /** - * @return array - */ - protected function getExpectedMediaFiles() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - $this->sanitizeMediaFile([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/b/b/6/c/bb6ce0ef18bfa15d9e9fb4e3b26ce7064ac80b63_Ziggy_certification.jpg', - ], - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/b/b/6/c/bb6ce0ef18bfa15d9e9fb4e3b26ce7064ac80b63_Ziggy_certification.jpg/download', - ], - ], - 'code' => 'b/b/6/c/bb6ce0ef18bfa15d9e9fb4e3b26ce7064ac80b63_Ziggy_certification.jpg', - 'original_filename' => 'Ziggy-certification.jpg', - 'mime_type' => 'image/jpeg', - 'size' => 10513, - 'extension' => 'jpg', - ]), - $this->sanitizeMediaFile([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/a/d/d/f/addf77b39f4e38241861554afc7d0ed8e436c99c_Ziggy.png', - ], - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/a/d/d/f/addf77b39f4e38241861554afc7d0ed8e436c99c_Ziggy.png/download', - ], - ], - 'code' => 'a/d/d/f/addf77b39f4e38241861554afc7d0ed8e436c99c_Ziggy.png', - 'original_filename' => 'Ziggy.png', - 'mime_type' => 'image/png', - 'size' => 118039, - 'extension' => 'png', - ]), - $this->sanitizeMediaFile([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/b/b/f/b/bbfbb253c296b0c56ee641e94b032697c06ba9e7_Akeneo_logo.png', - ], - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/b/b/f/b/bbfbb253c296b0c56ee641e94b032697c06ba9e7_Akeneo_logo.png/download', - ], - ], - 'code' => 'b/b/f/b/bbfbb253c296b0c56ee641e94b032697c06ba9e7_Akeneo_logo.png', - 'original_filename' => 'Akeneo-logo.png', - 'mime_type' => 'image/png', - 'size' => 18929, - 'extension' => 'png', - ]), - $this->sanitizeMediaFile([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/b/8/2/3/b823fe85baf0a5fdc62a7864d2df430e7f1dbf77_Ziggy_certification.jpg', - ], - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/b/8/2/3/b823fe85baf0a5fdc62a7864d2df430e7f1dbf77_Ziggy_certification.jpg/download', - ], - ], - 'code' => 'b/8/2/3/b823fe85baf0a5fdc62a7864d2df430e7f1dbf77_Ziggy_certification.jpg', - 'original_filename' => 'Ziggy-certification.jpg', - 'mime_type' => 'image/jpeg', - 'size' => 10513, - 'extension' => 'jpg', - ]) - ]; - } - - /** - * Sanitize the code and links of a media file, because the code is generated randomly. - * - * @param array $mediaFile - * - * @return array - */ - protected function sanitizeMediaFile(array $mediaFile) - { - $mediaFile['code'] = MediaSanitizer::sanitize($mediaFile['code']); - $mediaFile['_links']['self']['href'] = MediaSanitizer::sanitize($mediaFile['_links']['self']['href']); - $mediaFile['_links']['download']['href'] = MediaSanitizer::sanitize($mediaFile['_links']['download']['href']); - - return $mediaFile; - } -} diff --git a/tests/ConsoleCommandLauncher.php b/tests/ConsoleCommandLauncher.php deleted file mode 100644 index 3a709fc3..00000000 --- a/tests/ConsoleCommandLauncher.php +++ /dev/null @@ -1,67 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class ConsoleCommandLauncher -{ - /** @var array */ - private $configuration; - - /** - * @param array $configuration - */ - public function __construct(array $configuration) - { - $this->configuration = $configuration; - } - - /** - * Launches a command and returns its output. - * - * @param string $command - * - * @throws ProcessFailedException - * - * @return string - */ - public function launch($command) - { - $process = new Process(sprintf('%s %s', $this->getPimConsole(), $command)); - $process->mustRun(); - - return $process->getOutput(); - } - - /** - * Prepares the execution of the PIM console script. - * - * @return string - */ - private function getPimConsole() - { - $installPath = $this->configuration['pim']['install_path']; - $binPath = $this->configuration['pim']['bin_path']; - - if (true === $this->configuration['pim']['is_docker']) { - $container = $this->configuration['pim']['docker_name']; - - - return sprintf('docker exec %s %s/%s/console', $container, $installPath, $binPath); - } - - return sprintf('%s/%s/console', $installPath, $binPath); - } -} diff --git a/tests/CredentialGenerator.php b/tests/CredentialGenerator.php deleted file mode 100644 index 69ab8191..00000000 --- a/tests/CredentialGenerator.php +++ /dev/null @@ -1,54 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class CredentialGenerator -{ - /** @var ConsoleCommandLauncher */ - private $consoleCommandLauncher; - - /** - * @param ConsoleCommandLauncher $consoleCommandLauncher - */ - public function __construct(ConsoleCommandLauncher $consoleCommandLauncher) - { - $this->consoleCommandLauncher = $consoleCommandLauncher; - } - - /** - * Generates credentials on the PIM. - * - * @param string $pimVersion Akeneo PIM version - * - * @throws \RuntimeException If it was not possible to get the client id and - * secrets from the process output - * - * @return array credentials on the form ['client_id' => 'client', 'secret' => 'secret'] - */ - public function generate($pimVersion) - { - $label = "1.7" === $pimVersion ? '--label="PHP client credentials"' : '"PHP client credentials"'; - $command = sprintf('pim:oauth-server:create-client %s -e prod', $label); - - $output = $this->consoleCommandLauncher->launch($command); - - preg_match('/client_id: (.+)/', $output, $client); - preg_match('/secret: (.+)/', $output, $secret); - - if (!isset($client[1]) || !isset($secret[1])) { - throw new \RuntimeException(sprintf( - 'An error occurred when getting client id and secret from the generation process output: "%s"', - $output - )); - } - - return ['client_id' => $client[1], 'secret' => $secret[1]]; - } -} diff --git a/tests/DatabaseInstaller.php b/tests/DatabaseInstaller.php deleted file mode 100644 index aacedf0b..00000000 --- a/tests/DatabaseInstaller.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class DatabaseInstaller -{ - /** @var ConsoleCommandLauncher */ - private $consoleCommandLauncher; - - /** - * @param ConsoleCommandLauncher $consoleCommandLauncher - */ - public function __construct(ConsoleCommandLauncher $consoleCommandLauncher) - { - $this->consoleCommandLauncher = $consoleCommandLauncher; - } - - /** - * Installs the PIM database. - */ - public function install() - { - $this->consoleCommandLauncher->launch('pim:installer:db -e prod'); - } -} diff --git a/tests/DateSanitizer.php b/tests/DateSanitizer.php deleted file mode 100644 index 891bcd3e..00000000 --- a/tests/DateSanitizer.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class DateSanitizer -{ - const DATE_FIELD_COMPARISON = 'this is a date formatted to ISO-8601'; - const DATE_FIELD_PATTERN = '#[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\+[0-9]{2}:[0-9]{2}$#'; - - /** - * Replaces date by self::DATE_FIELD_COMPARISON. - * - * @param mixed $data - * - * @return mixed - */ - public static function sanitize($data) - { - if (1 === preg_match(self::DATE_FIELD_PATTERN, $data)) { - return self::DATE_FIELD_COMPARISON; - } - - return $data; - } -} diff --git a/tests/MediaSanitizer.php b/tests/MediaSanitizer.php deleted file mode 100644 index 4971b498..00000000 --- a/tests/MediaSanitizer.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class MediaSanitizer -{ - const MEDIA_ATTRIBUTE_DATA_COMPARISON = 'this is a media identifier'; - const MEDIA_ATTRIBUTE_DATA_PATTERN = '#([0-9a-z]/){4}[0-9a-z]{40}_\w+\.[a-zA-Z]+(/download)?$#'; - - /** - * Replaces media attributes data in the $data by self::MEDIA_ATTRIBUTE_DATA_COMPARISON. - * - * @param mixed $data - * - * @return mixed - */ - public static function sanitize($data) - { - if (1 === preg_match(self::MEDIA_ATTRIBUTE_DATA_PATTERN, $data)) { - return self::MEDIA_ATTRIBUTE_DATA_COMPARISON; - } - - return $data; - } -} diff --git a/tests/ValuesSanitizer.php b/tests/ValuesSanitizer.php deleted file mode 100644 index 41e5e6f9..00000000 --- a/tests/ValuesSanitizer.php +++ /dev/null @@ -1,32 +0,0 @@ - - * @copyright 2017 Akeneo SAS (http://www.akeneo.com) - * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) - */ -class ValuesSanitizer -{ - /** - * @param mixed $values - * - * @return mixed - */ - public static function sanitize($values) - { - foreach ($values as $key => $value) { - if (is_array($value)) { - $values[$key] = static::sanitize($value); - } else { - $values[$key] = DateSanitizer::sanitize($values[$key]); - $values[$key] = MediaSanitizer::sanitize($values[$key]); - } - } - - return $values; - } -} diff --git a/tests/etc/parameters.yml.dist b/tests/etc/parameters.yml.dist deleted file mode 100644 index d968d269..00000000 --- a/tests/etc/parameters.yml.dist +++ /dev/null @@ -1,7 +0,0 @@ -pim: - base_uri: 'http://akeneo-pim' - install_path: '/srv/pim' - is_docker: true - docker_name: akeneo-pim - bin_path: app - version: '1.7' diff --git a/tests/v1_7/Api/Family/GetFamilyApiIntegration.php b/tests/v1_7/Api/Family/GetFamilyApiIntegration.php deleted file mode 100644 index 65532caa..00000000 --- a/tests/v1_7/Api/Family/GetFamilyApiIntegration.php +++ /dev/null @@ -1,50 +0,0 @@ -createClient()->getFamilyApi(); - $family = $api->get('boots'); - - $expectedFamily = [ - 'code' => 'boots', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots', - 'fr_FR' => 'Bottes', - ], - ]; - - $this->assertSameContent($expectedFamily, $family); - } -} diff --git a/tests/v1_7/Api/Family/ListFamilyApiIntegration.php b/tests/v1_7/Api/Family/ListFamilyApiIntegration.php deleted file mode 100644 index 9f0172e3..00000000 --- a/tests/v1_7/Api/Family/ListFamilyApiIntegration.php +++ /dev/null @@ -1,252 +0,0 @@ -createClient()->getFamilyApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedFamilies = $this->getExpectedFamilies(); - - $firstPage = $api->listPerPage(2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $families = $firstPage->getItems(); - $this->assertCount(2 ,$families); - $this->assertSameContent($expectedFamilies[0], $families[0]); - $this->assertSameContent($expectedFamilies[1], $families[1]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $families = $secondPage->getItems(); - $this->assertCount(2 ,$families); - $this->assertSameContent($expectedFamilies[2], $families[0]); - $this->assertSameContent($expectedFamilies[3], $families[1]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - - $families = $lastPage->getItems(); - $this->assertCount(0 ,$families); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getFamilyApi(); - $expectedFamilies = $this->getExpectedFamilies(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/families?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $families = $firstPage->getItems(); - $this->assertCount(2 ,$families); - $this->assertSameContent($expectedFamilies[0], $families[0]); - $this->assertSameContent($expectedFamilies[1], $families[1]); - } - - public function testAll() - { - $api = $this->createClient()->getFamilyApi(); - $families = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $families); - - $families = iterator_to_array($families); - - $this->assertCount(4, $families); - $this->assertSameContent($this->getExpectedFamilies(), $families); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getFamilyApi(); - $families = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $families); - - $families = iterator_to_array($families); - - $this->assertCount(4, $families); - $this->assertSameContent($this->getExpectedFamilies(), $families); - } - - /** - * @return array - */ - protected function getExpectedFamilies() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/boots', - ], - ], - 'code' => 'boots', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots', - 'fr_FR' => 'Bottes', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/heels', - ], - ], - 'code' => 'heels', - 'attributes' => [ - 'manufacturer', - 'name', - 'price', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'name', - 'price', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Heels', - 'fr_FR' => 'Talons', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/sandals', - ], - ], - 'code' => 'sandals', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Sandals', - 'fr_FR' => 'Sandales', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/sneakers', - ], - ], - 'code' => 'sneakers', - 'attributes' => [ - 'color', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'name', - 'price', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Sneakers', - 'fr_FR' => 'Sneakers', - ], - ], - ]; - } -} diff --git a/tests/v1_7/Api/Product/CreateProductApiIntegration.php b/tests/v1_7/Api/Product/CreateProductApiIntegration.php deleted file mode 100644 index d6acef1e..00000000 --- a/tests/v1_7/Api/Product/CreateProductApiIntegration.php +++ /dev/null @@ -1,103 +0,0 @@ -createClient()->getProductApi(); - - try { - $api->create('black_sneakers', [ - 'enabled' => false, - 'family' => 'sneakers', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'data' => 'Black sneakers', - 'scope' => null, - ], - [ - 'data' => 'Sneakers', - 'locale' => 'fr_FR', - 'scope' => null, - ], - ], - ] - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame([ - [ - 'property' => 'identifier', - 'message' => 'The value black_sneakers is already set on another product for the unique attribute sku', - ], - ], $exception->getResponseErrors()); - } - } - - public function testCreate() - { - $api = $this->createClient()->getProductApi(); - $response = $api->create('pumps', [ - 'enabled' => false, - 'family' => 'sandals', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'data' => 'The pumps', - 'locale' => 'en_US', - 'scope' => null, - ], - [ - 'data' => 'Les pumps', - 'locale' => 'fr_FR', - 'scope' => null, - ] - ], - ] - ]); - - $this->assertSame(201, $response); - - $expectedProduct = $this->sanitizeProductData([ - 'identifier' => 'pumps', - 'family' => 'sandals', - 'groups' => [ - ], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - ], - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'The pumps', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Les pumps', - ], - ], - ], - 'created' => '2017-06-26T14:27:19+00:00', - 'updated' => '2017-06-26T14:27:19+00:00', - 'associations' => [ - ], - ]); - - $product = $this->sanitizeProductData($api->get('pumps')); - - $this->assertSameContent($expectedProduct, $product); - } -} diff --git a/tests/v1_7/Api/Product/GetProductApiIntegration.php b/tests/v1_7/Api/Product/GetProductApiIntegration.php deleted file mode 100644 index 2e37d465..00000000 --- a/tests/v1_7/Api/Product/GetProductApiIntegration.php +++ /dev/null @@ -1,127 +0,0 @@ -createClient()->getProductApi(); - - $product = $api->get('black_sneakers'); - $product = $this->sanitizeProductData($product); - - $this->assertSameContent($this->sanitizeProductData([ - 'identifier' => 'black_sneakers', - 'family' => 'sneakers', - 'groups' => [ - ], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'The famous sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Les fameuses sneakers', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Sneakers', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '9/8/e/d/98eda36deba5e392f5c9e0dd2d9ef194b045b2af_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => 'http://localhost/api/rest/v1/media-files/9/8/e/d/98eda36deba5e392f5c9e0dd2d9ef194b045b2af_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'length' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'amount' => 14, - 'unit' => 'CENTIMETER', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '40.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-22T14:08:29+00:00', - 'updated' => '2017-06-22T14:08:29+00:00', - 'associations' => [], - ]), $product); - } -} diff --git a/tests/v1_7/Api/Product/ListProductApiIntegration.php b/tests/v1_7/Api/Product/ListProductApiIntegration.php deleted file mode 100644 index a389f4fb..00000000 --- a/tests/v1_7/Api/Product/ListProductApiIntegration.php +++ /dev/null @@ -1,1355 +0,0 @@ -createClient()->getProductApi(); - $expectedProducts = $this->getExpectedProducts(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(5); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=false&pagination_type=page&limit=5', $firstPage->getNextLink()); - - $firstPageProducts = $this->sanitizeProductData($firstPage->getItems()); - $firstPageExpectedProducts = $this->sanitizeProductData(array_slice($expectedProducts, 0, 5)); - - $this->assertSameContent($firstPageExpectedProducts, $firstPageProducts); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=1&with_count=false&pagination_type=page&limit=5', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=3&with_count=false&pagination_type=page&limit=5', $secondPage->getNextLink()); - - $secondPageProducts = $this->sanitizeProductData($secondPage->getItems()); - $secondPageExpectedProducts = $this->sanitizeProductData(array_slice($expectedProducts, 5, 5)); - - $this->assertSameContent($secondPageExpectedProducts, $secondPageProducts); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=false&pagination_type=page&limit=5', $lastPage->getPreviousLink()); - - $products = $lastPage->getItems(); - $this->assertCount(0 ,$products); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getProductApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(10, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=true&pagination_type=page&limit=2', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getProductApi(); - $expectedProducts = $this->getExpectedProducts(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=false&pagination_type=page&limit=2&foo=bar', $firstPage->getNextLink()); - - $expectedProducts = $this->sanitizeProductData(array_slice($expectedProducts, 0, 2)); - $actualProducts = $this->sanitizeProductData($firstPage->getItems()); - $this->assertSameContent($expectedProducts, $actualProducts); - } - - public function testAll() - { - $api = $this->createClient()->getProductApi(); - $products = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $products); - - $expectedProducts = $this->sanitizeProductData($this->getExpectedProducts()); - $products = $this->sanitizeProductData(iterator_to_array($products)); - - $this->assertSameContent($expectedProducts, $products); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getProductApi(); - $products = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $products); - - $expectedProducts = $this->sanitizeProductData($this->getExpectedProducts()); - $products = $this->sanitizeProductData(iterator_to_array($products)); - - $this->assertSameContent($expectedProducts, $products); - } - - public function testSearchOnProductProperties() - { - $api = $this->createClient()->getProductApi(); - $products = $api->listPerPage(10, true, [ - 'search' => [ - 'family' => [ - [ - 'operator' => 'IN', - 'value' => ['sneakers'], - ] - ] - ] - ]); - - $this->assertSame(1, $products->getCount()); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('black_sneakers')); - $actualProduct = $this->sanitizeProductData($products->getItems()[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testSearchOnProductValues() - { - $api = $this->createClient()->getProductApi(); - $products = $api->listPerPage(10, true, [ - 'search' => [ - 'color' => [ - [ - 'operator' => 'IN', - 'value' => ['maroon'] - ] - ] - ] - ]); - - $this->assertSame(2, $products->getCount()); - - $products = $products->getItems(); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('small_boot')); - $actualProduct = $this->sanitizeProductData($products[0]); - $this->assertSameContent($expectedProduct, $actualProduct); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('docks_maroon')); - $actualProduct = $this->sanitizeProductData($products[1]); - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testSearchWithSeveralFiltersUsingSearchBuilder() - { - $api = $this->createClient()->getProductApi(); - - $searchBuilder = new SearchBuilder(); - $searchBuilder - ->addFilter('family', 'IN', ['sneakers']) - ->addFilter('color', 'IN', ['white', 'black']); - - $products = $api->listPerPage(10, true, ['search' => $searchBuilder->getFilters()]); - - $this->assertSame(1, $products->getCount()); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('black_sneakers')); - $actualProduct = $this->sanitizeProductData($products->getItems()[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testAllWithSelectedLocales() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $api = $this->createClient()->getProductApi(); - $products = $api->all(10, [ - 'locales' => 'fr_FR', - 'search' => [ - 'categories' => [ - [ - 'operator' => 'IN', - 'value' => ['sandals'], - ] - ] - ] - ]); - - $expectedProduct = $this->sanitizeProductData([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/dance_shoe', - ], - ], - 'identifier' => 'dance_shoe', - 'family' => 'sandals', - 'groups' => [], - 'variant_group' => null, - 'categories' => [ - 'sandals', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'greem', - ], - ], - 'description' => [ - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Dansez toute la nuit !', - ], - ], - 'destocking_date' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '2017-06-30T00:00:00+00:00', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Chaussure de dance', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '40', - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '90.50', - 'currency' => 'USD', - ], - [ - 'amount' => '99.49', - 'currency' => 'EUR', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ]); - - $actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testAllWithSelectedAttributes() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $api = $this->createClient()->getProductApi(); - $products = $api->all(1, ['attributes' => 'name,color']); - - $expectedProduct = $this->sanitizeProductData([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/big_boot', - ], - ], - 'identifier' => 'big_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Big boot !', - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [ - 'X_SELL' => [ - 'groups' => [], - 'products' => [ - 'small_boot', - 'medium_boot', - ], - ], - ], - ]); - - $actualProduct = $this->sanitizeProductData($products->current()); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testAllWithSelectedScope() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $api = $this->createClient()->getProductApi(); - $products = $api->all(10, [ - 'scope' => 'mobile', - 'search' => [ - 'family' => [ - [ - 'operator' => 'IN', - 'value' => ['sneakers'], - ] - ] - ] - ]); - - $expectedProduct = $this->sanitizeProductData([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/black_sneakers', - ], - ], - 'identifier' => 'black_sneakers', - 'family' => 'sneakers', - 'groups' => [], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black sneakers', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'length' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'amount' => 14, - 'unit' => 'CENTIMETER', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '40.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ]); - - $actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - /** - * @param string $identifier - * - * @return mixed - */ - protected function getExpectedProductByIdentifier($identifier) - { - foreach ($this->getExpectedProducts() as $product) { - if ($identifier === $product['identifier']) { - return $product; - } - } - } - - /** - * @return array - */ - protected function getExpectedProducts() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/big_boot', - ], - ], - 'identifier' => 'big_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Big boot for a big foot.', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'TimberLand', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Big boot !', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '8/2/4/3/824336b53f78c7badf3538793ab3ba92ffa3c120_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/8/2/4/3/824336b53f78c7badf3538793ab3ba92ffa3c120_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '37', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '110.00', - 'currency' => 'USD', - ], - [ - 'amount' => '120.00', - 'currency' => 'EUR', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [ - 'X_SELL' => [ - 'groups' => [], - 'products' => [ - 'small_boot', - 'medium_boot', - ], - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/small_boot', - ], - ], - 'identifier' => 'small_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'maroon', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'TimberLand', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Small boot', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '4/9/1/2/4912ff747899d2ade4d7f8d965b6d3d9a771655c_Ziggy.png', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/4/9/1/2/4912ff747899d2ade4d7f8d965b6d3d9a771655c_Ziggy.png/download', - ], - ], - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '110.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '110.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/medium_boot', - ], - ], - 'identifier' => 'medium_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'variant_group' => null, - 'categories' => [ - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'white', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'The medium boot.', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Medium boot', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '100.49', - 'currency' => 'USD', - ], - [ - 'amount' => '100.50', - 'currency' => 'EUR', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/dance_shoe', - ], - ], - 'identifier' => 'dance_shoe', - 'family' => 'sandals', - 'groups' => [], - 'variant_group' => null, - 'categories' => [ - 'sandals', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'greem', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'To dance all night !', - ], - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Dansez toute la nuit !', - ], - ], - 'destocking_date' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '2017-06-30T00:00:00+00:00', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Dance shoe', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Chaussure de dance', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '40', - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '90.50', - 'currency' => 'USD', - ], - [ - 'amount' => '99.49', - 'currency' => 'EUR', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/black_sneakers', - ], - ], - 'identifier' => 'black_sneakers', - 'family' => 'sneakers', - 'groups' => [], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'The famous sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Les fameuses sneakers', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Sneakers', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'length' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'amount' => 14, - 'unit' => 'CENTIMETER', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '40.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_blue', - ], - ], - 'identifier' => 'docks_blue', - 'family' => 'boots', - 'groups' => [], - 'variant_group' => 'caterpillar_boots', - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'blue', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_black', - ], - ], - 'identifier' => 'docks_black', - 'family' => 'boots', - 'groups' => [], - 'variant_group' => 'caterpillar_boots', - 'categories' => [ - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '42', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_white', - ], - ], - 'identifier' => 'docks_white', - 'family' => 'boots', - 'groups' => [], - 'variant_group' => 'caterpillar_boots', - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'white', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_maroon', - ], - ], - 'identifier' => 'docks_maroon', - 'family' => 'boots', - 'groups' => [], - 'variant_group' => 'caterpillar_boots', - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'maroon', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_red', - ], - ], - 'identifier' => 'docks_red', - 'family' => 'boots', - 'groups' => [], - 'variant_group' => 'caterpillar_boots', - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'red', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - ]; - } -} diff --git a/tests/v1_7/Api/Product/UpsertProductApiIntegration.php b/tests/v1_7/Api/Product/UpsertProductApiIntegration.php deleted file mode 100644 index f71e72d5..00000000 --- a/tests/v1_7/Api/Product/UpsertProductApiIntegration.php +++ /dev/null @@ -1,161 +0,0 @@ -createClient()->getProductApi(); - - $response = $api->upsert('docks_black', [ - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', - ], - ], - ] - ]); - - $this->assertSame(204, $response); - - $product = $this->sanitizeProductData($api->get('docks_black')); - - $this->assertSameContent($this->sanitizeProductData([ - 'identifier' => 'docks_black', - 'family' => 'boots', - 'groups' => [], - 'variant_group' => 'caterpillar_boots', - 'categories' => [ - 'winter_boots', - 'winter_collection', - ], - 'enabled' => false, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '42', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T14:48:15+00:00', - 'associations' => [] - ]), $product); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getProductApi(); - $response = $api->upsert('pumps', [ - 'enabled' => false, - 'family' => 'sandals', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'data' => 'The pumps', - 'locale' => 'en_US', - 'scope' => null, - ], - [ - 'data' => 'Les pumps', - 'locale' => 'fr_FR', - 'scope' => null, - ] - ], - ] - ]); - - $this->assertSame(201, $response); - - $product = $this->sanitizeProductData($api->get('pumps')); - - $expectedProduct = $this->sanitizeProductData([ - 'identifier' => 'pumps', - 'family' => 'sandals', - 'groups' => [], - 'variant_group' => null, - 'categories' => [ - 'summer_collection', - ], - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'The pumps', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Les pumps', - ], - ], - ], - 'created' => '2017-06-26T14:27:19+00:00', - 'updated' => '2017-06-26T14:27:19+00:00', - 'associations' => [ - ], - ]); - - $this->assertSameContent($expectedProduct, $product); - } -} diff --git a/tests/v2_0/Api/AssociationType/CreateAssociationTypeApiIntegration.php b/tests/v2_0/Api/AssociationType/CreateAssociationTypeApiIntegration.php deleted file mode 100644 index f369b95b..00000000 --- a/tests/v2_0/Api/AssociationType/CreateAssociationTypeApiIntegration.php +++ /dev/null @@ -1,77 +0,0 @@ -createClient()->getAssociationTypeApi(); - $response = $api->create( - 'NEW_SELL', - [ - 'labels' => [ - 'en_US' => 'New sell', - 'fr_FR' => 'Nouvelle vente', - ], - ] - ); - - $this->assertSame(201, $response); - - $associationType = $api->get('NEW_SELL'); - $this->assertSameContent( - [ - 'code' => 'NEW_SELL', - 'labels' => [ - 'en_US' => 'New sell', - 'fr_FR' => 'Nouvelle vente', - ], - ], - $associationType - ); - } - - public function testCreateAnExistingAssociationType() - { - $api = $this->createClient()->getAssociationTypeApi(); - - try { - $api->create( - 'UPSELL', - [ - 'labels' => [ - 'en_US' => 'Upsell', - ], - ] - ); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame( - [ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], - $exception->getResponseErrors() - ); - } - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidAssociationType() - { - $api = $this->createClient()->getAssociationTypeApi(); - $api->create( - 'fail', - [ - 'labels' => 'Upsell', - ] - ); - } -} diff --git a/tests/v2_0/Api/AssociationType/GetAssociationTypeApiIntegration.php b/tests/v2_0/Api/AssociationType/GetAssociationTypeApiIntegration.php deleted file mode 100644 index 33fc462c..00000000 --- a/tests/v2_0/Api/AssociationType/GetAssociationTypeApiIntegration.php +++ /dev/null @@ -1,32 +0,0 @@ -createClient()->getAssociationTypeApi(); - - $associationType = $api->get('X_SELL'); - - $this->assertSameContent([ - 'code' => 'X_SELL', - 'labels' => [ - 'en_US' => 'Cross sell', - ], - ], $associationType); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getAssociationTypeApi(); - - $api->get('unknown'); - } -} diff --git a/tests/v2_0/Api/AssociationType/ListAssociationTypeApiIntegration.php b/tests/v2_0/Api/AssociationType/ListAssociationTypeApiIntegration.php deleted file mode 100644 index 2a3be920..00000000 --- a/tests/v2_0/Api/AssociationType/ListAssociationTypeApiIntegration.php +++ /dev/null @@ -1,164 +0,0 @@ -createClient()->getAssociationTypeApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedAssociationTypes = $this->getExpectedAssociationTypes(); - - $firstPage = $api->listPerPage(2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/association-types?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $associationTypes = $firstPage->getItems(); - $this->assertCount(2 ,$associationTypes); - $this->assertSameContent($expectedAssociationTypes[0], $associationTypes[0]); - $this->assertSameContent($expectedAssociationTypes[1], $associationTypes[1]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/association-types?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/association-types?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $associationTypes = $secondPage->getItems(); - $this->assertCount(2 ,$associationTypes); - $this->assertSameContent($expectedAssociationTypes[2], $associationTypes[0]); - $this->assertSameContent($expectedAssociationTypes[3], $associationTypes[1]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/association-types?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - $this->assertCount(0, $lastPage->getItems()); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getAssociationTypeApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(1, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(4, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/association-types?page=2&limit=1&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getAssociationTypeApi(); - $expectedAssociationTypes = $this->getExpectedAssociationTypes(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(1, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/association-types?page=2&limit=1&with_count=false&foo=bar', $firstPage->getNextLink()); - - $associationTypes = $firstPage->getItems(); - $this->assertCount(1 ,$associationTypes); - $this->assertSameContent($expectedAssociationTypes[0], $associationTypes[0]); - } - - public function testAll() - { - $api = $this->createClient()->getAssociationTypeApi(); - $associationTypes = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $associationTypes); - - $associationTypes = iterator_to_array($associationTypes); - - $this->assertCount(4, $associationTypes); - $this->assertSameContent($this->getExpectedAssociationTypes(), $associationTypes); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getAssociationTypeApi(); - $associationTypes = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $associationTypes); - - $associationTypes = iterator_to_array($associationTypes); - - $this->assertCount(4, $associationTypes); - $this->assertSameContent($this->getExpectedAssociationTypes(), $associationTypes); - } - - /** - * @return array - */ - public function getExpectedAssociationTypes() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/association-types/PACK', - ], - ], - 'code' => 'PACK', - 'labels' => [ - 'en_US' => 'Pack', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/association-types/SUBSTITUTION', - ], - ], - 'code' => 'SUBSTITUTION', - 'labels' => [ - 'en_US' => 'Substitution', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/association-types/UPSELL', - ], - ], - 'code' => 'UPSELL', - 'labels' => [ - 'en_US' => 'Upsell', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/association-types/X_SELL', - ], - ], - 'code' => 'X_SELL', - 'labels' => [ - 'en_US' => 'Cross sell', - ], - ], - ]; - } -} diff --git a/tests/v2_0/Api/AssociationType/UpsertAssociationTypeApiIntegration.php b/tests/v2_0/Api/AssociationType/UpsertAssociationTypeApiIntegration.php deleted file mode 100644 index 2ed30adc..00000000 --- a/tests/v2_0/Api/AssociationType/UpsertAssociationTypeApiIntegration.php +++ /dev/null @@ -1,90 +0,0 @@ -createClient()->getAssociationTypeApi(); - - $response = $api->upsert( - 'X_SELL', - [ - 'labels' => [ - 'en_US' => 'Cross sell', - 'fr_FR' => 'Vente croisée', - ], - ] - ); - - $this->assertSame(204, $response); - - $associationType = $api->get('X_SELL'); - $this->assertSameContent( - [ - 'code' => 'X_SELL', - 'labels' => [ - 'en_US' => 'Cross sell', - 'fr_FR' => 'Vente croisée', - ], - ], - $associationType - ); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getAssociationTypeApi(); - $response = $api->upsert( - 'NEW_SELL', - [ - 'labels' => [ - 'en_US' => 'New sell', - 'fr_FR' => 'Nouvelle vente', - ], - ] - ); - - $this->assertSame(201, $response); - - $associationType = $api->get('NEW_SELL'); - $this->assertSameContent( - [ - 'code' => 'NEW_SELL', - 'labels' => [ - 'en_US' => 'New sell', - 'fr_FR' => 'Nouvelle vente', - ], - ], - $associationType - ); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getAssociationTypeApi(); - $api->upsert( - 'NEW_SELL', - [ - 'labels' => [ - 'en_US' => ['New sell'], - ], - ] - ); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getCategoryApi(); - $api->upsert('invalid code !'); - } -} diff --git a/tests/v2_0/Api/AssociationType/UpsertListAssociationTypeApiIntegration.php b/tests/v2_0/Api/AssociationType/UpsertListAssociationTypeApiIntegration.php deleted file mode 100644 index 53a1300c..00000000 --- a/tests/v2_0/Api/AssociationType/UpsertListAssociationTypeApiIntegration.php +++ /dev/null @@ -1,118 +0,0 @@ -createClient()->getAssociationTypeApi(); - - $response = $api->upsertList([ - [ - 'code' => 'X_SELL', - 'labels' => [ - 'en_US' => 'Cross sell', - 'fr_FR' => 'Vente croisée', - ], - ], - [ - 'code' => 'NEW_SELL', - 'labels' => [ - 'en_US' => 'New sell', - 'fr_FR' => 'Nouvelle vente', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'X_SELL', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'NEW_SELL', - 'status_code' => 201, - ] - ], $responseLines); - } - - public function testUpsertListFromStreamSuccessful() - { - $resourcesContent = - <<getStreamFactory()->createStream($resources); - $api = $this->createClient()->getAssociationTypeApi(); - $response = $api->upsertList($streamedResources); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'X_SELL', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'NEW_SELL', - 'status_code' => 201, - ] - ], $responseLines); - } - - public function testUpsertListFailed() - { - $api = $this->createClient()->getAssociationTypeApi(); - - $response = $api->upsertList([ - [ - 'labels' => [ - 'en_US' => 'Cross sell', - 'fr_FR' => 'Vente croisée', - ], - ], - [ - 'code' => 'NEW_SELL', - 'labels' => [ - 'en_US' => 'line too long' . str_repeat('a', 1000000), - 'fr_FR' => 'Nouvelle vente', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Code is missing.', - ], - 2 => [ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ] - ], $responseLines); - } -} diff --git a/tests/v2_0/Api/AttributeGroup/CreateAttributeGroupApiIntegration.php b/tests/v2_0/Api/AttributeGroup/CreateAttributeGroupApiIntegration.php deleted file mode 100644 index 3f1c9aa8..00000000 --- a/tests/v2_0/Api/AttributeGroup/CreateAttributeGroupApiIntegration.php +++ /dev/null @@ -1,79 +0,0 @@ -createClient()->getAttributeGroupApi(); - $response = $api->create( - 'tech', - [ - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'labels' => [ - 'en_US' => 'Tech', - ], - ] - ); - - $this->assertSame(201, $response); - - $attributeGroup = $api->get('tech'); - $this->assertSameContent( - [ - 'code' => 'tech', - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'labels' => [ - 'en_US' => 'Tech', - ], - ], - $attributeGroup - ); - } - - public function testCreateAnExistingAttributeGroup() - { - $api = $this->createClient()->getAttributeGroupApi(); - - try { - $api->create( - 'info', - [ - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ] - ); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame( - [ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], - $exception->getResponseErrors() - ); - } - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidCategory() - { - $api = $this->createClient()->getAttributeGroupApi(); - $api->create( - 'fail', - [ - 'labels' => ['fail'], - ] - ); - } -} diff --git a/tests/v2_0/Api/AttributeGroup/GetAttributeGroupIntegration.php b/tests/v2_0/Api/AttributeGroup/GetAttributeGroupIntegration.php deleted file mode 100644 index 62242e09..00000000 --- a/tests/v2_0/Api/AttributeGroup/GetAttributeGroupIntegration.php +++ /dev/null @@ -1,34 +0,0 @@ -createClient()->getAttributeGroupApi(); - - $attributeGroup = $api->get('info'); - - $this->assertSameContent([ - 'code' => 'info', - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ], $attributeGroup); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getAttributeGroupApi(); - - $api->get('unknown'); - } -} diff --git a/tests/v2_0/Api/AttributeGroup/ListAttributeGroupIntegration.php b/tests/v2_0/Api/AttributeGroup/ListAttributeGroupIntegration.php deleted file mode 100644 index 0e89ca12..00000000 --- a/tests/v2_0/Api/AttributeGroup/ListAttributeGroupIntegration.php +++ /dev/null @@ -1,205 +0,0 @@ -createClient()->getAttributeGroupApi(); - $expectedAttributeGroups = $this->getExpectedAttributeGroups(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $attributeGroups = $firstPage->getItems(); - $this->assertCount(2 ,$attributeGroups); - for ($i = 0; $i < 2; $i++) { - $this->assertSameContent($expectedAttributeGroups[$i], $attributeGroups[$i]); - } - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $attributeGroups = $secondPage->getItems(); - $this->assertCount(2 ,$attributeGroups); - for ($i = 0; $i < 2; $i++) { - $this->assertSameContent($expectedAttributeGroups[2 + $i], $attributeGroups[$i]); - } - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertTrue($lastPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=4&limit=2&with_count=false', $lastPage->getNextLink()); - - $attributeGroups = $lastPage->getItems(); - $this->assertCount(2 ,$attributeGroups); - for ($i = 0; $i < 2; $i++) { - $this->assertSameContent($expectedAttributeGroups[4 + $i], $attributeGroups[$i]); - } - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSameContent($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getAttributeGroupApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(4, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(6, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=2&limit=4&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getAttributeGroupApi(); - $expectedAttributeGroups = $this->getExpectedAttributeGroups(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/attribute-groups?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $attributeGroups = $firstPage->getItems(); - $this->assertCount(2 ,$attributeGroups); - $this->assertSameContent($expectedAttributeGroups[0], $attributeGroups[0]); - $this->assertSameContent($expectedAttributeGroups[1], $attributeGroups[1]); - } - - public function testAll() - { - $api = $this->createClient()->getAttributeGroupApi(); - $attributeGroups = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $attributeGroups); - - $attributeGroups = iterator_to_array($attributeGroups); - - $this->assertCount(6, $attributeGroups); - $this->assertSameContent($this->getExpectedAttributeGroups(), $attributeGroups); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getAttributeGroupApi(); - $attributeGroups = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $attributeGroups); - - $attributeGroups = iterator_to_array($attributeGroups); - - $this->assertCount(6, $attributeGroups); - $this->assertSameContent($this->getExpectedAttributeGroups(), $attributeGroups); - } - - /** - * @return array - */ - protected function getExpectedAttributeGroups() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attribute-groups/colors', - ], - ], - 'code' => 'colors', - 'attributes' => ['color', 'heel_color', 'sole_color'], - 'sort_order' => 4, - 'labels' => [ - 'en_US' => 'Colors', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attribute-groups/info', - ], - ], - 'code' => 'info', - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attribute-groups/marketing', - ], - ], - 'code' => 'marketing', - 'attributes' => ['price'], - 'sort_order' => 2, - 'labels' => [ - 'en_US' => 'Marketing', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attribute-groups/media', - ], - ], - 'code' => 'media', - 'attributes' => ['side_view'], - 'sort_order' => 5, - 'labels' => [ - 'en_US' => 'Media', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attribute-groups/other', - ], - ], - 'code' => 'other', - 'attributes' => ['number_in_stock', 'destocking_date', 'handmade'], - 'sort_order' => 100, - 'labels' => [ - 'en_US' => 'Other', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/attribute-groups/sizes', - ], - ], - 'code' => 'sizes', - 'attributes' => ['size'], - 'sort_order' => 3, - 'labels' => [ - 'en_US' => 'Sizes', - ], - ], - ]; - } -} diff --git a/tests/v2_0/Api/AttributeGroup/UpsertAttributeGroupApiIntegration.php b/tests/v2_0/Api/AttributeGroup/UpsertAttributeGroupApiIntegration.php deleted file mode 100644 index c8ba5a2f..00000000 --- a/tests/v2_0/Api/AttributeGroup/UpsertAttributeGroupApiIntegration.php +++ /dev/null @@ -1,89 +0,0 @@ -createClient()->getAttributeGroupApi(); - - $response = $api->upsert( - 'info', - [ - 'attributes' => ['weather_conditions'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ] - ); - - $this->assertSame(204, $response); - - $attributeGroup = $api->get('info'); - $this->assertSameContent([ - 'code' => 'info', - 'attributes' => ['weather_conditions'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ], $attributeGroup); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getAttributeGroupApi(); - $response = $api->upsert( - 'tech', - [ - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'labels' => [ - 'en_US' => 'Tech', - ], - ] - ); - - $this->assertSame(201, $response); - - $attributeGroup = $api->get('tech'); - $this->assertSameContent([ - 'code' => 'tech', - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'labels' => [ - 'en_US' => 'Tech', - ], - ], $attributeGroup); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getAttributeGroupApi(); - $api->upsert('tech', [ - 'labels' => [ - 'en_US' => ['wrong data type'], - 'fr_FR' => 'Sandales', - ], - ]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getAttributeGroupApi(); - $api->upsert('invalid code !', [ - 'labels' => [ - 'en_US' => 'Invalid code', - 'fr_FR' => 'Code invalide', - ], - ]); - } -} diff --git a/tests/v2_0/Api/AttributeGroup/UpsertListAttributeGroupApiIntegration.php b/tests/v2_0/Api/AttributeGroup/UpsertListAttributeGroupApiIntegration.php deleted file mode 100644 index 9967770e..00000000 --- a/tests/v2_0/Api/AttributeGroup/UpsertListAttributeGroupApiIntegration.php +++ /dev/null @@ -1,120 +0,0 @@ -createClient()->getAttributeGroupApi(); - - $response = $api->upsertList([ - [ - 'code' => 'info', - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ], - [ - 'code' => 'tech', - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'labels' => [ - 'en_US' => 'Tech', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'info', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'tech', - 'status_code' => 201, - ] - ], $responseLines); - } - - public function testUpsertListFromStreamSuccessful() - { - $resourcesContent = - <<getStreamFactory()->createStream($resources); - $api = $this->createClient()->getAttributeGroupApi(); - $response = $api->upsertList($streamedResources); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'info', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'tech', - 'status_code' => 201, - ] - ], $responseLines); - } - - public function testUpsertListFailed() - { - $api = $this->createClient()->getAttributeGroupApi(); - - $response = $api->upsertList([ - [ - 'attributes' => ['sku', 'name', 'manufacturer', 'weather_conditions', 'description', 'length'], - 'sort_order' => 1, - 'labels' => [ - 'en_US' => 'Product information', - ], - ], - [ - 'code' => 'tech', - 'labels' => [ - 'en_US' => 'line too long' . str_repeat('a', 1000000), - 'fr_FR' => 'Tech', - ], - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Code is missing.', - ], - 2 => [ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ] - ], $responseLines); - } -} diff --git a/tests/v2_0/Api/Channel/CreateChannelApiIntegration.php b/tests/v2_0/Api/Channel/CreateChannelApiIntegration.php deleted file mode 100644 index b1e89e2e..00000000 --- a/tests/v2_0/Api/Channel/CreateChannelApiIntegration.php +++ /dev/null @@ -1,88 +0,0 @@ -createClient()->getChannelApi(); - $response = $api->create('paper', [ - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - ]); - - $this->assertSame(201, $response); - - $channel = $api->get('paper'); - $this->assertSameContent( - [ - 'code' => 'paper', - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - ], - $channel - ); - } - - public function testCreateAnExistingChannel() - { - $api = $this->createClient()->getChannelApi(); - - try { - $api->create('ecommerce', [ - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame( - [ - [ - 'property' => 'code', - 'message' => 'This value is already used.', - ], - ], - $exception->getResponseErrors() - ); - } - - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testCreateAnInvalidChannel() - { - $api = $this->createClient()->getChannelApi(); - $api->create( - 'fail', - [ - 'category_tree' => 'unknown_tree', - ] - ); - } -} diff --git a/tests/v2_0/Api/Channel/UpsertChannelApiIntegration.php b/tests/v2_0/Api/Channel/UpsertChannelApiIntegration.php deleted file mode 100644 index 15e89403..00000000 --- a/tests/v2_0/Api/Channel/UpsertChannelApiIntegration.php +++ /dev/null @@ -1,117 +0,0 @@ -createClient()->getChannelApi(); - $response = $api->upsert( - 'ecommerce', - [ - 'currencies' => [ - 'EUR', - ], - 'locales' => [ - 'fr_FR', - ], - 'category_tree' => '2014_collection', - 'labels' => [ - 'en_US' => 'Ecommerce', - 'de_DE' => '', - 'fr_FR' => 'Ecommerce', - ], - ] - ); - - $this->assertSame(204, $response); - - $channel = $api->get('ecommerce'); - $this->assertSameContent( - [ - 'code' => 'ecommerce', - 'currencies' => [ - 'EUR', - ], - 'locales' => [ - 'fr_FR', - ], - 'category_tree' => '2014_collection', - 'conversion_units' => [], - 'labels' => [ - 'en_US' => 'Ecommerce', - 'fr_FR' => 'Ecommerce', - ], - ], - $channel - ); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getChannelApi(); - $response = $api->upsert( - 'paper', - [ - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - 'labels' => [ - 'en_US' => 'Paper', - 'fr_FR' => 'Papier', - ], - ] - ); - - $this->assertSame(201, $response); - - $channel = $api->get('paper'); - $this->assertSameContent( - [ - 'code' => 'paper', - 'currencies' => [ - 'USD', - 'EUR', - ], - 'locales' => [ - 'en_US', - 'fr_FR', - ], - 'category_tree' => '2014_collection', - 'conversion_units' => [], - 'labels' => [ - 'en_US' => 'Paper', - 'fr_FR' => 'Papier', - ], - ], - $channel - ); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertWrongDataTypeFail() - { - $api = $this->createClient()->getChannelApi(); - $api->upsert('paper', ['category_tree' => ['2014_collection']]); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - */ - public function testUpsertInvalidCodeFail() - { - $api = $this->createClient()->getChannelApi(); - $api->upsert('invalid code !'); - } -} diff --git a/tests/v2_0/Api/Channel/UpsertListChannelApiIntegration.php b/tests/v2_0/Api/Channel/UpsertListChannelApiIntegration.php deleted file mode 100644 index 88d09c81..00000000 --- a/tests/v2_0/Api/Channel/UpsertListChannelApiIntegration.php +++ /dev/null @@ -1,86 +0,0 @@ -createClient()->getChannelApi(); - $response = $api->upsertList([ - [ - 'code' => 'ecommerce', - 'labels' => [ - 'en_US' => 'Ecommerce', - 'fr_FR' => 'Ecommerce', - ], - ], - [ - 'code' => 'paper', - 'category_tree' => '2014_collection', - 'currencies' => ['EUR'], - 'locales' => [ - 'fr_FR', - 'en_US', - 'de_DE', - ], - ], - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'code' => 'ecommerce', - 'status_code' => 204, - ], $responseLines[1]); - - $this->assertSame([ - 'line' => 2, - 'code' => 'paper', - 'status_code' => 201, - ], $responseLines[2]); - } - - public function testUpsertListFailed() - { - $api = $this->createClient()->getChannelApi(); - $response = $api->upsertList([ - [ - 'labels' => [ - 'en_US' => 'Ecommerce', - 'fr_FR' => 'Ecommerce', - ], - ], - [ - 'code' => 'mobile', - 'labels' => [ - 'en_US' => 'line too long' . str_repeat('a', 1000000), - 'fr_FR' => 'Course', - ], - ], - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - $this->assertCount(2, $responseLines); - - $this->assertSame([ - 'line' => 1, - 'status_code' => 422, - 'message' => 'Code is missing.', - ], $responseLines[1]); - - $this->assertSame([ - 'line' => 2, - 'status_code' => 413, - 'message' => 'Line is too long.', - ], $responseLines[2]); - } -} diff --git a/tests/v2_0/Api/Currency/GetCurrencyApiIntegration.php b/tests/v2_0/Api/Currency/GetCurrencyApiIntegration.php deleted file mode 100644 index 7a4b0f09..00000000 --- a/tests/v2_0/Api/Currency/GetCurrencyApiIntegration.php +++ /dev/null @@ -1,30 +0,0 @@ -createClient()->getCurrencyApi(); - - $currency = $api->get('EUR'); - - $this->assertSameContent([ - 'code' => 'EUR', - 'enabled' => true, - ], $currency); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getCurrencyApi(); - - $api->get('unknown'); - } -} diff --git a/tests/v2_0/Api/Currency/ListCurrencyApiIntegration.php b/tests/v2_0/Api/Currency/ListCurrencyApiIntegration.php deleted file mode 100644 index e6cd918b..00000000 --- a/tests/v2_0/Api/Currency/ListCurrencyApiIntegration.php +++ /dev/null @@ -1,189 +0,0 @@ -createClient()->getCurrencyApi(); - $expectedCurrencies = $this->getExpectedCurrencies(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(3); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/currencies?page=2&limit=3&with_count=false', $firstPage->getNextLink()); - - $currencies = $firstPage->getItems(); - $this->assertCount(3 ,$currencies); - for ($i = 0; $i < 3; $i++) { - $this->assertSameContent($expectedCurrencies[$i], $currencies[$i]); - } - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/currencies?page=1&limit=3&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/currencies?page=3&limit=3&with_count=false', $secondPage->getNextLink()); - - $currencies = $secondPage->getItems(); - $this->assertCount(3 ,$currencies); - for ($i = 0; $i < 3; $i++) { - $this->assertSameContent($expectedCurrencies[$i + 3], $currencies[$i]); - } - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/currencies?page=2&limit=3&with_count=false', $lastPage->getPreviousLink()); - - $currencies = $lastPage->getItems(); - $this->assertCount(1 ,$currencies); - $this->assertSameContent($expectedCurrencies[6], $currencies[0]); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSameContent($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getCurrencyApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(7, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(7, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/currencies?page=2&limit=7&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getCurrencyApi(); - $expectedCurrencies = $this->getExpectedCurrencies(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/currencies?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $currencies = $firstPage->getItems(); - $this->assertCount(2 ,$currencies); - $this->assertSameContent($expectedCurrencies[0], $currencies[0]); - $this->assertSameContent($expectedCurrencies[1], $currencies[1]); - } - - public function testAll() - { - $api = $this->createClient()->getCurrencyApi(); - $currencies = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $currencies); - - $attributes = iterator_to_array($currencies); - - $this->assertCount(7, $currencies); - $this->assertSameContent($this->getExpectedCurrencies(), $attributes); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getCurrencyApi(); - $currencies = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $currencies); - - $currencies = iterator_to_array($currencies); - - $this->assertCount(7, $currencies); - $this->assertSameContent($this->getExpectedCurrencies(), $currencies); - } - - /** - * @return array - */ - public function getExpectedCurrencies() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/AUD', - ], - ], - 'code' => 'AUD', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/CHF', - ], - ], - 'code' => 'CHF', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/EUR', - ], - ], - 'code' => 'EUR', - 'enabled' => true, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/GBP', - ], - ], - 'code' => 'GBP', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/JPY', - ], - ], - 'code' => 'JPY', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/RUB', - ], - ], - 'code' => 'RUB', - 'enabled' => false, - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/currencies/USD', - ], - ], - 'code' => 'USD', - 'enabled' => true, - ], - ]; - } -} diff --git a/tests/v2_0/Api/Family/GetFamilyApiIntegration.php b/tests/v2_0/Api/Family/GetFamilyApiIntegration.php deleted file mode 100644 index 7c7ecdd0..00000000 --- a/tests/v2_0/Api/Family/GetFamilyApiIntegration.php +++ /dev/null @@ -1,51 +0,0 @@ -createClient()->getFamilyApi(); - $family = $api->get('boots'); - - $expectedFamily = [ - 'code' => 'boots', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - 'weather_conditions' - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots', - 'fr_FR' => 'Bottes', - ], - ]; - - $this->assertSameContent($expectedFamily, $family); - } -} diff --git a/tests/v2_0/Api/Family/ListFamilyApiIntegration.php b/tests/v2_0/Api/Family/ListFamilyApiIntegration.php deleted file mode 100644 index b0e4e6e4..00000000 --- a/tests/v2_0/Api/Family/ListFamilyApiIntegration.php +++ /dev/null @@ -1,258 +0,0 @@ -createClient()->getFamilyApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedFamilies = $this->getExpectedFamilies(); - - $firstPage = $api->listPerPage(2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $families = $firstPage->getItems(); - $this->assertCount(2 ,$families); - $this->assertSameContent($expectedFamilies[0], $families[0]); - $this->assertSameContent($expectedFamilies[1], $families[1]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $families = $secondPage->getItems(); - $this->assertCount(2 ,$families); - $this->assertSameContent($expectedFamilies[2], $families[0]); - $this->assertSameContent($expectedFamilies[3], $families[1]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/families?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - - $families = $lastPage->getItems(); - $this->assertCount(0 ,$families); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getFamilyApi(); - $expectedFamilies = $this->getExpectedFamilies(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/families?page=2&limit=2&with_count=false&foo=bar', $firstPage->getNextLink()); - - $families = $firstPage->getItems(); - $this->assertCount(2 ,$families); - $this->assertSameContent($expectedFamilies[0], $families[0]); - $this->assertSameContent($expectedFamilies[1], $families[1]); - } - - public function testAll() - { - $api = $this->createClient()->getFamilyApi(); - $families = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $families); - - $families = iterator_to_array($families); - - $this->assertCount(4, $families); - $this->assertSameContent($this->getExpectedFamilies(), $families); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getFamilyApi(); - $families = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $families); - - $families = iterator_to_array($families); - - $this->assertCount(4, $families); - $this->assertSameContent($this->getExpectedFamilies(), $families); - } - - /** - * @return array - */ - protected function getExpectedFamilies() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/boots', - ], - ], - 'code' => 'boots', - 'attributes' => [ - 'color', - 'description', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - 'weather_conditions', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Boots', - 'fr_FR' => 'Bottes', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/heels', - ], - ], - 'code' => 'heels', - 'attributes' => [ - 'manufacturer', - 'name', - 'price', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'name', - 'price', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Heels', - 'fr_FR' => 'Talons', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/sandals', - ], - ], - 'code' => 'sandals', - 'attributes' => [ - 'color', - 'description', - 'destocking_date', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'description', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Sandals', - 'fr_FR' => 'Sandales', - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/sneakers', - ], - ], - 'code' => 'sneakers', - 'attributes' => [ - 'color', - 'description', - 'length', - 'manufacturer', - 'name', - 'price', - 'side_view', - 'size', - 'sku', - 'weather_conditions', - ], - 'attribute_as_label' => 'name', - 'attribute_requirements' => [ - 'ecommerce' => [ - 'color', - 'name', - 'price', - 'size', - 'sku', - ], - 'mobile' => [ - 'name', - 'sku', - ], - ], - 'labels' => [ - 'en_US' => 'Sneakers', - 'fr_FR' => 'Sneakers', - ], - ], - ]; - } -} diff --git a/tests/v2_0/Api/FamilyVariant/CreateFamilyVariantApiIntegration.php b/tests/v2_0/Api/FamilyVariant/CreateFamilyVariantApiIntegration.php deleted file mode 100644 index 74408fd9..00000000 --- a/tests/v2_0/Api/FamilyVariant/CreateFamilyVariantApiIntegration.php +++ /dev/null @@ -1,68 +0,0 @@ -createClient()->getFamilyVariantApi(); - $data = [ - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Boots by color and size', - 'fr_FR' => 'Bottes par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['size'], - 'attributes' => [ - 'name', - 'description', - 'size' - ] - ], - [ - 'level' => 2, - 'axes' => ['color'], - 'attributes' => ['sku', 'color'] - ] - ] - ]; - $response = $api->create('boots', 'super_boots_color_size', $data); - $this->assertSame(201, $response); - - $familyVariant = $api->get('boots', 'super_boots_color_size'); - - $data['code'] = 'super_boots_color_size'; - $this->assertSameContent($data, $familyVariant); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - * @expectedExceptionMessage Validation failed - */ - public function testFailedToCreateAFamilyVariant() - { - $api = $this->createClient()->getFamilyVariantApi(); - $data = [ - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Boots by color and size', - 'fr_FR' => 'Bottes par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 2, - 'axes' => ['color'], - 'attributes' => ['sku', 'color'] - ] - ] - ]; - $response = $api->create('boots', 'boots_size_color', $data); - $this->assertSame(422, $response); - } -} diff --git a/tests/v2_0/Api/FamilyVariant/GetFamilyVariantApiIntegration.php b/tests/v2_0/Api/FamilyVariant/GetFamilyVariantApiIntegration.php deleted file mode 100644 index 019d3c24..00000000 --- a/tests/v2_0/Api/FamilyVariant/GetFamilyVariantApiIntegration.php +++ /dev/null @@ -1,61 +0,0 @@ -createClient()->getFamilyVariantApi(); - - $familyVariant = $api->get('boots', 'rain_boots_color_size'); - - $expected = [ - 'code' => 'rain_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Rain boots by color and size', - 'fr_FR' => 'Bottes de pluie par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => [ - 'name', - 'description', - 'side_view', - 'color' - ] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ]; - - $this->assertSameContent($expected, $familyVariant); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - * @expectedExceptionMessage Family variant "trololo" does not exist or is not a variant of the family "boots". - */ - public function testFamilyVariantNotFound() - { - $this->createClient()->getFamilyVariantApi()->get('boots', 'trololo'); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - * @expectedExceptionMessage Family "trololo" does not exist. - */ - public function testFamilyNotFound() - { - $this->createClient()->getFamilyVariantApi()->get('trololo', 'rain_boots_color_size'); - } -} diff --git a/tests/v2_0/Api/FamilyVariant/ListFamilyVariantApiIntegration.php b/tests/v2_0/Api/FamilyVariant/ListFamilyVariantApiIntegration.php deleted file mode 100644 index fa91b485..00000000 --- a/tests/v2_0/Api/FamilyVariant/ListFamilyVariantApiIntegration.php +++ /dev/null @@ -1,195 +0,0 @@ -createClient()->getFamilyVariantApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedFamilyVariants = $this->getExpectedFamilyVariants(); - - $firstPage = $api->listPerPage('boots', 2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/families/boots/variants?page=2&limit=2&with_count=false', $firstPage->getNextLink()); - - $familyVariants = $firstPage->getItems(); - $this->assertCount(2 ,$familyVariants); - $this->assertSameContent($expectedFamilyVariants[0], $familyVariants[0]); - $this->assertSameContent($expectedFamilyVariants[1], $familyVariants[1]); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/families/boots/variants?page=1&limit=2&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/families/boots/variants?page=3&limit=2&with_count=false', $secondPage->getNextLink()); - - $familyVariants = $secondPage->getItems(); - $this->assertCount(2 ,$familyVariants); - $this->assertSameContent($expectedFamilyVariants[2], $familyVariants[0]); - $this->assertSameContent($expectedFamilyVariants[3], $familyVariants[1]); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/families/boots/variants?page=2&limit=2&with_count=false', $lastPage->getPreviousLink()); - - $familyVariants = $lastPage->getItems(); - $this->assertCount(0 ,$familyVariants); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testAll() - { - $api = $this->createClient()->getFamilyVariantApi(); - $familyVariants = $api->all('boots'); - - $this->assertInstanceOf(ResourceCursorInterface::class, $familyVariants); - - $familyVariants = iterator_to_array($familyVariants); - - $this->assertCount(4, $familyVariants); - $this->assertSameContent($this->getExpectedFamilyVariants(), $familyVariants); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getFamilyVariantApi(); - $familyVariants = $api->all('boots', 10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $familyVariants); - - $familyVariants = iterator_to_array($familyVariants); - - $this->assertCount(4, $familyVariants); - $this->assertSameContent($this->getExpectedFamilyVariants(), $familyVariants); - } - - /** - * @return array - */ - protected function getExpectedFamilyVariants() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/boots/variants/city_boots_color_size', - ], - ], - 'code' => 'city_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'City boots by color and size', - 'fr_FR' => 'Bottes de ville par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => ['name', 'description', 'side_view', 'color'] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/boots/variants/man_boots_color_size', - ] - ], - 'code' => 'man_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Man boots by color and size', - 'fr_FR' => 'Bottes homme par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => ['name', 'description', 'side_view', 'color'] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'], - ] - ] - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/boots/variants/rain_boots_color_size' - ] - ], - 'code' => 'rain_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Rain boots by color and size', - 'fr_FR' => 'Bottes de pluie par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => ['name', 'description', 'side_view', 'color'] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/families/boots/variants/woman_boots_color_size' - ] - ], - 'code' => 'woman_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Woman boots by color and size', - 'fr_FR' => 'Bottes femme par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => ['name', 'description', 'side_view', 'color'] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ] - ]; - } -} diff --git a/tests/v2_0/Api/FamilyVariant/UpsertFamilyVariantApiIntegration.php b/tests/v2_0/Api/FamilyVariant/UpsertFamilyVariantApiIntegration.php deleted file mode 100644 index 76bbd048..00000000 --- a/tests/v2_0/Api/FamilyVariant/UpsertFamilyVariantApiIntegration.php +++ /dev/null @@ -1,87 +0,0 @@ -createClient()->getFamilyVariantApi(); - - $response = $api->upsert('boots', 'rain_boots_color_size', [ - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe.', - 'en_US' => 'Rain boots better use it during rain.', - 'fr_FR' => 'Bottes de pluie à utiliser pendant la pluie.' - ] - ]); - - $this->assertSame(204, $response); - - $familyVariant = $api->get('boots', 'rain_boots_color_size'); - - $this->assertSameContent([ - 'code' => 'rain_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe.', - 'en_US' => 'Rain boots better use it during rain.', - 'fr_FR' => 'Bottes de pluie à utiliser pendant la pluie.' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => [ - 'name', - 'description', - 'side_view', - 'color' - ] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ], $familyVariant); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getFamilyVariantApi(); - $data = [ - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'Boots by color and size', - 'fr_FR' => 'Bottes par couleur et taille' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['size'], - 'attributes' => [ - 'name', - 'description', - 'size' - ] - ], - [ - 'level' => 2, - 'axes' => ['color'], - 'attributes' => ['sku', 'color'] - ] - ] - ]; - $response = $api->upsert('boots', 'super_boots_color_size', $data); - - $this->assertSame(201, $response); - sleep(10); - $familyVariant = $api->get('boots', 'super_boots_color_size'); - - $data['code'] = 'super_boots_color_size'; - $this->assertSameContent($data, $familyVariant); - } -} diff --git a/tests/v2_0/Api/FamilyVariant/UpsertListOfFamilyVariantsApiIntegration.php b/tests/v2_0/Api/FamilyVariant/UpsertListOfFamilyVariantsApiIntegration.php deleted file mode 100644 index 7dfbd551..00000000 --- a/tests/v2_0/Api/FamilyVariant/UpsertListOfFamilyVariantsApiIntegration.php +++ /dev/null @@ -1,136 +0,0 @@ -createClient()->getFamilyVariantApi(); - - $response = $api->upsertList('boots', [ - [ - 'code' => 'rain_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'test update', - 'fr_FR' => 'test update' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => [ - 'name', - 'description', - 'side_view', - 'color' - ] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ], - [ - 'code' => 'man_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'test fail', - 'fr_FR' => 'test fail' - ], - 'variant_attribute_sets' => [] - ], - [ - 'code' => 'create_boots_color_size', - 'labels' => [ - 'de_DE' => 'Stiefel nach Farbe und Größe', - 'en_US' => 'test create', - 'fr_FR' => 'test create' - ], - 'variant_attribute_sets' => [ - [ - 'level' => 1, - 'axes' => ['color'], - 'attributes' => [ - 'name', - 'description', - 'side_view', - 'color' - ] - ], - [ - 'level' => 2, - 'axes' => ['size'], - 'attributes' => ['sku', 'size'] - ] - ] - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'rain_boots_color_size', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'man_boots_color_size', - 'status_code' => 422, - 'message' => 'The number of variant attribute sets cannot be changed. Check the expected format on the API documentation.', - '_links' => [ - 'documentation' => [ - 'href' => 'http://api.akeneo.com/api-reference.html#patch_families__family_code__variants__code__' - ] - ] - ], - 3 => [ - 'line' => 3, - 'code' => 'create_boots_color_size', - 'status_code' => 201, - ], - ], $responseLines); - } - - public function testUpsertListFromStreamSuccessful() - { - $resourcesContent = - <<getStreamFactory()->createStream($resources); - $api = $this->createClient()->getFamilyVariantApi(); - $response = $api->upsertList('boots', $streamedResources); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'rain_boots_color_size', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'man_boots_color_size', - 'status_code' => 204, - ], - ], $responseLines); - } -} diff --git a/tests/v2_0/Api/MeasureFamily/GetMeasureFamilyIntegration.php b/tests/v2_0/Api/MeasureFamily/GetMeasureFamilyIntegration.php deleted file mode 100644 index 16078972..00000000 --- a/tests/v2_0/Api/MeasureFamily/GetMeasureFamilyIntegration.php +++ /dev/null @@ -1,161 +0,0 @@ -createClient()->getMeasureFamilyApi(); - - $measureFamily = $api->get('area'); - - $this->assertSameContent( - [ - 'code' => 'area', - 'standard' => 'SQUARE_METER', - 'units' => [ - [ - 'code' => 'SQUARE_MILLIMETER', - 'convert' => [ - 'mul' => '0.000001', - ], - 'symbol' => 'mm²', - ], - [ - 'code' => 'SQUARE_CENTIMETER', - 'convert' => [ - 'mul' => '0.0001', - ], - 'symbol' => 'cm²', - ], - [ - 'code' => 'SQUARE_DECIMETER', - 'convert' => [ - 'mul' => '0.01', - ], - 'symbol' => 'dm²', - ], - [ - 'code' => 'SQUARE_METER', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'm²', - ], - [ - 'code' => 'CENTIARE', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'ca', - ], - [ - 'code' => 'SQUARE_DEKAMETER', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'dam²', - ], - [ - 'code' => 'ARE', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'a', - ], - [ - 'code' => 'SQUARE_HECTOMETER', - 'convert' => [ - 'mul' => '10000', - ], - 'symbol' => 'hm²', - ], - [ - 'code' => 'HECTARE', - 'convert' => [ - 'mul' => '10000', - ], - 'symbol' => 'ha', - ], - [ - 'code' => 'SQUARE_KILOMETER', - 'convert' => [ - 'mul' => '1000000', - ], - 'symbol' => 'km²', - ], - [ - 'code' => 'SQUARE_MIL', - 'convert' => [ - 'mul' => '0.00000000064516', - ], - 'symbol' => 'sq mil', - ], - [ - 'code' => 'SQUARE_INCH', - 'convert' => [ - 'mul' => '0.00064516', - ], - 'symbol' => 'in²', - ], - [ - 'code' => 'SQUARE_FOOT', - 'convert' => [ - 'mul' => '0.09290304', - ], - 'symbol' => 'ft²', - ], - [ - 'code' => 'SQUARE_YARD', - 'convert' => [ - 'mul' => '0.83612736', - ], - 'symbol' => 'yd²', - ], - [ - 'code' => 'ARPENT', - 'convert' => [ - 'mul' => '3418.89', - ], - 'symbol' => 'arpent', - ], - [ - 'code' => 'ACRE', - 'convert' => [ - 'mul' => '4046.856422', - ], - 'symbol' => 'A', - ], - [ - 'code' => 'SQUARE_FURLONG', - 'convert' => [ - 'mul' => '40468.726', - ], - 'symbol' => 'fur²', - ], - [ - 'code' => 'SQUARE_MILE', - 'convert' => [ - 'mul' => '2589988.110336', - ], - 'symbol' => 'mi²', - ], - ], - ], - $measureFamily - ); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - */ - public function testGetNotFound() - { - $api = $this->createClient()->getMeasureFamilyApi(); - - $api->get('unknown'); - } -} diff --git a/tests/v2_0/Api/MeasureFamily/ListMeasureFamilyIntegration.php b/tests/v2_0/Api/MeasureFamily/ListMeasureFamilyIntegration.php deleted file mode 100644 index 007754d6..00000000 --- a/tests/v2_0/Api/MeasureFamily/ListMeasureFamilyIntegration.php +++ /dev/null @@ -1,1335 +0,0 @@ -createClient()->getMeasureFamilyApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $expectedMeasureFamilies = $this->getExpectedMeasureFamilies(); - - $firstPage = $api->listPerPage(5); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=2&limit=5&with_count=false', $firstPage->getNextLink()); - - $measureFamilies = $firstPage->getItems(); - $this->assertCount(5 ,$measureFamilies); - for ($i = 0; $i < 5; $i++) { - $this->assertSameContent($expectedMeasureFamilies[$i], $measureFamilies[$i]); - } - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=1&limit=5&with_count=false', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=3&limit=5&with_count=false', $secondPage->getNextLink()); - - $measureFamilies = $secondPage->getItems(); - $this->assertCount(5 ,$measureFamilies); - for ($i = 0; $i < 5; $i++) { - $this->assertSameContent($expectedMeasureFamilies[5 + $i], $measureFamilies[$i]); - } - - $thirdPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $thirdPage); - $this->assertTrue($thirdPage->hasPreviousPage()); - $this->assertTrue($thirdPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=2&limit=5&with_count=false', $thirdPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=4&limit=5&with_count=false', $thirdPage->getNextLink()); - - $measureFamilies = $thirdPage->getItems(); - $this->assertCount(5 ,$measureFamilies); - for ($i = 0; $i < 5; $i++) { - $this->assertSameContent($expectedMeasureFamilies[10 + $i], $measureFamilies[$i]); - } - - $lastPage = $thirdPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=3&limit=5&with_count=false', $lastPage->getPreviousLink()); - - $measureFamilies = $lastPage->getItems(); - $this->assertCount(3 ,$measureFamilies); - for ($i = 0; $i < 3; $i++) { - $this->assertSameContent($expectedMeasureFamilies[15 + $i], $measureFamilies[$i]); - } - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($thirdPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getMeasureFamilyApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(10, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(18, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=2&limit=10&with_count=true', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getMeasureFamilyApi(); - $expectedMeasureFamilies = $this->getExpectedMeasureFamilies(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(1, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/measure-families?page=2&limit=1&with_count=false&foo=bar', $firstPage->getNextLink()); - - $measureFamilies = $firstPage->getItems(); - $this->assertCount(1 ,$measureFamilies); - $this->assertSameContent($expectedMeasureFamilies[0], $measureFamilies[0]); - } - - public function testAll() - { - $api = $this->createClient()->getMeasureFamilyApi(); - $measureFamilies = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $measureFamilies); - - $measureFamilies = iterator_to_array($measureFamilies); - - $this->assertCount(18, $measureFamilies); - $this->assertSameContent($this->getExpectedMeasureFamilies(), $measureFamilies); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getMeasureFamilyApi(); - $measureFamilies = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $measureFamilies); - - $measureFamilies = iterator_to_array($measureFamilies); - - $this->assertCount(18, $measureFamilies); - $this->assertSameContent($this->getExpectedMeasureFamilies(), $measureFamilies); - } - - public function getExpectedMeasureFamilies() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/area', - ], - ], - 'code' => 'area', - 'standard' => 'SQUARE_METER', - 'units' => [ - [ - 'code' => 'SQUARE_MILLIMETER', - 'convert' => [ - 'mul' => '0.000001', - ], - 'symbol' => 'mm²', - ], - [ - 'code' => 'SQUARE_CENTIMETER', - 'convert' => [ - 'mul' => '0.0001', - ], - 'symbol' => 'cm²', - ], - [ - 'code' => 'SQUARE_DECIMETER', - 'convert' => [ - 'mul' => '0.01', - ], - 'symbol' => 'dm²', - ], - [ - 'code' => 'SQUARE_METER', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'm²', - ], - [ - 'code' => 'CENTIARE', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'ca', - ], - [ - 'code' => 'SQUARE_DEKAMETER', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'dam²', - ], - [ - 'code' => 'ARE', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'a', - ], - [ - 'code' => 'SQUARE_HECTOMETER', - 'convert' => [ - 'mul' => '10000', - ], - 'symbol' => 'hm²', - ], - [ - 'code' => 'HECTARE', - 'convert' => [ - 'mul' => '10000', - ], - 'symbol' => 'ha', - ], - [ - 'code' => 'SQUARE_KILOMETER', - 'convert' => [ - 'mul' => '1000000', - ], - 'symbol' => 'km²', - ], - [ - 'code' => 'SQUARE_MIL', - 'convert' => [ - 'mul' => '0.00000000064516', - ], - 'symbol' => 'sq mil', - ], - [ - 'code' => 'SQUARE_INCH', - 'convert' => [ - 'mul' => '0.00064516', - ], - 'symbol' => 'in²', - ], - [ - 'code' => 'SQUARE_FOOT', - 'convert' => [ - 'mul' => '0.09290304', - ], - 'symbol' => 'ft²', - ], - [ - 'code' => 'SQUARE_YARD', - 'convert' => [ - 'mul' => '0.83612736', - ], - 'symbol' => 'yd²', - ], - [ - 'code' => 'ARPENT', - 'convert' => [ - 'mul' => '3418.89', - ], - 'symbol' => 'arpent', - ], - [ - 'code' => 'ACRE', - 'convert' => [ - 'mul' => '4046.856422', - ], - 'symbol' => 'A', - ], - [ - 'code' => 'SQUARE_FURLONG', - 'convert' => [ - 'mul' => '40468.726', - ], - 'symbol' => 'fur²', - ], - [ - 'code' => 'SQUARE_MILE', - 'convert' => [ - 'mul' => '2589988.110336', - ], - 'symbol' => 'mi²', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/binary', - ], - ], - 'code' => 'binary', - 'standard' => 'BYTE', - 'units' => [ - [ - 'code' => 'BIT', - 'convert' => [ - 'mul' => '0.125', - ], - 'symbol' => 'b', - ], - [ - 'code' => 'BYTE', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'B', - ], - [ - 'code' => 'KILOBYTE', - 'convert' => [ - 'mul' => '1024', - ], - 'symbol' => 'kB', - ], - [ - 'code' => 'MEGABYTE', - 'convert' => [ - 'mul' => '1048576', - ], - 'symbol' => 'MB', - ], - [ - 'code' => 'GIGABYTE', - 'convert' => [ - 'mul' => '1073741824', - ], - 'symbol' => 'GB', - ], - [ - 'code' => 'TERABYTE', - 'convert' => [ - 'mul' => '1099511627776', - ], - 'symbol' => 'TB', - ], - ] - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/decibel', - ], - ], - 'code' => 'decibel', - 'standard' => 'DECIBEL', - 'units' => [ - [ - 'code' => 'DECIBEL', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'dB', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/frequency', - ], - ], - 'code' => 'frequency', - 'standard' => 'HERTZ', - 'units' => [ - [ - 'code' => 'HERTZ', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'Hz', - ], - [ - 'code' => 'KILOHERTZ', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'kHz', - ], - [ - 'code' => 'MEGAHERTZ', - 'convert' => [ - 'mul' => '1000000', - ], - 'symbol' => 'MHz', - ], - [ - 'code' => 'GIGAHERTZ', - 'convert' => [ - 'mul' => '1000000000', - ], - 'symbol' => 'GHz', - ], - [ - 'code' => 'TERAHERTZ', - 'convert' => [ - 'mul' => '1000000000000', - ], - 'symbol' => 'THz', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/length', - ], - ], - 'code' => 'length', - 'standard' => 'METER', - 'units' => [ - [ - 'code' => 'MILLIMETER', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'mm', - ], - [ - 'code' => 'CENTIMETER', - 'convert' => [ - 'mul' => '0.01', - ], - 'symbol' => 'cm', - ], - [ - 'code' => 'DECIMETER', - 'convert' => [ - 'mul' => '0.1', - ], - 'symbol' => 'dm', - ], - [ - 'code' => 'METER', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'm', - ], - [ - 'code' => 'DEKAMETER', - 'convert' => [ - 'mul' => '10', - ], - 'symbol' => 'dam', - ], - [ - 'code' => 'HECTOMETER', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'hm', - ], - [ - 'code' => 'KILOMETER', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'km', - ], - [ - 'code' => 'MIL', - 'convert' => [ - 'mul' => '0.0000254', - ], - 'symbol' => 'mil', - ], - [ - 'code' => 'INCH', - 'convert' => [ - 'mul' => '0.0254', - ], - 'symbol' => 'in', - ], - [ - 'code' => 'FEET', - 'convert' => [ - 'mul' => '0.3048', - ], - 'symbol' => 'ft', - ], - [ - 'code' => 'YARD', - 'convert' => [ - 'mul' => '0.9144', - ], - 'symbol' => 'yd', - ], - [ - 'code' => 'CHAIN', - 'convert' => [ - 'mul' => '20.1168', - ], - 'symbol' => 'ch', - ], - [ - 'code' => 'FURLONG', - 'convert' => [ - 'mul' => '201.168', - ], - 'symbol' => 'fur', - ], - [ - 'code' => 'MILE', - 'convert' => [ - 'mul' => '1609.344', - ], - 'symbol' => 'mi', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/power', - ], - ], - 'code' => 'power', - 'standard' => 'WATT', - 'units' => [ - [ - 'code' => 'WATT', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'W', - ], - [ - 'code' => 'KILOWATT', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'kW', - ], - [ - 'code' => 'MEGAWATT', - 'convert' => [ - 'mul' => '1000000', - ], - 'symbol' => 'MW', - ], - [ - 'code' => 'GIGAWATT', - 'convert' => [ - 'mul' => '1000000000', - ], - 'symbol' => 'GW', - ], - [ - 'code' => 'TERAWATT', - 'convert' => [ - 'mul' => '1000000000000', - ], - 'symbol' => 'TW', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/voltage', - ], - ], - 'code' => 'voltage', - 'standard' => 'VOLT', - 'units' => [ - [ - 'code' => 'MILLIVOLT', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'mV', - ], - [ - 'code' => 'CENTIVOLT', - 'convert' => [ - 'mul' => '0.01', - ], - 'symbol' => 'cV', - ], - [ - 'code' => 'DECIVOLT', - 'convert' => [ - 'mul' => '0.1', - ], - 'symbol' => 'dV', - ], - [ - 'code' => 'VOLT', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'V', - ], - [ - 'code' => 'DEKAVOLT', - 'convert' => [ - 'mul' => '10', - ], - 'symbol' => 'daV', - ], - [ - 'code' => 'HECTOVOLT', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'hV', - ], - [ - 'code' => 'KILOVOLT', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'kV', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/intensity', - ], - ], - 'code' => 'intensity', - 'standard' => 'AMPERE', - 'units' => [ - [ - 'code' => 'MILLIAMPERE', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'mA', - ], - [ - 'code' => 'CENTIAMPERE', - 'convert' => [ - 'mul' => '0.01', - ], - 'symbol' => 'cA', - ], - [ - 'code' => 'DECIAMPERE', - 'convert' => [ - 'mul' => '0.1', - ], - 'symbol' => 'dA', - ], - [ - 'code' => 'AMPERE', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'A', - ], - [ - 'code' => 'DEKAMPERE', - 'convert' => [ - 'mul' => '10', - ], - 'symbol' => 'daA', - ], - [ - 'code' => 'HECTOAMPERE', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'hA', - ], - [ - 'code' => 'KILOAMPERE', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'kA', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/resistance', - ], - ], - 'code' => 'resistance', - 'standard' => 'OHM', - 'units' => [ - [ - 'code' => 'MILLIOHM', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'mΩ', - ], - [ - 'code' => 'CENTIOHM', - 'convert' => [ - 'mul' => '0.01', - ], - 'symbol' => 'cΩ', - ], - [ - 'code' => 'DECIOHM', - 'convert' => [ - 'mul' => '0.1', - ], - 'symbol' => 'dΩ', - ], - [ - 'code' => 'OHM', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'Ω', - ], - [ - 'code' => 'DEKAOHM', - 'convert' => [ - 'mul' => '10', - ], - 'symbol' => 'daΩ', - ], - [ - 'code' => 'HECTOHM', - 'convert' => [ - 'mul' => '100', - ], - 'symbol' => 'hΩ', - ], - [ - 'code' => 'KILOHM', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'kΩ', - ], - [ - 'code' => 'MEGOHM', - 'convert' => [ - 'mul' => '1000000', - ], - 'symbol' => 'MΩ', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/speed', - ], - ], - 'code' => 'speed', - 'standard' => 'METER_PER_SECOND', - 'units' => [ - [ - 'code' => 'METER_PER_SECOND', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'mdivs', - ], - [ - 'code' => 'METER_PER_MINUTE', - 'convert' => [ - 'div' => '60', - ], - 'symbol' => 'mdivm', - ], - [ - 'code' => 'METER_PER_HOUR', - 'convert' => [ - 'mul' => '1', - 'div' => '3600', - ], - 'symbol' => 'mdivh', - ], - [ - 'code' => 'KILOMETER_PER_HOUR', - 'convert' => [ - 'mul' => '1000', - 'div' => '3600', - ], - 'symbol' => 'kmdivh', - ], - [ - 'code' => 'FOOT_PER_SECOND', - 'convert' => [ - 'mul' => '0.3048', - ], - 'symbol' => 'ftdivs', - ], - [ - 'code' => 'FOOT_PER_HOUR', - 'convert' => [ - 'mul' => '0.3048', - 'div' => '3600', - ], - 'symbol' => 'ftdivh', - ], - [ - 'code' => 'YARD_PER_HOUR', - 'convert' => [ - 'mul' => '0.9144', - 'div' => '3600', - ], - 'symbol' => 'yddivh', - ], - [ - 'code' => 'MILE_PER_HOUR', - 'convert' => [ - 'mul' => '1609.344', - 'div' => '3600', - ], - 'symbol' => 'midivh', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/electriccharge', - ], - ], - 'code' => 'electriccharge', - 'standard' => 'AMPEREHOUR', - 'units' => [ - [ - 'code' => 'MILLIAMPEREHOUR', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'mAh', - ], - [ - 'code' => 'AMPEREHOUR', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'Ah', - ], - [ - 'code' => 'MILLICOULOMB', - 'convert' => [ - 'div' => '3600000', - ], - 'symbol' => 'mC', - ], - [ - 'code' => 'CENTICOULOMB', - 'convert' => [ - 'div' => '360000', - ], - 'symbol' => 'cC', - ], - [ - 'code' => 'DECICOULOMB', - 'convert' => [ - 'div' => '36000', - ], - 'symbol' => 'dC', - ], - [ - 'code' => 'COULOMB', - 'convert' => [ - 'div' => '3600', - ], - 'symbol' => 'C', - ], - [ - 'code' => 'DEKACOULOMB', - 'convert' => [ - 'div' => '360', - ], - 'symbol' => 'daC', - ], - [ - 'code' => 'HECTOCOULOMB', - 'convert' => [ - 'div' => '36', - ], - 'symbol' => 'hC', - ], - [ - 'code' => 'KILOCOULOMB', - 'convert' => [ - 'div' => '3.6', - ], - 'symbol' => 'kC', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/duration', - ], - ], - 'code' => 'duration', - 'standard' => 'SECOND', - 'units' => [ - [ - 'code' => 'MILLISECOND', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'ms', - ], - [ - 'code' => 'SECOND', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 's', - ], - [ - 'code' => 'MINUTE', - 'convert' => [ - 'mul' => '60', - ], - 'symbol' => 'm', - ], - [ - 'code' => 'HOUR', - 'convert' => [ - 'mul' => '3600', - ], - 'symbol' => 'h', - ], - [ - 'code' => 'DAY', - 'convert' => [ - 'mul' => '86400', - ], - 'symbol' => 'd', - ], - [ - 'code' => 'WEEK', - 'convert' => [ - 'mul' => '604800', - ], - 'symbol' => 'week', - ], - [ - 'code' => 'MONTH', - 'convert' => [ - 'mul' => '18748800', - ], - 'symbol' => 'month', - ], - [ - 'code' => 'YEAR', - 'convert' => [ - 'mul' => '31536000', - ], - 'symbol' => 'year', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/temperature', - ], - ], - 'code' => 'temperature', - 'standard' => 'KELVIN', - 'units' => [ - [ - 'code' => 'CELSIUS', - 'convert' => [ - 'add' => '273.15', - ], - 'symbol' => '°C', - ], - [ - 'code' => 'FAHRENHEIT', - 'convert' => [ - 'sub' => '32', - 'div' => '1.8', - 'add' => '273.15', - ], - 'symbol' => '°F', - ], - [ - 'code' => 'KELVIN', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => '°K', - ], - [ - 'code' => 'RANKINE', - 'convert' => [ - 'div' => '1.8', - ], - 'symbol' => '°R', - ], - [ - 'code' => 'REAUMUR', - 'convert' => [ - 'mul' => '1.25', - 'add' => '273.15', - ], - 'symbol' => '°r', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/volume', - ], - ], - 'code' => 'volume', - 'standard' => 'CUBIC_METER', - 'units' => [ - [ - 'code' => 'CUBIC_MILLIMETER', - 'convert' => [ - 'mul' => '0.000000001', - ], - 'symbol' => 'mm³', - ], - [ - 'code' => 'CUBIC_CENTIMETER', - 'convert' => [ - 'mul' => '0.000001', - ], - 'symbol' => 'cm³', - ], - [ - 'code' => 'MILLILITER', - 'convert' => [ - 'mul' => '0.000001', - ], - 'symbol' => 'ml', - ], - [ - 'code' => 'CENTILITER', - 'convert' => [ - 'mul' => '0.00001', - ], - 'symbol' => 'cl', - ], - [ - 'code' => 'DECILITER', - 'convert' => [ - 'mul' => '0.0001', - ], - 'symbol' => 'dl', - ], - [ - 'code' => 'CUBIC_DECIMETER', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'dm³', - ], - [ - 'code' => 'LITER', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'l', - ], - [ - 'code' => 'CUBIC_METER', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'm³', - ], - [ - 'code' => 'OUNCE', - 'convert' => [ - 'mul' => '0.00454609', - 'div' => '160', - ], - 'symbol' => 'oz', - ], - [ - 'code' => 'PINT', - 'convert' => [ - 'mul' => '0.00454609', - 'div' => '8', - ], - 'symbol' => 'pt', - ], - [ - 'code' => 'BARREL', - 'convert' => [ - 'mul' => '0.16365924', - ], - 'symbol' => 'bbl', - ], - [ - 'code' => 'GALLON', - 'convert' => [ - 'mul' => '0.00454609', - ], - 'symbol' => 'gal', - ], - [ - 'code' => 'CUBIC_FOOT', - 'convert' => [ - 'mul' => '6.54119159', - 'div' => '231', - ], - 'symbol' => 'ft³', - ], - [ - 'code' => 'CUBIC_INCH', - 'convert' => [ - 'mul' => '0.0037854118', - 'div' => '231', - ], - 'symbol' => 'in³', - ], - [ - 'code' => 'CUBIC_YARD', - 'convert' => [ - 'mul' => '0.764554861', - ], - 'symbol' => 'yd³', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/weight', - ], - ], - 'code' => 'weight', - 'standard' => 'KILOGRAM', - 'units' => [ - [ - 'code' => 'MILLIGRAM', - 'convert' => [ - 'mul' => '0.000001', - ], - 'symbol' => 'mg', - ], - [ - 'code' => 'GRAM', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'g', - ], - [ - 'code' => 'KILOGRAM', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'kg', - ], - [ - 'code' => 'TON', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 't', - ], - [ - 'code' => 'GRAIN', - 'convert' => [ - 'mul' => '0.00006479891', - ], - 'symbol' => 'gr', - ], - [ - 'code' => 'DENIER', - 'convert' => [ - 'mul' => '0.001275', - ], - 'symbol' => 'denier', - ], - [ - 'code' => 'ONCE', - 'convert' => [ - 'mul' => '0.03059', - ], - 'symbol' => 'once', - ], - [ - 'code' => 'MARC', - 'convert' => [ - 'mul' => '0.24475', - ], - 'symbol' => 'marc', - ], - [ - 'code' => 'LIVRE', - 'convert' => [ - 'mul' => '0.4895', - ], - 'symbol' => 'livre', - ], - [ - 'code' => 'OUNCE', - 'convert' => [ - 'mul' => '0.45359237', - 'div' => '16' - ], - 'symbol' => 'oz', - ], - [ - 'code' => 'POUND', - 'convert' => [ - 'mul' => '0.45359237', - ], - 'symbol' => 'lb', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/pressure', - ], - ], - 'code' => 'pressure', - 'standard' => 'BAR', - 'units' => [ - [ - 'code' => 'BAR', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'Bar', - ], - [ - 'code' => 'PASCAL', - 'convert' => [ - 'mul' => '0.00001', - ], - 'symbol' => 'Pa', - ], - [ - 'code' => 'HECTOPASCAL', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'hPa', - ], - [ - 'code' => 'MILLIBAR', - 'convert' => [ - 'mul' => '0.001', - ], - 'symbol' => 'mBar', - ], - [ - 'code' => 'ATM', - 'convert' => [ - 'mul' => '0.986923', - ], - 'symbol' => 'atm', - ], - [ - 'code' => 'PSI', - 'convert' => [ - 'mul' => '14.50376985373022', - ], - 'symbol' => 'PSI', - ], - [ - 'code' => 'TORR', - 'convert' => [ - 'mul' => '750.06375541921', - ], - 'symbol' => 'Torr', - ], - [ - 'code' => 'MMHG', - 'convert' => [ - 'mul' => '750.06375541921', - ], - 'symbol' => 'mmHg', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/energy', - ], - ], - 'code' => 'energy', - 'standard' => 'JOULE', - 'units' => [ - [ - 'code' => 'JOULE', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'J', - ], - [ - 'code' => 'CALORIE', - 'convert' => [ - 'mul' => '4.184', - ], - 'symbol' => 'cal', - ], - [ - 'code' => 'KILOCALORIE', - 'convert' => [ - 'mul' => '4184', - ], - 'symbol' => 'kcal', - ], - [ - 'code' => 'KILOJOULE', - 'convert' => [ - 'mul' => '1000', - ], - 'symbol' => 'kJ', - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/measure-families/casebox', - ], - ], - 'code' => 'casebox', - 'standard' => 'PIECE', - 'units' => [ - [ - 'code' => 'PIECE', - 'convert' => [ - 'mul' => '1', - ], - 'symbol' => 'Pc', - ], - [ - 'code' => 'DOZEN', - 'convert' => [ - 'mul' => '12', - ], - 'symbol' => 'Dz', - ], - ], - ], - ]; - } -} diff --git a/tests/v2_0/Api/Product/CreateProductApiIntegration.php b/tests/v2_0/Api/Product/CreateProductApiIntegration.php deleted file mode 100644 index a440e731..00000000 --- a/tests/v2_0/Api/Product/CreateProductApiIntegration.php +++ /dev/null @@ -1,102 +0,0 @@ -createClient()->getProductApi(); - - try { - $api->create('black_sneakers', [ - 'enabled' => false, - 'family' => 'sneakers', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'data' => 'Black sneakers', - 'scope' => null, - ], - [ - 'data' => 'Sneakers', - 'locale' => 'fr_FR', - 'scope' => null, - ], - ], - ] - ]); - } catch (UnprocessableEntityHttpException $exception) { - $this->assertSame([ - [ - 'property' => 'identifier', - 'message' => 'The same identifier is already set on another product', - ], - ], $exception->getResponseErrors()); - } - } - - public function testCreate() - { - $api = $this->createClient()->getProductApi(); - $response = $api->create('pumps', [ - 'enabled' => false, - 'family' => 'sandals', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'data' => 'The pumps', - 'locale' => 'en_US', - 'scope' => null, - ], - [ - 'data' => 'Les pumps', - 'locale' => 'fr_FR', - 'scope' => null, - ] - ], - ] - ]); - - $this->assertSame(201, $response); - - $expectedProduct = $this->sanitizeProductData([ - 'identifier' => 'pumps', - 'family' => 'sandals', - 'groups' => [ - ], - 'categories' => [ - 'summer_collection', - ], - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'The pumps', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Les pumps', - ], - ], - ], - 'created' => '2017-06-26T14:27:19+00:00', - 'updated' => '2017-06-26T14:27:19+00:00', - 'associations' => [ - ], - ]); - sleep(10); - $product = $this->sanitizeProductData($api->get('pumps')); - - $this->assertSameContent($expectedProduct, $product); - } -} diff --git a/tests/v2_0/Api/Product/GetProductApiIntegration.php b/tests/v2_0/Api/Product/GetProductApiIntegration.php deleted file mode 100644 index a5e0ca53..00000000 --- a/tests/v2_0/Api/Product/GetProductApiIntegration.php +++ /dev/null @@ -1,126 +0,0 @@ -createClient()->getProductApi(); - - $product = $api->get('black_sneakers'); - $product = $this->sanitizeProductData($product); - - $this->assertSameContent($this->sanitizeProductData([ - 'identifier' => 'black_sneakers', - 'family' => 'sneakers', - 'groups' => [ - ], - 'categories' => [ - 'summer_collection', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'The famous sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Les fameuses sneakers', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Sneakers', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '9/8/e/d/98eda36deba5e392f5c9e0dd2d9ef194b045b2af_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => 'http://localhost/api/rest/v1/media-files/9/8/e/d/98eda36deba5e392f5c9e0dd2d9ef194b045b2af_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'length' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'amount' => 14, - 'unit' => 'CENTIMETER', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '40.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-22T14:08:29+00:00', - 'updated' => '2017-06-22T14:08:29+00:00', - 'associations' => [], - ]), $product); - } -} diff --git a/tests/v2_0/Api/Product/ListProductApiIntegration.php b/tests/v2_0/Api/Product/ListProductApiIntegration.php deleted file mode 100644 index e392b227..00000000 --- a/tests/v2_0/Api/Product/ListProductApiIntegration.php +++ /dev/null @@ -1,1343 +0,0 @@ -createClient()->getProductApi(); - $expectedProducts = $this->getExpectedProducts(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(5); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=false&pagination_type=page&limit=5', $firstPage->getNextLink()); - - $firstPageProducts = $this->sanitizeProductData($firstPage->getItems()); - $firstPageExpectedProducts = $this->sanitizeProductData(array_slice($expectedProducts, 0, 5)); - - $this->assertSameContent($firstPageExpectedProducts, $firstPageProducts); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=1&with_count=false&pagination_type=page&limit=5', $secondPage->getPreviousLink()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=3&with_count=false&pagination_type=page&limit=5', $secondPage->getNextLink()); - - $secondPageProducts = $this->sanitizeProductData($secondPage->getItems()); - $secondPageExpectedProducts = $this->sanitizeProductData(array_slice($expectedProducts, 5, 5)); - - $this->assertSameContent($secondPageExpectedProducts, $secondPageProducts); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=false&pagination_type=page&limit=5', $lastPage->getPreviousLink()); - - $products = $lastPage->getItems(); - $this->assertCount(0 ,$products); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getProductApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(10, $firstPage->getCount()); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=true&pagination_type=page&limit=2', $firstPage->getNextLink()); - } - - public function testListPerPageWithSpecificQueryParameter() - { - $api = $this->createClient()->getProductApi(); - $expectedProducts = $this->getExpectedProducts(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, false, ['foo' => 'bar']); - - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame($baseUri . '/api/rest/v1/products?page=2&with_count=false&pagination_type=page&limit=2&foo=bar', $firstPage->getNextLink()); - - $expectedProducts = $this->sanitizeProductData(array_slice($expectedProducts, 0, 2)); - $actualProducts = $this->sanitizeProductData($firstPage->getItems()); - - $this->assertSameContent($expectedProducts, $actualProducts); - } - - public function testAll() - { - $api = $this->createClient()->getProductApi(); - $products = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $products); - - $expectedProducts = $this->sanitizeProductData($this->getExpectedProducts()); - $products = $this->sanitizeProductData(iterator_to_array($products)); - - $this->assertSameContent($expectedProducts, $products); - } - - public function testAllWithUselessQueryParameter() - { - $api = $this->createClient()->getProductApi(); - $products = $api->all(10, ['foo' => 'bar']); - - $this->assertInstanceOf(ResourceCursorInterface::class, $products); - - $expectedProducts = $this->sanitizeProductData($this->getExpectedProducts()); - $products = $this->sanitizeProductData(iterator_to_array($products)); - - $this->assertSameContent($expectedProducts, $products); - } - - public function testSearchOnProductProperties() - { - $api = $this->createClient()->getProductApi(); - $products = $api->listPerPage(10, true, [ - 'search' => [ - 'family' => [ - [ - 'operator' => 'IN', - 'value' => ['sneakers'], - ] - ] - ] - ]); - - $this->assertSame(1, $products->getCount()); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('black_sneakers')); - $actualProduct = $this->sanitizeProductData($products->getItems()[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testSearchOnProductValues() - { - $api = $this->createClient()->getProductApi(); - $products = $api->listPerPage(10, true, [ - 'search' => [ - 'color' => [ - [ - 'operator' => 'IN', - 'value' => ['maroon'] - ] - ] - ] - ]); - - $this->assertSame(2, $products->getCount()); - - $products = $products->getItems(); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('small_boot')); - $actualProduct = $this->sanitizeProductData($products[0]); - $this->assertSameContent($expectedProduct, $actualProduct); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('docks_maroon')); - $actualProduct = $this->sanitizeProductData($products[1]); - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testSearchWithSeveralFiltersUsingSearchBuilder() - { - $api = $this->createClient()->getProductApi(); - - $searchBuilder = new SearchBuilder(); - $searchBuilder - ->addFilter('family', 'IN', ['sneakers']) - ->addFilter('color', 'IN', ['white', 'black']); - - $products = $api->listPerPage(10, true, ['search' => $searchBuilder->getFilters()]); - - $this->assertSame(1, $products->getCount()); - - $expectedProduct = $this->sanitizeProductData($this->getExpectedProductByIdentifier('black_sneakers')); - $actualProduct = $this->sanitizeProductData($products->getItems()[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testAllWithSelectedLocales() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $api = $this->createClient()->getProductApi(); - $products = $api->all(10, [ - 'locales' => 'fr_FR', - 'search' => [ - 'categories' => [ - [ - 'operator' => 'IN', - 'value' => ['sandals'], - ] - ] - ] - ]); - - $expectedProduct = $this->sanitizeProductData([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/dance_shoe', - ], - ], - 'identifier' => 'dance_shoe', - 'family' => 'sandals', - 'groups' => [], - 'categories' => [ - 'sandals', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'greem', - ], - ], - 'description' => [ - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Dansez toute la nuit !', - ], - ], - 'destocking_date' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '2017-06-30T00:00:00+00:00', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Chaussure de dance', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '40', - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '99.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '90.50', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ]); - - $actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testAllWithSelectedAttributes() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $api = $this->createClient()->getProductApi(); - $products = $api->all(1, ['attributes' => 'name,color']); - - $expectedProduct = $this->sanitizeProductData([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/big_boot', - ], - ], - 'identifier' => 'big_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'categories' => [ - 'summer_collection', - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Big boot !', - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [ - 'X_SELL' => [ - 'groups' => [], - 'products' => [ - 'small_boot', - 'medium_boot', - ], - ], - ], - ]); - - $actualProduct = $this->sanitizeProductData($products->current()); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - public function testAllWithSelectedScope() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - $api = $this->createClient()->getProductApi(); - $products = $api->all(10, [ - 'scope' => 'mobile', - 'search' => [ - 'family' => [ - [ - 'operator' => 'IN', - 'value' => ['sneakers'], - ] - ] - ] - ]); - - $expectedProduct = $this->sanitizeProductData([ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/black_sneakers', - ], - ], - 'identifier' => 'black_sneakers', - 'family' => 'sneakers', - 'groups' => [], - 'categories' => [ - 'summer_collection', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black sneakers', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'length' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'amount' => 14, - 'unit' => 'CENTIMETER', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '40.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ]); - - $actualProduct = $this->sanitizeProductData(iterator_to_array($products)[0]); - - $this->assertSameContent($expectedProduct, $actualProduct); - } - - /** - * @param string $identifier - * - * @return mixed - */ - protected function getExpectedProductByIdentifier($identifier) - { - foreach ($this->getExpectedProducts() as $product) { - if ($identifier === $product['identifier']) { - return $product; - } - } - } - - /** - * @return array - */ - protected function getExpectedProducts() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/big_boot', - ], - ], - 'identifier' => 'big_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'categories' => [ - 'summer_collection', - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Big boot for a big foot.', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'TimberLand', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Big boot !', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '8/2/4/3/824336b53f78c7badf3538793ab3ba92ffa3c120_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/8/2/4/3/824336b53f78c7badf3538793ab3ba92ffa3c120_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '37', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '120.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '110.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [ - 'X_SELL' => [ - 'groups' => [], - 'products' => [ - 'small_boot', - 'medium_boot', - ], - ], - ], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_red', - ], - ], - 'identifier' => 'docks_red', - 'family' => 'boots', - 'groups' => ['caterpillar_boots'], - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'red', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/small_boot', - ], - ], - 'identifier' => 'small_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'categories' => [ - 'summer_collection', - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'maroon', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'TimberLand', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Small boot', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '4/9/1/2/4912ff747899d2ade4d7f8d965b6d3d9a771655c_Ziggy.png', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/4/9/1/2/4912ff747899d2ade4d7f8d965b6d3d9a771655c_Ziggy.png/download', - ], - ], - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '110.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '110.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/medium_boot', - ], - ], - 'identifier' => 'medium_boot', - 'family' => 'boots', - 'groups' => [ - 'similar_boots', - ], - 'categories' => [ - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'white', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'The medium boot.', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Medium boot', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '100.50', - 'currency' => 'EUR', - ], - [ - 'amount' => '100.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/dance_shoe', - ], - ], - 'identifier' => 'dance_shoe', - 'family' => 'sandals', - 'groups' => [], - 'categories' => [ - 'sandals', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'greem', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'To dance all night !', - ], - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Dansez toute la nuit !', - ], - ], - 'destocking_date' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '2017-06-30T00:00:00+00:00', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Dance shoe', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Chaussure de dance', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/0/4/1/a/041a1570a3cefa2c79872c433f60c2e6301afd60_Akeneo_logo.png/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '40', - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '99.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '90.50', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/black_sneakers', - ], - ], - 'identifier' => 'black_sneakers', - 'family' => 'sneakers', - 'groups' => [], - 'categories' => [ - 'summer_collection', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'The famous sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => 'ecommerce', - 'data' => 'Les fameuses sneakers', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Converse', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black sneakers', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Sneakers', - ], - ], - 'side_view' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg', - '_links' => [ - 'download' => [ - 'href' => $baseUri . '/api/rest/v1/media-files/3/d/8/9/3d89680c85a835b5b0a5bd0e7dd2515b55a4b657_Ziggy_certification.jpg/download', - ], - ], - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '41', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'dry', - 'wet', - ], - ], - ], - 'length' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'amount' => 14, - 'unit' => 'CENTIMETER', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '40.00', - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_blue', - ], - ], - 'identifier' => 'docks_blue', - 'family' => 'boots', - 'groups' => ['caterpillar_boots'], - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'blue', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_black', - ], - ], - 'identifier' => 'docks_black', - 'family' => 'boots', - 'groups' => ['caterpillar_boots'], - 'categories' => [ - 'winter_boots', - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '42', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_white', - ], - ], - 'identifier' => 'docks_white', - 'family' => 'boots', - 'groups' => ['caterpillar_boots'], - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'white', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/products/docks_maroon', - ], - ], - 'identifier' => 'docks_maroon', - 'family' => 'boots', - 'groups' => ['caterpillar_boots'], - 'categories' => [ - 'winter_collection', - ], - 'enabled' => true, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'maroon', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '44', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T07:33:09+00:00', - 'associations' => [], - ], - ]; - } -} diff --git a/tests/v2_0/Api/Product/UpsertProductApiIntegration.php b/tests/v2_0/Api/Product/UpsertProductApiIntegration.php deleted file mode 100644 index 467ca177..00000000 --- a/tests/v2_0/Api/Product/UpsertProductApiIntegration.php +++ /dev/null @@ -1,159 +0,0 @@ -createClient()->getProductApi(); - - $response = $api->upsert('docks_black', [ - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', - ], - ], - ] - ]); - - $this->assertSame(204, $response); - - $product = $this->sanitizeProductData($api->get('docks_black')); - - $this->assertSameContent($this->sanitizeProductData([ - 'identifier' => 'docks_black', - 'family' => 'boots', - 'groups' => ['caterpillar_boots'], - 'categories' => [ - 'winter_boots', - 'winter_collection', - ], - 'enabled' => false, - 'values' => [ - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'black', - ], - ], - 'manufacturer' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'Caterpillar', - ], - ], - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Black Docks', - ], - ], - 'size' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => '42', - ], - ], - 'weather_conditions' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - 'cold', - 'snowy', - 'wet', - ], - ], - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => '149.49', - 'currency' => 'EUR', - ], - [ - 'amount' => '149.49', - 'currency' => 'USD', - ], - ], - ], - ], - ], - 'created' => '2017-06-26T07:33:09+00:00', - 'updated' => '2017-06-26T14:48:15+00:00', - 'associations' => [] - ]), $product); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getProductApi(); - $response = $api->upsert('pumps', [ - 'enabled' => false, - 'family' => 'sandals', - 'categories' => ['summer_collection'], - 'values' => [ - 'name' => [ - [ - 'data' => 'The pumps', - 'locale' => 'en_US', - 'scope' => null, - ], - [ - 'data' => 'Les pumps', - 'locale' => 'fr_FR', - 'scope' => null, - ] - ], - ] - ]); - - $this->assertSame(201, $response); - sleep(10); - $product = $this->sanitizeProductData($api->get('pumps')); - - $expectedProduct = $this->sanitizeProductData([ - 'identifier' => 'pumps', - 'family' => 'sandals', - 'groups' => [], - 'categories' => [ - 'summer_collection', - ], - 'enabled' => false, - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'The pumps', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Les pumps', - ], - ], - ], - 'created' => '2017-06-26T14:27:19+00:00', - 'updated' => '2017-06-26T14:27:19+00:00', - 'associations' => [ - ], - ]); - - $this->assertSameContent($expectedProduct, $product); - } -} diff --git a/tests/v2_0/Api/ProductModel/CreateProductModelIntegration.php b/tests/v2_0/Api/ProductModel/CreateProductModelIntegration.php deleted file mode 100644 index 06827f17..00000000 --- a/tests/v2_0/Api/ProductModel/CreateProductModelIntegration.php +++ /dev/null @@ -1,133 +0,0 @@ -createClient()->getProductModelApi(); - $code = 'saddle'; - $data = [ - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Red rain boots', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie rouges', - ], - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'saddle' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Saddle rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ] - ] - ] - ] - ]; - $response = $api->create($code, $data); - $this->assertSame(201, $response); - - // We need this because of product model post save events. - sleep(5); - $productModel = $api->get($code); - - $data['code'] = $code; - $this->assertSameContent($data, $productModel); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\UnprocessableEntityHttpException - * @expectedExceptionMessage Validation failed - */ - public function testFailToCreateAProductModel() - { - $api = $this->createClient()->getProductModelApi(); - $code = 'red'; - $data = [ - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Red rain boots', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie rouges', - ], - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'red' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Red rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ] - ] - ] - ] - ]; - $response = $api->create($code, $data); - $this->assertSame(422, $response); - } -} diff --git a/tests/v2_0/Api/ProductModel/GetProductModelApiIntegration.php b/tests/v2_0/Api/ProductModel/GetProductModelApiIntegration.php deleted file mode 100644 index b3127110..00000000 --- a/tests/v2_0/Api/ProductModel/GetProductModelApiIntegration.php +++ /dev/null @@ -1,78 +0,0 @@ -createClient()->getProductModelApi(); - - $productModel = $api->get('rain_boots_red'); - $productModel = $this->sanitizeProductData($productModel); - - $this->assertSameContent($this->sanitizeProductData([ - 'code' => 'rain_boots_red', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Red rain boots', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie rouges', - ], - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'red' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Red rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ] - ] - ] - ], - 'created' => '2017-10-17T14:12:35+00:00', - 'updated' => '2017-10-17T14:12:35+00:00' - ]), $productModel); - } - - /** - * @expectedException \Akeneo\Pim\ApiClient\Exception\NotFoundHttpException - * @expectedExceptionMessage Product model "trololo" does not exist. - */ - public function testEntityNotFound() - { - $this->createClient()->getProductModelApi()->get('trololo'); - } -} diff --git a/tests/v2_0/Api/ProductModel/ListProductModelApiIntegration.php b/tests/v2_0/Api/ProductModel/ListProductModelApiIntegration.php deleted file mode 100644 index 2edd8e9a..00000000 --- a/tests/v2_0/Api/ProductModel/ListProductModelApiIntegration.php +++ /dev/null @@ -1,307 +0,0 @@ -createClient()->getProductModelApi(); - $expectedProductModels = $this->getExpectedProductModels(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertNull($firstPage->getCount()); - $this->assertNull($firstPage->getPreviousLink()); - $this->assertNull($firstPage->getPreviousPage()); - $this->assertFalse($firstPage->hasPreviousPage()); - $this->assertTrue($firstPage->hasNextPage()); - $this->assertSame( - $baseUri . '/api/rest/v1/product-models?page=2&with_count=false&pagination_type=page&limit=2', - $firstPage->getNextLink() - ); - - $firstPageProducts = $this->sanitizeProductData($firstPage->getItems()); - $firstPageExpectedProducts = $this->sanitizeProductData(array_slice($expectedProductModels, 0, 2)); - - $this->assertSameContent($firstPageExpectedProducts, $firstPageProducts); - - $secondPage = $firstPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $secondPage); - $this->assertTrue($secondPage->hasPreviousPage()); - $this->assertTrue($secondPage->hasNextPage()); - $this->assertSame( - $baseUri . '/api/rest/v1/product-models?page=1&with_count=false&pagination_type=page&limit=2', - $secondPage->getPreviousLink() - ); - $this->assertSame( - $baseUri . '/api/rest/v1/product-models?page=3&with_count=false&pagination_type=page&limit=2', - $secondPage->getNextLink() - ); - - $secondPageProducts = $this->sanitizeProductData($secondPage->getItems()); - $secondPageExpectedProducts = $this->sanitizeProductData(array_slice($expectedProductModels, 2, 2)); - - $this->assertSameContent($secondPageExpectedProducts, $secondPageProducts); - - $lastPage = $secondPage->getNextPage(); - $this->assertInstanceOf(PageInterface::class, $lastPage); - $this->assertTrue($lastPage->hasPreviousPage()); - $this->assertFalse($lastPage->hasNextPage()); - $this->assertNull($lastPage->getNextPage()); - $this->assertNull($lastPage->getNextLink()); - $this->assertSame( - $baseUri . '/api/rest/v1/product-models?page=2&with_count=false&pagination_type=page&limit=2', - $lastPage->getPreviousLink() - ); - - $productModels = $lastPage->getItems(); - $this->assertCount(0 , $productModels); - - $previousPage = $lastPage->getPreviousPage(); - $this->assertInstanceOf(PageInterface::class, $previousPage); - $this->assertSame($secondPage->getItems(), $previousPage->getItems()); - } - - public function testListPerPageWithCount() - { - $api = $this->createClient()->getProductModelApi(); - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - $firstPage = $api->listPerPage(2, true); - $this->assertInstanceOf(PageInterface::class, $firstPage); - $this->assertSame(4, $firstPage->getCount()); - $this->assertSame( - $baseUri . '/api/rest/v1/product-models?page=2&with_count=true&pagination_type=page&limit=2', - $firstPage->getNextLink() - ); - } - - public function testAll() - { - $api = $this->createClient()->getProductModelApi(); - $productModels = $api->all(); - - $this->assertInstanceOf(ResourceCursorInterface::class, $productModels); - - $expectedProductModels = $this->sanitizeProductData($this->getExpectedProductModels()); - $productModels = $this->sanitizeProductData(iterator_to_array($productModels)); - - $this->assertSameContent($expectedProductModels, $productModels); - } - - protected function getExpectedProductModels() - { - $baseUri = $this->getConfiguration()['pim']['base_uri']; - - return [ - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/product-models/rain_boots' - ] - ], - 'code' => 'rain_boots', - 'family_variant' => 'rain_boots_color_size', - 'parent' => null, - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR' - ], - [ - 'amount' => '42.00', - 'currency' => 'USD' - ] - ] - ] - ] - ], - 'created' => '2017-10-23T13:18:15+00:00', - 'updated' => '2017-10-23T13:18:15+00:00' - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/product-models/rain_boots_blue' - ] - ], - 'code' => 'rain_boots_blue', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Blue rain boots' - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie bleues' - ] - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'blue' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Blue rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR' - ], - [ - 'amount' => '42.00', - 'currency' => 'USD' - ] - ] - ] - ] - ], - 'created' => '2017-10-23T13:18:16+00:00', - 'updated' => '2017-10-23T13:18:16+00:00' - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/product-models/rain_boots_red' - ] - ], - 'code' => 'rain_boots_red', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Red rain boots' - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie rouges' - ] - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'red' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Red rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR' - ], - [ - 'amount' => '42.00', - 'currency' => 'USD' - ] - ] - ] - ] - ], - 'created' => '2017-10-23T13:18:16+00:00', - 'updated' => '2017-10-23T13:18:16+00:00' - ], - [ - '_links' => [ - 'self' => [ - 'href' => $baseUri . '/api/rest/v1/product-models/rain_boots_charcoal' - ] - ], - 'code' => 'rain_boots_charcoal', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Charcoal rain boots' - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie couleur charbon' - ] - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'charcoal' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Charcoal rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR' - ], - [ - 'amount' => '42.00', - 'currency' => 'USD' - ] - ] - ] - ] - ], - 'created' => '2017-10-23T13:18:16+00:00', - 'updated' => '2017-10-23T13:18:16+00:00' - ] - ]; - } -} diff --git a/tests/v2_0/Api/ProductModel/UpsertListOfProductModelApiIntegration.php b/tests/v2_0/Api/ProductModel/UpsertListOfProductModelApiIntegration.php deleted file mode 100644 index 47bafa60..00000000 --- a/tests/v2_0/Api/ProductModel/UpsertListOfProductModelApiIntegration.php +++ /dev/null @@ -1,130 +0,0 @@ -createClient()->getProductModelApi(); - - $response = $api->upsertList([ - [ - 'code' => 'rain_boots_red', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots'], - 'values' => [ - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Red rain boots made of butter (why not?) for winter.' - ] - ] - ] - ], - [ - 'code' => 'rain_boots_saddle', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots'], - 'values' => [ - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Saddle rain boots made of rubber for winter.' - ] - ] - ] - ], - [ - 'code' => 'rain_boots_greem', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots'], - 'values' => [ - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Greem rain boots made of rubber for winter.' - ] - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'greem' - ] - ] - ] - ] - ]); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'rain_boots_red', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'rain_boots_saddle', - 'status_code' => 422, - 'message' => 'Validation failed.', - 'errors' => [ - [ - 'property' => 'attribute', - 'message' => 'Attribute "color" cannot be empty, as it is defined as an axis for this entity' - ] - ] - ], - 3 => [ - 'line' => 3, - 'code' => 'rain_boots_greem', - 'status_code' => 201, - ], - ], $responseLines); - } - - public function testUpsertListFromStreamSuccessful() - { - $resourcesContent = - <<getStreamFactory()->createStream($resources); - $api = $this->createClient()->getProductModelApi(); - $response = $api->upsertList($streamedResources); - - $this->assertInstanceOf('\Iterator', $response); - - $responseLines = iterator_to_array($response); - - $this->assertSame([ - 1 => [ - 'line' => 1, - 'code' => 'rain_boots_red', - 'status_code' => 204, - ], - 2 => [ - 'line' => 2, - 'code' => 'rain_boots_blue', - 'status_code' => 204, - ], - ], $responseLines); - } -} diff --git a/tests/v2_0/Api/ProductModel/UpsertProductModelApiIntegration.php b/tests/v2_0/Api/ProductModel/UpsertProductModelApiIntegration.php deleted file mode 100644 index a0ecd28b..00000000 --- a/tests/v2_0/Api/ProductModel/UpsertProductModelApiIntegration.php +++ /dev/null @@ -1,145 +0,0 @@ -createClient()->getProductModelApi(); - - $response = $api->upsert('rain_boots_red', [ - 'values' => [ - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Red rain boots en_US.' - ] - ] - ] - ]); - - $this->assertSame(204, $response); - - $productModel = $this->sanitizeProductData($api->get('rain_boots_red')); - - $this->assertSameContent($this->sanitizeProductData([ - 'code' => 'rain_boots_red', - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Red rain boots', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie rouges', - ], - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'red' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Red rain boots en_US.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ] - ] - ] - ], - 'created' => '2017-10-17T14:12:35+00:00', - 'updated' => '2017-10-17T14:12:35+00:00' - ]), $productModel); - } - - public function testUpsertDoingCreate() - { - $api = $this->createClient()->getProductModelApi(); - $data = [ - 'family_variant' => 'rain_boots_color_size', - 'parent' => 'rain_boots', - 'categories' => ['2014_collection', 'winter_boots', 'winter_collection'], - 'values' => [ - 'name' => [ - [ - 'locale' => 'en_US', - 'scope' => null, - 'data' => 'Red rain boots', - ], - [ - 'locale' => 'fr_FR', - 'scope' => null, - 'data' => 'Bottes de pluie rouges', - ], - ], - 'color' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => 'saddle' - ] - ], - 'description' => [ - [ - 'locale' => 'en_US', - 'scope' => 'ecommerce', - 'data' => 'Saddle rain boots made of rubber for winter.' - ] - ], - 'price' => [ - [ - 'locale' => null, - 'scope' => null, - 'data' => [ - [ - 'amount' => null, - 'currency' => 'EUR', - ], - [ - 'amount' => '42.00', - 'currency' => 'USD', - ], - ] - ] - ] - ] - ]; - $response = $api->upsert('saddle', $data); - - $this->assertSame(201, $response); - sleep(10); - $productModel = $this->sanitizeProductData($api->get('saddle')); - - $expectedProductModel = $this->sanitizeProductData(array_merge(['code' => 'saddle'], $data)); - - $this->assertSameContent($expectedProductModel, $productModel); - } -} diff --git a/travis.php.ini b/travis.php.ini new file mode 100644 index 00000000..719c6143 --- /dev/null +++ b/travis.php.ini @@ -0,0 +1 @@ +always_populate_raw_post_data = -1