Codeception打印出Acceptance Cest方法变量

时间:2018-11-16 09:53:18

标签: php drupal drupal-8 codeception

我与Drupal 8合作,需要检查客户(产品负责人)是否具有创建,更新和删除内容类型的正确权限。

首先,我为需要测试的每种内容类型编写了一个单独的验收指南。但是,这变得非常乏味。

这就是为什么我决定编写一个接受Cest来从JSON文件中检索预定义的内容类型,然后检查该内容类型应具有的权限,然后按照这些权限测试内容管理器用户是否确实是能够执行该动作(或者在他们不应该执行一个动作的情况下无法执行)。它将对JSON文件中定义的所有内容类型执行此操作。

它工作得很漂亮,我很高兴通过使用@dataProvider批注可以实现这一点。

但是,有一点我不满意,那就是Codeception似乎在打印它在命令行中循环的内容类型的值。

但是,很奇怪的是,它用我的$I->wantTo();方法调用中的文本覆盖了命令行中已经可见的内容。

有什么方法可以防止Codeception在命令行中打印内容类型的值?如果不是,为什么这样做,因为我不太了解是什么原因导致了这种情况的发生。

我提供了遍历内容类型并对其进行测试的方法的代码,从JSON文件检索数据的方法的代码以及JSON文件本身。当我运行可视化测试时,命令行中还会发生GIF。

我希望借此提供足够的信息。如果需要更多,我将很乐意提供。

//This method checks if the rights to create a content type are in place correctly
/**
* @param AcceptanceTester $I
* @dataProvider typeProvider
*/
public function CmUserCreateRight(AcceptanceTester $I, \Codeception\Example $contentType)
{
    $objective = sprintf("see that the CM user " . ($contentType['rights']['create'] ? 'can' : 'cannot') . " create a %s", $contentType['realname']);

    $I->wantTo($objective);
    $I->amOnPage('/node/add');
    $I->seeResponseCodeIs(200);

    //The rights are defined as either true or false, this checks which is defined and tests accordingly.
    if ($contentType['rights']['create']) {
        $I->seeLink(sprintf('%s', $contentType['realname']), sprintf('/node/add/%s', $contentType['urlname']));
    } else {
        $I->dontSeeLink(sprintf('%s', $contentType['realname']), sprintf('/node/add/%s', $contentType['urlname']));
    }
}

您可以看到“ TypeProvider”被用作dataProvider。此方法与上面的方法在同一类中。

 /**
 * @return array
 */
protected function typeProvider()
{
    $TH = new TypeHelper();
    return $TH->getTypes();
}

TypeProvider方法调用类“ ContentTypes”(在这里我将其用作“ TypeHelper”),以检索JSON数据。

class ContentTypes {

    private $contentTypes = [];

    public function __construct()
    {
        $this->contentTypes = $this->getConfig();
    }

    private function getConfig() {
        $json = file_get_contents('tests/_data/contenttypes.json');
        return json_decode($json, true);
    }

    public function getTypes() {
        return $this->contentTypes;
    }
}

最后,此类检索JSON数据并将其作为\Codeception\Example返回给原始方法,以在Cest中使用。

JSON文件:

[
    {
        "urlname": "configuratie_pagina",
        "realname": "Configuratie pagina",
        "rights": {
            "create": false,
            "update": true,
            "delete": false
        }
    },   

   {
       "urlname": "content",
       "realname": "Contentpagina",
       "rights": {
           "create": true,
           "update": true,
           "delete": true
        }
    }
]

This is what happens in the command line

0 个答案:

没有答案