Chris@0: 'page', 'name' => 'page']); Chris@0: $type->save(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Tests the node validation constraints. Chris@0: */ Chris@0: public function testValidation() { Chris@0: $this->createUser(); Chris@0: $node = Node::create(['type' => 'page', 'title' => 'test', 'uid' => 1]); Chris@0: $violations = $node->validate(); Chris@0: $this->assertEqual(count($violations), 0, 'No violations when validating a default node.'); Chris@0: Chris@0: $node->set('title', $this->randomString(256)); Chris@0: $violations = $node->validate(); Chris@0: $this->assertEqual(count($violations), 1, 'Violation found when title is too long.'); Chris@0: $this->assertEqual($violations[0]->getPropertyPath(), 'title.0.value'); Chris@0: $this->assertEqual($violations[0]->getMessage(), 'Title: may not be longer than 255 characters.'); Chris@0: Chris@0: $node->set('title', NULL); Chris@0: $violations = $node->validate(); Chris@0: $this->assertEqual(count($violations), 1, 'Violation found when title is not set.'); Chris@0: $this->assertEqual($violations[0]->getPropertyPath(), 'title'); Chris@0: $this->assertEqual($violations[0]->getMessage(), 'This value should not be null.'); Chris@0: Chris@0: $node->set('title', ''); Chris@0: $violations = $node->validate(); Chris@0: $this->assertEqual(count($violations), 1, 'Violation found when title is set to an empty string.'); Chris@0: $this->assertEqual($violations[0]->getPropertyPath(), 'title'); Chris@0: Chris@0: // Make the title valid again. Chris@0: $node->set('title', $this->randomString()); Chris@0: // Save the node so that it gets an ID and a changed date. Chris@0: $node->save(); Chris@0: // Set the changed date to something in the far past. Chris@0: $node->set('changed', 433918800); Chris@0: $violations = $node->validate(); Chris@0: $this->assertEqual(count($violations), 1, 'Violation found when changed date is before the last changed date.'); Chris@0: $this->assertEqual($violations[0]->getPropertyPath(), ''); Chris@0: $this->assertEqual($violations[0]->getMessage(), 'The content has either been modified by another user, or you have already submitted modifications. As a result, your changes cannot be saved.'); Chris@0: } Chris@0: Chris@0: }