Chris@0: 'page', 'name' => 'page']); Chris@0: $type->save(); Chris@0: $type = NodeType::create(['type' => 'article', 'name' => 'article']); Chris@0: $type->save(); Chris@0: $type = NodeType::create(['type' => 'test', 'name' => 'test']); Chris@0: $type->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests conditions. Chris@0: */ Chris@0: public function testConditions() { Chris@0: $manager = $this->container->get('plugin.manager.condition', $this->container->get('container.namespaces')); Chris@0: $this->createUser(); Chris@0: Chris@0: // Get some nodes of various types to check against. Chris@0: $page = Node::create(['type' => 'page', 'title' => $this->randomMachineName(), 'uid' => 1]); Chris@0: $page->save(); Chris@0: $article = Node::create(['type' => 'article', 'title' => $this->randomMachineName(), 'uid' => 1]); Chris@0: $article->save(); Chris@0: $test = Node::create(['type' => 'test', 'title' => $this->randomMachineName(), 'uid' => 1]); Chris@0: $test->save(); Chris@0: Chris@0: // Grab the node type condition and configure it to check against node type Chris@0: // of 'article' and set the context to the page type node. Chris@0: $condition = $manager->createInstance('node_type') Chris@0: ->setConfig('bundles', ['article' => 'article']) Chris@0: ->setContextValue('node', $page); Chris@0: $this->assertFalse($condition->execute(), 'Page type nodes fail node type checks for articles.'); Chris@0: // Check for the proper summary. Chris@0: $this->assertEqual('The node bundle is article', $condition->summary()); Chris@0: Chris@0: // Set the node type check to page. Chris@0: $condition->setConfig('bundles', ['page' => 'page']); Chris@0: $this->assertTrue($condition->execute(), 'Page type nodes pass node type checks for pages'); Chris@0: // Check for the proper summary. Chris@0: $this->assertEqual('The node bundle is page', $condition->summary()); Chris@0: Chris@0: // Set the node type check to page or article. Chris@0: $condition->setConfig('bundles', ['page' => 'page', 'article' => 'article']); Chris@0: $this->assertTrue($condition->execute(), 'Page type nodes pass node type checks for pages or articles'); Chris@0: // Check for the proper summary. Chris@0: $this->assertEqual('The node bundle is page or article', $condition->summary()); Chris@0: Chris@0: // Set the context to the article node. Chris@0: $condition->setContextValue('node', $article); Chris@0: $this->assertTrue($condition->execute(), 'Article type nodes pass node type checks for pages or articles'); Chris@0: Chris@0: // Set the context to the test node. Chris@0: $condition->setContextValue('node', $test); Chris@0: $this->assertFalse($condition->execute(), 'Test type nodes pass node type checks for pages or articles'); Chris@0: Chris@0: // Check a greater than 2 bundles summary scenario. Chris@0: $condition->setConfig('bundles', ['page' => 'page', 'article' => 'article', 'test' => 'test']); Chris@0: $this->assertEqual('The node bundle is page, article or test', $condition->summary()); Chris@0: Chris@0: // Test Constructor injection. Chris@0: $condition = $manager->createInstance('node_type', ['bundles' => ['article' => 'article'], 'context' => ['node' => $article]]); Chris@0: $this->assertTrue($condition->execute(), 'Constructor injection of context and configuration working as anticipated.'); Chris@0: } Chris@0: Chris@0: }