diff options
author | Olivier Paroz <github@oparoz.com> | 2015-09-08 23:47:13 +0300 |
---|---|---|
committer | Olivier Paroz <github@oparoz.com> | 2015-09-08 23:47:13 +0300 |
commit | e3686034ab7eeec493022df3ee021eacc6dc48a9 (patch) | |
tree | d958d770661be7f3cfaa32d16a0d74f03fde9de5 /tests | |
parent | dab919f36ef447a2c50eb0f6aef13e9c9da80d47 (diff) |
Use 2 different type of files to test the API previews
Diffstat (limited to 'tests')
-rw-r--r-- | tests/_support/ApiTester.php | 16 | ||||
-rw-r--r-- | tests/_support/_generated/ApiTesterActions.php | 390 | ||||
-rw-r--r-- | tests/_support/_generated/IntegrationTesterActions.php | 46 | ||||
-rw-r--r-- | tests/_support/_generated/UnitTesterActions.php | 62 | ||||
-rw-r--r-- | tests/api.suite.yml | 1 | ||||
-rw-r--r-- | tests/api/GetPreviewCest.php | 28 |
6 files changed, 535 insertions, 8 deletions
diff --git a/tests/_support/ApiTester.php b/tests/_support/ApiTester.php index 41210a3c..bac05c5c 100644 --- a/tests/_support/ApiTester.php +++ b/tests/_support/ApiTester.php @@ -20,12 +20,11 @@ class ApiTester extends \Codeception\Actor { use _generated\ApiTesterActions; /** - * Define custom actions here + * Makes sure the response we get is the expected file * * @param array $file * @param string $filename */ - public function downloadAFile($file, $filename = null) { $I = $this; if (!$filename) { @@ -39,4 +38,17 @@ class ApiTester extends \Codeception\Actor { . $filename . '"' ); } + + /** + * Compares the dimensions of the downloaded image to the expected dimensions + * + * @param int $width + * @param int $height + */ + public function checkImageSize($width, $height) { + $I = $this; + $image = imagecreatefromstring($I->grabResponse()); + $I->assertEquals($width, imagesx($image)); + $I->assertEquals($height, imagesy($image)); + } } diff --git a/tests/_support/_generated/ApiTesterActions.php b/tests/_support/_generated/ApiTesterActions.php index d3c031be..ee203cab 100644 --- a/tests/_support/_generated/ApiTesterActions.php +++ b/tests/_support/_generated/ApiTesterActions.php @@ -1,10 +1,11 @@ -<?php //[STAMP] fca24ce90a907d625b57471272f29c22 +<?php //[STAMP] 0f2a47ed0d13e8e09ab23f0015cde7f9 namespace _generated; // This class was automatically generated by build task // You should not change it manually as it will be overwritten on next build // @codingStandardsIgnoreFile +use Codeception\Module\Asserts; use Helper\Api; use Helper\DataSetup; use Codeception\Module\REST; @@ -20,6 +21,337 @@ trait ApiTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * + * Checks that two variables are equal. + * + * @param $expected + * @param $actual + * @param string $message + * + * @return mixed + * @see \Codeception\Module\Asserts::assertEquals() + */ + public function assertEquals($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEquals', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that two variables are not equal + * + * @param $expected + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertNotEquals() + */ + public function assertNotEquals($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEquals', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that two variables are same + * + * @param $expected + * @param $actual + * @param string $message + * + * @return mixed + * @see \Codeception\Module\Asserts::assertSame() + */ + public function assertSame($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertSame', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that two variables are not same + * + * @param $expected + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertNotSame() + */ + public function assertNotSame($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotSame', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that actual is greater than expected + * + * @param $expected + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertGreaterThan() + */ + public function assertGreaterThan($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThan', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @deprecated + * @see \Codeception\Module\Asserts::assertGreaterThen() + */ + public function assertGreaterThen($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThen', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that actual is greater or equal than expected + * + * @param $expected + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertGreaterThanOrEqual() + */ + public function assertGreaterThanOrEqual($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThanOrEqual', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * @deprecated + * @see \Codeception\Module\Asserts::assertGreaterThenOrEqual() + */ + public function assertGreaterThenOrEqual($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertGreaterThenOrEqual', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that actual is less than expected + * + * @param $expected + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertLessThan() + */ + public function assertLessThan($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThan', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that actual is less or equal than expected + * + * @param $expected + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertLessThanOrEqual() + */ + public function assertLessThanOrEqual($expected, $actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertLessThanOrEqual', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that haystack contains needle + * + * @param $needle + * @param $haystack + * @param string $message + * @see \Codeception\Module\Asserts::assertContains() + */ + public function assertContains($needle, $haystack, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertContains', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that haystack doesn't contain needle. + * + * @param $needle + * @param $haystack + * @param string $message + * @see \Codeception\Module\Asserts::assertNotContains() + */ + public function assertNotContains($needle, $haystack, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotContains', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that string match with pattern + * + * @param string $pattern + * @param string $string + * @param string $message + * @see \Codeception\Module\Asserts::assertRegExp() + */ + public function assertRegExp($pattern, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertRegExp', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that string not match with pattern + * + * @param string $pattern + * @param string $string + * @param string $message + * @see \Codeception\Module\Asserts::assertNotRegExp() + */ + public function assertNotRegExp($pattern, $string, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotRegExp', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that variable is empty. + * + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertEmpty() + */ + public function assertEmpty($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertEmpty', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that variable is not empty. + * + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertNotEmpty() + */ + public function assertNotEmpty($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotEmpty', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that variable is NULL + * + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertNull() + */ + public function assertNull($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNull', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that variable is not NULL + * + * @param $actual + * @param string $message + * @see \Codeception\Module\Asserts::assertNotNull() + */ + public function assertNotNull($actual, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertNotNull', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that condition is positive. + * + * @param $condition + * @param string $message + * @see \Codeception\Module\Asserts::assertTrue() + */ + public function assertTrue($condition, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertTrue', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks that condition is negative. + * + * @param $condition + * @param string $message + * @see \Codeception\Module\Asserts::assertFalse() + */ + public function assertFalse($condition, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFalse', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if file exists + * + * @param string $filename + * @param string $message + * @see \Codeception\Module\Asserts::assertFileExists() + */ + public function assertFileExists($filename, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileExists', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Checks if file doesn't exist + * + * @param string $filename + * @param string $message + * @see \Codeception\Module\Asserts::assertFileNotExists() + */ + public function assertFileNotExists($filename, $message = null) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('assertFileNotExists', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Fails the test with message. + * + * @param $message + * @see \Codeception\Module\Asserts::fail() + */ + public function fail($message) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * * Retrieves the user's credentials from the test data * * @return mixed @@ -73,6 +405,62 @@ trait ApiTesterActions /** * [!] Method is generated. Documentation taken from corresponding module. * + * @return mixed + * @throws \Codeception\Exception\ModuleException + * @see \Helper\Api::getSharedFolder() + */ + public function getSharedFolder() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('getSharedFolder', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::createBrokenConfig() + */ + public function createBrokenConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('createBrokenConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::createConfigWithBom() + */ + public function createConfigWithBom() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('createConfigWithBom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::emptyConfig() + */ + public function emptyConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('emptyConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::restoreValidConfig() + */ + public function restoreValidConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('restoreValidConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * * Sets HTTP header * * @param $name diff --git a/tests/_support/_generated/IntegrationTesterActions.php b/tests/_support/_generated/IntegrationTesterActions.php index 2dea9391..151b7c9d 100644 --- a/tests/_support/_generated/IntegrationTesterActions.php +++ b/tests/_support/_generated/IntegrationTesterActions.php @@ -1,4 +1,4 @@ -<?php //[STAMP] 2ab543bb9cfa3d42406c0d655af4c148 +<?php //[STAMP] aaa131e2f3cfca66f5f79cc2d0aa3031 namespace _generated; // This class was automatically generated by build task @@ -361,4 +361,48 @@ trait IntegrationTesterActions public function getFilesDataForFolder($folderPath) { return $this->getScenario()->runStep(new \Codeception\Step\Action('getFilesDataForFolder', func_get_args())); } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::createBrokenConfig() + */ + public function createBrokenConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('createBrokenConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::createConfigWithBom() + */ + public function createConfigWithBom() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('createConfigWithBom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::emptyConfig() + */ + public function emptyConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('emptyConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::restoreValidConfig() + */ + public function restoreValidConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('restoreValidConfig', func_get_args())); + } } diff --git a/tests/_support/_generated/UnitTesterActions.php b/tests/_support/_generated/UnitTesterActions.php index e9b23fde..acca33a7 100644 --- a/tests/_support/_generated/UnitTesterActions.php +++ b/tests/_support/_generated/UnitTesterActions.php @@ -1,4 +1,4 @@ -<?php //[STAMP] d2c433ccdfe3be7aa215a511eba39638 +<?php //[STAMP] aaa131e2f3cfca66f5f79cc2d0aa3031 namespace _generated; // This class was automatically generated by build task @@ -7,6 +7,7 @@ namespace _generated; use Codeception\Module\Asserts; use Helper\Unit; +use Helper\DataSetup; trait UnitTesterActions { @@ -345,4 +346,63 @@ trait UnitTesterActions public function fail($message) { return $this->getScenario()->runStep(new \Codeception\Step\Action('fail', func_get_args())); } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * Returns a list of ids available in the given folder + * + * @param string $folderPath + * + * @return array<string,int|string> + * @see \Helper\DataSetup::getFilesDataForFolder() + */ + public function getFilesDataForFolder($folderPath) { + return $this->getScenario()->runStep(new \Codeception\Step\Action('getFilesDataForFolder', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::createBrokenConfig() + */ + public function createBrokenConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('createBrokenConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::createConfigWithBom() + */ + public function createConfigWithBom() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('createConfigWithBom', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::emptyConfig() + */ + public function emptyConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('emptyConfig', func_get_args())); + } + + + /** + * [!] Method is generated. Documentation taken from corresponding module. + * + * + * @see \Helper\DataSetup::restoreValidConfig() + */ + public function restoreValidConfig() { + return $this->getScenario()->runStep(new \Codeception\Step\Action('restoreValidConfig', func_get_args())); + } } diff --git a/tests/api.suite.yml b/tests/api.suite.yml index 09ec480e..bcb113de 100644 --- a/tests/api.suite.yml +++ b/tests/api.suite.yml @@ -1,6 +1,7 @@ class_name: ApiTester modules: enabled: + - Asserts - \Helper\Api - \Helper\DataSetup - REST: diff --git a/tests/api/GetPreviewCest.php b/tests/api/GetPreviewCest.php index cd0d889f..ab2facc5 100644 --- a/tests/api/GetPreviewCest.php +++ b/tests/api/GetPreviewCest.php @@ -40,16 +40,38 @@ class GetPreviewCest { $I->connectToTheApi($this->apiUrl . '/9999999/1920/1080', 'the preview API'); } - public function getPreview(\Step\Api\User $I) { + public function getPreviewOfPng(\Step\Api\User $I) { $I->am('an app'); - $I->wantTo('get the preview of a file'); + $I->wantTo('get the preview of a PNG file'); + + $I->getUserCredentialsAndUseHttpAuthentication(); + $data = $I->getFilesDataForFolder('folder2'); + $file = $data['testimage.png']; + $url = $this->apiUrl . '/' . $file['id'] . '/64/64'; + $I->sendGET($url); + $I->downloadAFile($file, 'testimage.png'); + $I->checkImageSize(64, 64); + } + + /** + * That's a different code path because the file is animated + * + * @todo maybe + * + * @param \Step\Api\User $I + */ + public function getPreviewOfAnimatedGif(\Step\Api\User $I) { + $I->am('an app'); + $I->wantTo('get the preview of an animated GIF file'); $I->getUserCredentialsAndUseHttpAuthentication(); $data = $I->getFilesDataForFolder(''); + // 89x72 gif $file = $data['animated.gif']; - $url = $this->apiUrl . '/' . $file['id'] . '/1920/1080'; + $url = $this->apiUrl . '/' . $file['id'] . '/64/64'; $I->sendGET($url); $I->downloadAFile($file, 'animated.gif'); + $I->checkImageSize(89, 72); } public function emptyResponse(\Step\Api\User $I) { |