Skip to content

Commit

Permalink
add webservice tests
Browse files Browse the repository at this point in the history
  • Loading branch information
solverat committed Jan 20, 2019
1 parent d634ff9 commit 8a6fd7d
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 141 deletions.
17 changes: 3 additions & 14 deletions tests/_support/RestTester.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?php

namespace Pimcore\Tests;
namespace DachcomBundle\Test;

/**
* Inherited Methods
* Class RestTester
*
* @method void wantToTest($text)
* @method void wantTo($text)
* @method void execute($callable)
* @method void expectTo($prediction)
* @method void expect($prediction)
* @method void amGoingTo($argumentation)
* @method void am($role)
* @method void lookForwardTo($achieveValue)
* @method void comment($description)
* @method \Codeception\Lib\Friend haveFriend($name, $actorClass = NULL)
*
* @SuppressWarnings(PHPMD)
* @package DachcomBundle\Test
*/
class RestTester extends \Codeception\Actor
{
Expand Down
4 changes: 3 additions & 1 deletion tests/bundle_tests/rest.suite.dist.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
class_name: RestTester
modules:
enabled:
- \Pimcore\Tests\Helper\Pimcore:
- \DachcomBundle\Test\Helper\PimcoreCore:
connect_db: true
- \DachcomBundle\Test\Helper\PimcoreBundleCore:
run_installer: true
- \Pimcore\Tests\Helper\ClassManager
- \Pimcore\Tests\Helper\Model
- \Pimcore\Tests\Helper\PimcoreRest:
Expand Down
88 changes: 88 additions & 0 deletions tests/bundle_tests/rest/ObjectTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Pimcore\Tests\Rest;

use DachcomBundle\Test\Util\MembersHelper;
use MembersBundle\Adapter\Group\GroupInterface;
use MembersBundle\Adapter\User\UserInterface;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\MembersGroup;
use Pimcore\Model\DataObject\MembersUser;
use Pimcore\Tests\Test\RestTestCase;
use Pimcore\Tests\Util\TestHelper;

class UserTest extends RestTestCase
{
protected function _after()
{
TestHelper::cleanUp();
MembersHelper::cleanUp();
MembersHelper::reCreateMembersStructure();

parent::_after();
}

public function testUserCreate()
{
$unsavedObject = new MembersUser();
$unsavedObject->setParentId(1);
$unsavedObject->setUserOwner(1);
$unsavedObject->setUserModification(1);
$unsavedObject->setCreationDate(time());
$unsavedObject->setKey(uniqid() . rand(10, 99));

$time = time();

$result = $this->restClient->createObjectConcrete($unsavedObject);

$this->assertTrue($result->success, 'request not successful . ' . $result->msg);
$this->assertEquals(2, TestHelper::getObjectCount());

$id = $result->id;
$this->assertTrue($id > 1, 'id must be greater than 1');

$objectDirect = AbstractObject::getById($id);
$creationDate = $objectDirect->getCreationDate();

$this->assertTrue($creationDate >= $time, 'wrong creation date');

// as the object key is unique there must be exactly one object with that key
$list = $this->restClient->getObjectList('{ "o_key" : "' . $unsavedObject->getKey() . '"}');
$this->assertEquals(1, count($list));

$fetchedObject = $this->restClient->getObjectById($id);
$this->assertInstanceOf(UserInterface::class, $fetchedObject);
}

public function testUserGroupCreate()
{
$unsavedObject = new MembersGroup();
$unsavedObject->setParentId(1);
$unsavedObject->setUserOwner(1);
$unsavedObject->setUserModification(1);
$unsavedObject->setCreationDate(time());
$unsavedObject->setKey(uniqid() . rand(10, 99));

$time = time();

$result = $this->restClient->createObjectConcrete($unsavedObject);

$this->assertTrue($result->success, 'request not successful . ' . $result->msg);
$this->assertEquals(2, TestHelper::getObjectCount());

$id = $result->id;
$this->assertTrue($id > 1, 'id must be greater than 1');

$objectDirect = AbstractObject::getById($id);
$creationDate = $objectDirect->getCreationDate();

$this->assertTrue($creationDate >= $time, 'wrong creation date');

// as the object key is unique there must be exactly one object with that key
$list = $this->restClient->getObjectList('{ "o_key" : "' . $unsavedObject->getKey() . '"}');
$this->assertEquals(1, count($list));

$fetchedObject = $this->restClient->getObjectById($id);
$this->assertInstanceOf(GroupInterface::class, $fetchedObject);
}
}
126 changes: 0 additions & 126 deletions tests/bundle_tests/rest/UserTest.php

This file was deleted.

0 comments on commit 8a6fd7d

Please sign in to comment.