eZ\Publish\Core\Persistence\Legacy\Tests\User\Role\LimitationConverterTest::testObjectStateToSPI PHP Method

testObjectStateToSPI() public method

Test Object State from legacy value (database) to SPI value (supported by API).
    public function testObjectStateToSPI()
    {
        $this->insertDatabaseFixture(__DIR__ . '/../../../../../Repository/Tests/Service/Integration/Legacy/_fixtures/clean_ezdemo_47_dump.php');
        $converter = $this->getLimitationConverter();
        $policy = new Policy();
        $policy->module = 'content';
        $policy->function = 'read';
        // #1 Test wildcard
        $policy->limitations = array(ObjectStateLimitationHandler::STATE_GROUP . 'ez_lock' => '*');
        $converter->toSPI($policy);
        $this->assertEquals(array(Limitation::STATE => '*'), $policy->limitations, 'Expected State limitation to be transformed into StateGroup_ limitations');
        // #2 Test valid state values
        $policy->limitations = array(ObjectStateLimitationHandler::STATE_GROUP . 'ez_lock' => array(1, 2));
        $converter->toSPI($policy);
        $this->assertEquals(array(Limitation::STATE => array(1, 2)), $policy->limitations, 'Expected State limitation to be transformed into StateGroup_ limitations');
        // #3 Test invalid state values (as the values supposedly comes from database they are carried over)
        $policy->limitations = array(ObjectStateLimitationHandler::STATE_GROUP . 'ez_lock' => array(1, 2, 3, 4));
        $converter->toSPI($policy);
        $this->assertEquals(array(Limitation::STATE => array(1, 2, 3, 4)), $policy->limitations, 'Expected State limitation to be transformed into StateGroup_ limitations');
        // #4 Test invalid state values with mix of wildcard (wildcard values is loaded from db, rest kept as is)
        $policy->limitations = array(ObjectStateLimitationHandler::STATE_GROUP . 'ez_lock' => '*', ObjectStateLimitationHandler::STATE_GROUP . 'invalid' => array(5));
        $converter->toSPI($policy);
        $this->assertArrayHasKey(Limitation::STATE, $policy->limitations);
        // Don't expect backend to return sorted result, so lets sort values before testing
        sort($policy->limitations[Limitation::STATE], SORT_NUMERIC);
        $this->assertEquals(array(1, 2, 5), $policy->limitations[Limitation::STATE], 'Expected State limitation to be transformed into StateGroup_ limitations');
    }