Added Entity and Entity Reference Revisions which got dropped somewhere along the...
[yaffs-website] / web / modules / contrib / entity / tests / src / Unit / QueryAccess / ConditionTest.php
1 <?php
2
3 namespace Drupal\Tests\entity\Unit\QueryAccess;
4
5 use Drupal\entity\QueryAccess\Condition;
6 use Drupal\Tests\UnitTestCase;
7
8 /**
9  * @coversDefaultClass \Drupal\entity\QueryAccess\Condition
10  * @group entity
11  */
12 class ConditionTest extends UnitTestCase {
13
14   /**
15    * ::covers __construct.
16    *
17    * @expectedException \InvalidArgumentException
18    * @expectedExceptionMessage Unrecognized operator "INVALID".
19    */
20   public function testInvalidOperator() {
21     $condition = new Condition('uid', '1', 'INVALID');
22   }
23
24   /**
25    * ::covers getField
26    * ::covers getValue
27    * ::covers getOperator
28    * ::covers __toString.
29    */
30   public function testGetters() {
31     $condition = new Condition('uid', '2');
32     $this->assertEquals('uid', $condition->getField());
33     $this->assertEquals('2', $condition->getValue());
34     $this->assertEquals('=', $condition->getOperator());
35     $this->assertEquals("uid = '2'", $condition->__toString());
36
37     $condition = new Condition('type', ['article', 'page']);
38     $this->assertEquals('type', $condition->getField());
39     $this->assertEquals(['article', 'page'], $condition->getValue());
40     $this->assertEquals('IN', $condition->getOperator());
41     $this->assertEquals("type IN ['article', 'page']", $condition->__toString());
42
43     $condition = new Condition('title', NULL, 'IS NULL');
44     $this->assertEquals('title', $condition->getField());
45     $this->assertEquals(NULL, $condition->getValue());
46     $this->assertEquals('IS NULL', $condition->getOperator());
47     $this->assertEquals("title IS NULL", $condition->__toString());
48   }
49
50 }